Remotes: Save a cleaned pushurl (by deleting it from the config)
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 45 46 47 48 49 50 51 52 53
diff --git a/src/remote.c b/src/remote.c
index cdd593c..bee1ab6 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -207,15 +207,24 @@ int git_remote_save(const git_remote *remote)
return -1;
}
- if (remote->pushurl) {
- git_buf_clear(&buf);
- if (git_buf_printf(&buf, "remote.%s.pushurl", remote->name) < 0)
- return -1;
+ git_buf_clear(&buf);
+ if (git_buf_printf(&buf, "remote.%s.pushurl", remote->name) < 0)
+ return -1;
+ if (remote->pushurl) {
if (git_config_set_string(config, git_buf_cstr(&buf), remote->pushurl) < 0) {
git_buf_free(&buf);
return -1;
}
+ } else {
+ int error = git_config_delete(config, git_buf_cstr(&buf));
+ if (error == GIT_ENOTFOUND) {
+ error = 0;
+ }
+ if (error < 0) {
+ git_buf_free(&buf);
+ return -1;
+ }
}
if (remote->fetch.src != NULL && remote->fetch.dst != NULL) {
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index 61b29b8..3d989c1 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -120,6 +120,15 @@ void test_network_remotes__save(void)
cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
cl_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/libgit2_push");
+
+ /* remove the pushurl again and see if we can save that too */
+ cl_git_pass(git_remote_set_pushurl(_remote, NULL));
+ cl_git_pass(git_remote_save(_remote));
+ git_remote_free(_remote);
+ _remote = NULL;
+
+ cl_git_pass(git_remote_load(&_remote, _repo, "upstream"));
+ cl_assert(git_remote_pushurl(_remote) == NULL);
}
void test_network_remotes__fnmatch(void)