diff options
Diffstat (limited to 'src/libgit2/repository.c')
-rw-r--r-- | src/libgit2/repository.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index 0d149a626..13559ef07 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -3366,10 +3366,10 @@ int git_repository__shallow_roots_write(git_repository *repo, git_array_oid_t ro assert(repo); if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0) - return error; + goto on_error; if ((error = git_filebuf_open(&file, git_str_cstr(&path), GIT_FILEBUF_HASH_CONTENTS, 0666)) < 0) - return error; + goto on_error; git_array_foreach(roots, idx, oid) { git_filebuf_write(&file, git_oid_tostr_s(oid), GIT_OID_HEXSZ); @@ -3378,12 +3378,19 @@ int git_repository__shallow_roots_write(git_repository *repo, git_array_oid_t ro git_filebuf_commit(&file); - git_str_dispose(&path); + if ((error = load_grafts(repo)) < 0) { + error = -1; + goto on_error; + } - if (load_grafts(repo) < 0) - return -1; + if (git_array_size(roots) == 0) { + remove(path.ptr); + } - return 0; +on_error: + git_str_dispose(&path); + + return error; } int git_repository_shallow_roots(git_oidarray *out, git_repository *repo) |