diff options
author | eldritch horrors <pennae@lix.systems> | 2024-03-07 14:33:43 +0100 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-03-07 14:50:43 +0100 |
commit | 232f4feacebb5c9ea7072238ae3e565c2c292b70 (patch) | |
tree | 7e5856260181413f2a82030202a9ce74bfde6213 /src/libfetchers | |
parent | 852bc55c870e32f18ca64cb7dcbdf225b137ed3c (diff) |
Merge pull request #9324 from 9999years/fix-8854-take-2
Don't attempt to `git add` ignored files
(cherry picked from commit 359990dfdc713c80aabd7ea6f7e4528628fbe108)
===
also added a regression test that isn't upstream to be sure we're
actually fixing the bug.
Change-Id: I8267a3d0ece9909d8008b7435b90e7b3eee366f6
Diffstat (limited to 'src/libfetchers')
-rw-r--r-- | src/libfetchers/git.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 321950e63..1689155b3 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -377,15 +377,26 @@ struct GitInputScheme : InputScheme assert(sourcePath); auto gitDir = ".git"; - runProgram("git", true, - { "-C", *sourcePath, "--git-dir", gitDir, "add", "--intent-to-add", "--", std::string(file) }); + auto result = runProgram(RunOptions { + .program = "git", + .args = {"-C", *sourcePath, "--git-dir", gitDir, "check-ignore", "--quiet", std::string(file)}, + }); + auto exitCode = WEXITSTATUS(result.first); - // Pause the logger to allow for user input (such as a gpg passphrase) in `git commit` - logger->pause(); - Finally restoreLogger([]() { logger->resume(); }); - if (commitMsg) + if (exitCode != 0) { + // The path is not `.gitignore`d, we can add the file. runProgram("git", true, - { "-C", *sourcePath, "--git-dir", gitDir, "commit", std::string(file), "-m", *commitMsg }); + { "-C", *sourcePath, "--git-dir", gitDir, "add", "--intent-to-add", "--", std::string(file) }); + + + if (commitMsg) { + // Pause the logger to allow for user input (such as a gpg passphrase) in `git commit` + logger->pause(); + Finally restoreLogger([]() { logger->resume(); }); + runProgram("git", true, + { "-C", *sourcePath, "--git-dir", gitDir, "commit", std::string(file), "-m", *commitMsg }); + } + } } std::pair<bool, std::string> getActualUrl(const Input & input) const |