Skip to content

Commit 6935e7d

Browse files
authored
cleanGit on an already cleaned copies to store (#788)
``` cleanGit { src = cleanSrcWith { ... } } ``` Results in the full `src` being copied to the store before filtering the files not in the git index. This change uses `src.origSrcSubDir` if it exists to avoid this.
1 parent 6ca073d commit 6935e7d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/clean-git.nix

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ let
5151
s;
5252

5353
lines = s: filter (x : x != [] && x != "") (split "\n" s);
54+
55+
origSrcSubDir = toString (src.origSrcSubDir or src);
5456
in
5557

56-
if builtins.pathExists (toString src + "/.git")
58+
if builtins.pathExists (origSrcSubDir + "/.git")
5759
then
5860
let
59-
hasIndex = builtins.pathExists (toString src + "/.git/index");
60-
isWorktree = (builtins.readDir (toString src)).".git" == "regular";
61+
hasIndex = builtins.pathExists (origSrcSubDir + "/.git/index");
62+
isWorktree = (builtins.readDir origSrcSubDir).".git" == "regular";
6163

6264
# Identify the .git directory and filter just the files that we need.
6365
gitDir = cleanSourceWith ({
@@ -74,19 +76,19 @@ then
7476
if hasIndex
7577
then { inherit src; subDir = ".git"; }
7678
else if !isWorktree
77-
then abort "cleanGit: ${toString src + "/.git"} has no index file"
79+
then abort "cleanGit: ${origSrcSubDir + "/.git"} has no index file"
7880
else {
7981
# likely a git worktree, so follow the indirection
8082
src =
8183
let
82-
git_content = lines (readFile (toString src + "/.git"));
84+
git_content = lines (readFile (origSrcSubDir + "/.git"));
8385
first_line = head git_content;
8486
prefix = "gitdir: ";
8587
ok = length git_content == 1 && has_prefix prefix first_line;
8688
in
8789
if ok
8890
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"}";
9092
}));
9193

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

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

108110
gitSubmoduleFiles = cleanSourceWith {
@@ -154,7 +156,7 @@ then
154156
}
155157

156158
else
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." (
158160
cleanSourceWith {
159161
caller = "cleanGit";
160162
inherit name src subDir;

0 commit comments

Comments
 (0)