1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 21:41:48 +02:00

Automatically do git/hg add on flake.lock

This commit is contained in:
Eelco Dolstra 2020-02-02 16:32:46 +01:00
parent f83acbbfe3
commit d5334c466b
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 47 additions and 23 deletions

View file

@ -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);

View file

@ -62,6 +62,9 @@ struct Input : std::enable_shared_from_this<Input>
virtual std::optional<Path> getSourcePath() const { return {}; }
// FIXME: should merge with getSourcePath().
virtual void markChangedFile(std::string_view file) const { assert(false); }
virtual void clone(const Path & destDir) const
{
throw Error("do not know how to clone input '%s'", to_string());

View file

@ -165,6 +165,18 @@ struct GitInput : Input
return {};
}
void markChangedFile(std::string_view file) const override
{
auto sourcePath = getSourcePath();
assert(sourcePath);
runProgram("git", true,
{ "-C", *sourcePath, "add",
"--force",
"--intent-to-add",
std::string(file)
});
}
std::pair<bool, std::string> getActualUrl() const
{
// Don't clone file:// URIs (but otherwise treat them the

View file

@ -84,6 +84,17 @@ struct MercurialInput : Input
return {};
}
void markChangedFile(std::string_view file) const override
{
auto sourcePath = getSourcePath();
assert(sourcePath);
// FIXME: shut up if file is already tracked.
runProgram("hg", true,
{ "add",
*sourcePath + "/" + std::string(file)
});
}
std::pair<bool, std::string> getActualUrl() const
{
bool isLocal = url.scheme == "file";