aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/flake/flake.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-02-02 16:32:46 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-02-02 16:33:22 +0100
commitd5334c466b9ee237a1cce4fd005d790e67d74822 (patch)
tree07c7b62e81c3aa9a8185900cf8257f147a87e828 /src/libexpr/flake/flake.cc
parentf83acbbfe389c356ce95f61c48d193961717c480 (diff)
Automatically do git/hg add on flake.lock
Diffstat (limited to 'src/libexpr/flake/flake.cc')
-rw-r--r--src/libexpr/flake/flake.cc25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc
index 39fdc776c..5018b460b 100644
--- a/src/libexpr/flake/flake.cc
+++ b/src/libexpr/flake/flake.cc
@@ -579,22 +579,23 @@ LockedFlake lockFlake(
newLockFile.write(path);
- // Rewriting the lockfile changed the top-level
- // repo, so we should re-read it.
+ topRef.input->markChangedFile(
+ (topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock");
+
+ /* Rewriting the lockfile changed the top-level
+ repo, so we should re-read it. FIXME: we could
+ also just clear the 'rev' field... */
+ auto prevLockedRef = flake.lockedRef;
FlakeCache dummyCache;
flake = getFlake(state, topRef, {}, lockFlags.useRegistries, dummyCache);
- if (flake.lockedRef.input->isImmutable())
+ /* Make sure that we picked up the change,
+ i.e. the tree should usually be dirty
+ now. Corner case: we could have reverted from a
+ dirty to a clean tree! */
+ if (flake.lockedRef.input == prevLockedRef.input
+ && !flake.lockedRef.input->isImmutable())
throw Error("'%s' did not change after I updated its 'flake.lock' file; is 'flake.lock' under version control?", flake.originalRef);
-
- #if 0
- // Hack: Make sure that flake.lock is visible to Git, so it ends up in the Nix store.
- runProgram("git", true,
- { "-C", *sourcePath, "add",
- "--force",
- "--intent-to-add",
- (topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock" });
- #endif
}
} else
throw Error("cannot write modified lock file of flake '%s' (use '--no-write-lock-file' to ignore)", topRef);