Hint at the source file on conflict in flake new

Add a pointer to the source file (from the template) when `nix flake new` (or `init`) encounters an already existing file

Fix #6542
This commit is contained in:
Théophane Hufschmitt 2022-05-18 16:46:13 +02:00 committed by GitHub
parent 78dc64ec1e
commit 452ffe5464
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -758,7 +758,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
if (pathExists(to2)) { if (pathExists(to2)) {
auto contents2 = readFile(to2); auto contents2 = readFile(to2);
if (contents != contents2) if (contents != contents2)
throw Error("refusing to overwrite existing file '%s'", to2); throw Error("refusing to overwrite existing file '%s' - please merge manually with '%s'", to2, from2);
} else } else
writeFile(to2, contents); writeFile(to2, contents);
} }
@ -766,7 +766,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
auto target = readLink(from2); auto target = readLink(from2);
if (pathExists(to2)) { if (pathExists(to2)) {
if (readLink(to2) != target) if (readLink(to2) != target)
throw Error("refusing to overwrite existing symlink '%s'", to2); throw Error("refusing to overwrite existing symlink '%s' - please merge manually with '%s'", to2, from2);
} else } else
createSymlink(target, to2); createSymlink(target, to2);
} }