Skip to content

Commit d81cb2e

Browse files
committed
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. libgit2#3856
1 parent c18a2bc commit d81cb2e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ v0.24 + 1
1010
directory matching the starting directory will not prevent git from
1111
finding a repository in the starting directory or a parent directory.
1212

13+
* Do not fail when deleting remotes in the presence of broken
14+
global configs which contain branches.
15+
1316
### API additions
1417

1518
* You can now get the user-agent used by libgit2 using the

src/remote.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,15 +2162,21 @@ static int remove_branch_config_related_entries(
21622162
if (git_buf_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch) < 0)
21632163
break;
21642164

2165-
if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0)
2166-
break;
2165+
if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
2166+
if (error != GIT_ENOTFOUND)
2167+
break;
2168+
giterr_clear();
2169+
}
21672170

21682171
git_buf_clear(&buf);
21692172
if (git_buf_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch) < 0)
21702173
break;
21712174

2172-
if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0)
2173-
break;
2175+
if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
2176+
if (error != GIT_ENOTFOUND)
2177+
break;
2178+
giterr_clear();
2179+
}
21742180
}
21752181

21762182
if (error == GIT_ITEROVER)

0 commit comments

Comments
 (0)