summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Turner <dturner@twosigma.com>2016-07-15 13:32:23 -0400
committerCarlos Martín Nieto <cmn@dwim.me>2016-10-01 17:40:41 +0200
commit9894c7ddeb204d0568e1173f0f9bb48580ece010 (patch)
tree20d024a79fb317779c760311b7589227bc5ee8de
parent49188d2b2986daf8e4a93c9d1acd177b98e304ec (diff)
downloadlibgit2-9894c7ddeb204d0568e1173f0f9bb48580ece010.tar.gz
remote: Handle missing config values when deleting a remote
Somehow I ended up with the following in my ~/.gitconfig: [branch "master"] remote = origin merge = master rebase = true I assume something went crazy while I was running the git.git tests some time ago, and that I never noticed until now. This is not a good configuration, but it shouldn't cause problems. But it does. Specifically, if you have this in your config, and you perform the following set of actions: create a remote fetch from that remote create a branch off of the remote master branch called "master" delete the branch delete the remote The remote delete fails with the message "Could not find key 'branch.master.rebase' to delete". This is because it's iterating over the config entries (including the ones in the global config) and believes that there is a master branch which must therefore have these config keys. https://github.com/libgit2/libgit2/issues/3856
-rw-r--r--src/remote.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/remote.c b/src/remote.c
index db7564a59..15a00dd28 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -2228,15 +2228,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)