aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/populate/src')
-rw-r--r--pkgs/populate/src/sh.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs
index 9ae920b..0411edd 100644
--- a/pkgs/populate/src/sh.rs
+++ b/pkgs/populate/src/sh.rs
@@ -414,9 +414,15 @@ else
fetch "$ref"
hash=$(git rev-parse --verify 'FETCH_HEAD^{commit}')
fi
-# Also if HEAD is there already: rewriting a lock file in place, e.g.,
-# changes the work tree, and stages the lock file if Nix created it.
-git reset --hard "$hash" >&2
+# Also if HEAD is there already, unless no tracked file differs from it:
+# rewriting a lock file in place, e.g., changes the work tree, and stages
+# the lock file if Nix created it.
+head=$(git rev-parse --verify --quiet HEAD) || head=
+commit=$(git rev-parse --verify --quiet "$hash^{commit}") || commit=
+changes=$(git status --porcelain --untracked-files=no) || changes=unknown
+if test -z "$head" || test "$head" != "$commit" || test -n "$changes"; then
+ git reset --hard "$hash" >&2
+fi
git submodule update --init --recursive
n=$#
while test "$n" -gt 0; do