summaryrefslogtreecommitdiff
path: root/src/libgit2/repository.c
diff options
context:
space:
mode:
authoryuangli <yuangli@mathworks.com>2022-08-09 19:24:57 +0100
committeryuangli <yuangli@mathworks.com>2022-08-09 19:24:57 +0100
commitdf5eb3239b1419b3f4382d7bcca9a5d85611d7d3 (patch)
treea5d97cf1c8f6b269bae26f48a6176236e749c005 /src/libgit2/repository.c
parent09b3d33d6dba7f4804b478a72dec3258405856c2 (diff)
downloadlibgit2-df5eb3239b1419b3f4382d7bcca9a5d85611d7d3.tar.gz
support fetch unshallow option on shallow repos
Diffstat (limited to 'src/libgit2/repository.c')
-rw-r--r--src/libgit2/repository.c19
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)