mirror of
https://github.com/NixOS/nix.git
synced 2025-12-22 17:01:08 +01:00
GitRepo: Implement create flag
This was ignored for some reason.
This commit is contained in:
parent
1c728ce0de
commit
9a6f1e6266
2 changed files with 6 additions and 9 deletions
|
|
@ -203,16 +203,19 @@ static git_packbuilder_progress PACKBUILDER_PROGRESS_CHECK_INTERRUPT = &packBuil
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
static void initRepoAtomically(std::filesystem::path & path, bool bare)
|
static void initRepoAtomically(std::filesystem::path & path, GitRepo::Options options)
|
||||||
{
|
{
|
||||||
if (pathExists(path.string()))
|
if (pathExists(path.string()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!options.create)
|
||||||
|
throw Error("Git repository %s does not exist.", path);
|
||||||
|
|
||||||
std::filesystem::path tmpDir = createTempDir(path.parent_path());
|
std::filesystem::path tmpDir = createTempDir(path.parent_path());
|
||||||
AutoDelete delTmpDir(tmpDir, true);
|
AutoDelete delTmpDir(tmpDir, true);
|
||||||
Repository tmpRepo;
|
Repository tmpRepo;
|
||||||
|
|
||||||
if (git_repository_init(Setter(tmpRepo), tmpDir.string().c_str(), bare))
|
if (git_repository_init(Setter(tmpRepo), tmpDir.string().c_str(), options.bare))
|
||||||
throw Error("creating Git repository %s: %s", path, git_error_last()->message);
|
throw Error("creating Git repository %s: %s", path, git_error_last()->message);
|
||||||
try {
|
try {
|
||||||
std::filesystem::rename(tmpDir, path);
|
std::filesystem::rename(tmpDir, path);
|
||||||
|
|
@ -261,7 +264,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||||
{
|
{
|
||||||
initLibGit2();
|
initLibGit2();
|
||||||
|
|
||||||
initRepoAtomically(path, options.bare);
|
initRepoAtomically(path, options);
|
||||||
if (git_repository_open(Setter(repo), path.string().c_str()))
|
if (git_repository_open(Setter(repo), path.string().c_str()))
|
||||||
throw Error("opening Git repository %s: %s", path, git_error_last()->message);
|
throw Error("opening Git repository %s: %s", path, git_error_last()->message);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -637,12 +637,6 @@ struct GitInputScheme : InputScheme
|
||||||
url);
|
url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't check here for the path existence, then we can give libgit2 any directory
|
|
||||||
// and it will initialize them as git directories.
|
|
||||||
// FIXME
|
|
||||||
if (!pathExists(path)) {
|
|
||||||
throw Error("The path '%s' does not exist.", path);
|
|
||||||
}
|
|
||||||
repoInfo.location = std::filesystem::absolute(path);
|
repoInfo.location = std::filesystem::absolute(path);
|
||||||
} else {
|
} else {
|
||||||
if (url.scheme == "file")
|
if (url.scheme == "file")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue