Merge pull request #3862 from novalis/dturner/do-not-die-on-missing-config remote: Handle missing config values when deleting a remote
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 32925d4..45fce0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,9 @@ v0.24 + 1
directory matching the starting directory will not prevent git from
finding a repository in the starting directory or a parent directory.
+* Do not fail when deleting remotes in the presence of broken
+ global configs which contain branches.
+
### API additions
* You can now get the user-agent used by libgit2 using the
diff --git a/src/remote.c b/src/remote.c
index 5f89c40..c1d7d59 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -2162,15 +2162,21 @@ static int remove_branch_config_related_entries(
if (git_buf_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch) < 0)
break;
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0)
- break;
+ if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
+ if (error != GIT_ENOTFOUND)
+ break;
+ giterr_clear();
+ }
git_buf_clear(&buf);
if (git_buf_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch) < 0)
break;
- if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0)
- break;
+ if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
+ if (error != GIT_ENOTFOUND)
+ break;
+ giterr_clear();
+ }
}
if (error == GIT_ITEROVER)