Skip to content

cleanGit on an already cleaned copies to store #788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/clean-git.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ let
s;

lines = s: filter (x : x != [] && x != "") (split "\n" s);

origSrcSubDir = toString (src.origSrcSubDir or src);
in

if builtins.pathExists (toString src + "/.git")
if builtins.pathExists (origSrcSubDir + "/.git")
then
let
hasIndex = builtins.pathExists (toString src + "/.git/index");
isWorktree = (builtins.readDir (toString src)).".git" == "regular";
hasIndex = builtins.pathExists (origSrcSubDir + "/.git/index");
isWorktree = (builtins.readDir origSrcSubDir).".git" == "regular";

# Identify the .git directory and filter just the files that we need.
gitDir = cleanSourceWith ({
Expand All @@ -74,19 +76,19 @@ then
if hasIndex
then { inherit src; subDir = ".git"; }
else if !isWorktree
then abort "cleanGit: ${toString src + "/.git"} has no index file"
then abort "cleanGit: ${origSrcSubDir + "/.git"} has no index file"
else {
# likely a git worktree, so follow the indirection
src =
let
git_content = lines (readFile (toString src + "/.git"));
git_content = lines (readFile (origSrcSubDir + "/.git"));
first_line = head git_content;
prefix = "gitdir: ";
ok = length git_content == 1 && has_prefix prefix first_line;
in
if ok
then /. + remove_prefix prefix first_line
else abort "gitSource.nix: Cannot parse ${toString src + "/.git"}";
else abort "gitSource.nix: Cannot parse ${origSrcSubDir + "/.git"}";
}));

# Worktrees have a commondir pointing to the common `.git` dir. We need the
Expand All @@ -102,7 +104,7 @@ then
else gitDir + "/config";

# We need the .gitmodules file for submoules to work.
gitModulesStr = toString src + "/.gitmodules";
gitModulesStr = origSrcSubDir + "/.gitmodules";
gitModules = builtins.path { name = "gitmodules"; path = gitModulesStr; };

gitSubmoduleFiles = cleanSourceWith {
Expand Down Expand Up @@ -154,7 +156,7 @@ then
}

else
trace "gitSource.nix: ${toString src} does not seem to be a git repository,\nassuming it is a clean checkout." (
trace "gitSource.nix: ${origSrcSubDir} does not seem to be a git repository,\nassuming it is a clean checkout." (
cleanSourceWith {
caller = "cleanGit";
inherit name src subDir;
Expand Down