on iko/ghcjs-patch-master help sign in
cleanGit on an already cleaned copies to store (#788)
6935e7dHamish Mackenzie
lib/clean-git.nix+10−8
@@ -51,13 +51,15 @@ let
51 s;
51 s;
52
52
53 lines = s: filter (x : x != [] && x != "") (split "\n" s);
53 lines = s: filter (x : x != [] && x != "") (split "\n" s);
54+
55+ origSrcSubDir = toString (src.origSrcSubDir or src);
54in
56in
55
57
56−if builtins.pathExists (toString src + "/.git")
58+if builtins.pathExists (origSrcSubDir + "/.git")
57then
59then
58 let
60 let
59− hasIndex = builtins.pathExists (toString src + "/.git/index");
61+ hasIndex = builtins.pathExists (origSrcSubDir + "/.git/index");
60− isWorktree = (builtins.readDir (toString src)).".git" == "regular";
62+ isWorktree = (builtins.readDir origSrcSubDir).".git" == "regular";
61
63
62 # Identify the .git directory and filter just the files that we need.
64 # Identify the .git directory and filter just the files that we need.
63 gitDir = cleanSourceWith ({
65 gitDir = cleanSourceWith ({
@@ -74,19 +76,19 @@ then
74 if hasIndex
76 if hasIndex
75 then { inherit src; subDir = ".git"; }
77 then { inherit src; subDir = ".git"; }
76 else if !isWorktree
78 else if !isWorktree
77− then abort "cleanGit: ${toString src + "/.git"} has no index file"
79+ then abort "cleanGit: ${origSrcSubDir + "/.git"} has no index file"
78 else {
80 else {
79 # likely a git worktree, so follow the indirection
81 # likely a git worktree, so follow the indirection
80 src =
82 src =
81 let
83 let
82− git_content = lines (readFile (toString src + "/.git"));
84+ git_content = lines (readFile (origSrcSubDir + "/.git"));
83 first_line = head git_content;
85 first_line = head git_content;
84 prefix = "gitdir: ";
86 prefix = "gitdir: ";
85 ok = length git_content == 1 && has_prefix prefix first_line;
87 ok = length git_content == 1 && has_prefix prefix first_line;
86 in
88 in
87 if ok
89 if ok
88 then /. + remove_prefix prefix first_line
90 then /. + remove_prefix prefix first_line
89− else abort "gitSource.nix: Cannot parse ${toString src + "/.git"}";
91+ else abort "gitSource.nix: Cannot parse ${origSrcSubDir + "/.git"}";
90 }));
92 }));
91
93
92 # Worktrees have a commondir pointing to the common `.git` dir. We need the
94 # Worktrees have a commondir pointing to the common `.git` dir. We need the
@@ -102,7 +104,7 @@ then
102 else gitDir + "/config";
104 else gitDir + "/config";
103
105
104 # We need the .gitmodules file for submoules to work.
106 # We need the .gitmodules file for submoules to work.
105− gitModulesStr = toString src + "/.gitmodules";
107+ gitModulesStr = origSrcSubDir + "/.gitmodules";
106 gitModules = builtins.path { name = "gitmodules"; path = gitModulesStr; };
108 gitModules = builtins.path { name = "gitmodules"; path = gitModulesStr; };
107
109
108 gitSubmoduleFiles = cleanSourceWith {
110 gitSubmoduleFiles = cleanSourceWith {
@@ -154,7 +156,7 @@ then
154 }
156 }
155
157
156else
158else
157− trace "gitSource.nix: ${toString src} does not seem to be a git repository,\nassuming it is a clean checkout." (
159+ trace "gitSource.nix: ${origSrcSubDir} does not seem to be a git repository,\nassuming it is a clean checkout." (
158 cleanSourceWith {
160 cleanSourceWith {
159 caller = "cleanGit";
161 caller = "cleanGit";
160 inherit name src subDir;
162 inherit name src subDir;