From 413d55638483678357ebcb8c26911cf944be95cc Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Wed, 25 Jul 2012 02:10:35 +0200 Subject: [PATCH] Remotes: Save a cleaned pushurl (by deleting it from the config) --- src/remote.c | 17 +++++++++++++---- tests-clar/network/remotes.c | 9 +++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/remote.c b/src/remote.c index cdd593cdb..bee1ab65c 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 61b29b85e..3d989c1b6 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)