Skip to content
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

Don't ignore unstaged files in local flakes #6858

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,16 @@ WorkdirInfo getWorkdirInfo(const Input & input, const Path & workdir)

try {
if (hasHead) {
// 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", workdir, "--git-dir", gitDir, "diff", "HEAD", "--quiet"});
// Use git status --short to list changed and untracked files.
// The output will be empty if there are none and the tree is clean
auto gitDiffOpts = Strings({ "-C", workdir, "--git-dir", gitDir, "status", "--short"});
Comment on lines +184 to +186

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this output is being parsed in a script it would probably be better to use git status --porcelain, as that output is guaranteed to be stable (whereas git status --short is not).

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;
clean = (chomp(runProgram("git", true, gitDiffOpts)) == "");
}
} catch (ExecError & e) {
if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 1) throw;
Expand All @@ -212,9 +210,13 @@ std::pair<StorePath, Input> fetchFromWorkdir(ref<Store> store, Input & input, co
if (fetchSettings.warnDirty)
warn("Git tree '%s' is dirty", workdir);

auto gitOpts = Strings({ "-C", workdir, "--git-dir", gitDir, "ls-files", "-z" });
auto gitOpts = Strings({ "-C", workdir, "--git-dir", gitDir, "ls-files", "--cached", "-z" });
if (submodules)
gitOpts.emplace_back("--recurse-submodules");
else {
gitOpts.emplace_back("--others");
gitOpts.emplace_back("--exclude-standard");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to have an option to not run the standard excludes? I would like to be able to have .gitignored local files that still get applied in my nix config. I don't care about other users/programs on the computer reading them, they just don't make sense to be in the upstream repo.

(Also see #12291 for an alternative approach.)

}
Comment on lines +216 to +219

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI the else { and } lines use tabs to indent, while the rest of the file uses spaces.


auto files = tokenizeString<std::set<std::string>>(
runProgram("git", true, gitOpts), "\0"s);
Expand Down