aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schwaighofer <mschwaig@users.noreply.github.com>2021-12-13 21:31:20 +0100
committerMartin Schwaighofer <mschwaig@users.noreply.github.com>2022-02-19 22:58:23 +0100
commitc7e527b82b3dafed5f0da2ec0e14a47cf8e65def (patch)
tree97efcf796b1ce9c590e78514a59c17f2fc0379f8 /src
parent0bfa0cdea1b4eb09405e35b338887c91a041d28c (diff)
git fetcher: invoke diff instead of diff-index
diff-index operates on the view that git has of the working tree, which might be outdated. The higher-level diff command does this automatically. This change also adds handling for submodules. fixes #4140 Alternative fixes would be invoking update-index before diff-index or matching more closely what require_clean_work_tree from git-sh-setup.sh does, but both those options make it more difficult to reason about correctness.
Diffstat (limited to 'src')
-rw-r--r--src/libfetchers/git.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc
index 7479318e3..d241eb67a 100644
--- a/src/libfetchers/git.cc
+++ b/src/libfetchers/git.cc
@@ -235,7 +235,17 @@ struct GitInputScheme : InputScheme
try {
if (hasHead) {
- runProgram("git", true, { "-C", actualUrl, "diff-index", "--quiet", "HEAD", "--" });
+ // Using git diff is preferrable over lower-level operations here,
+ // because its conceptually simpler and we only need the exit code anyways.
+ auto gitDiffOpts = Strings({ "-C", actualUrl, "diff", "HEAD", "--quiet"});
+ if (!submodules) {
+ // Changes in submodules should only make the tree dirty
+ // when those submodules will be copied as well.
+ gitDiffOpts.emplace_back("--ignore-submodules");
+ }
+ gitDiffOpts.emplace_back("--");
+ runProgram("git", true, gitDiffOpts);
+
clean = true;
}
} catch (ExecError & e) {