summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2012-10-02 11:48:02 +0200
committerCarlos Martín Nieto <cmn@elego.de>2012-10-02 13:09:18 +0200
commit218c88a968eb983261920465105c698aaacacaaf (patch)
tree321eb2ebbb915c1d44a382733ca1a11471dcf6f9
parent8bc5caccee4ebb0b9239135fe81750f3b72a8e76 (diff)
downloadlibgit2-218c88a968eb983261920465105c698aaacacaaf.tar.gz
remote: set/unset the autotag setting on save
Make the configuration option match the configured behavior when saving a remote.
-rw-r--r--src/remote.c34
-rw-r--r--tests-clar/network/remotes.c24
2 files changed, 58 insertions, 0 deletions
diff --git a/src/remote.c b/src/remote.c
index c01e41dce..7c7790bfc 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -198,7 +198,9 @@ cleanup:
int git_remote_save(const git_remote *remote)
{
+ int error;
git_config *config;
+ const char *tagopt = NULL;
git_buf buf = GIT_BUF_INIT, value = GIT_BUF_INIT;
if (git_repository_config__weakptr(&config, remote->repo) < 0)
@@ -260,6 +262,38 @@ int git_remote_save(const git_remote *remote)
goto on_error;
}
+ /*
+ * What action to take depends on the old and new values. This
+ * is describes by the table below. tagopt means whether the
+ * is already a value set in the config
+ *
+ * AUTO ALL or NONE
+ * +-----------------------+
+ * tagopt | remove | set |
+ * +---------+-------------|
+ * !tagopt | nothing | set |
+ * +---------+-------------+
+ */
+
+ git_buf_clear(&buf);
+ if (git_buf_printf(&buf, "remote.%s.tagopt", remote->name) < 0)
+ goto on_error;
+
+ error = git_config_get_string(&tagopt, config, git_buf_cstr(&buf));
+ if (error < 0 && error != GIT_ENOTFOUND)
+ goto on_error;
+
+ if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
+ if (git_config_set_string(config, git_buf_cstr(&buf), "--tags") < 0)
+ goto on_error;
+ } else if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_NONE) {
+ if (git_config_set_string(config, git_buf_cstr(&buf), "--no-tags") < 0)
+ goto on_error;
+ } else if (tagopt) {
+ if (git_config_delete(config, git_buf_cstr(&buf)) < 0)
+ goto on_error;
+ }
+
git_buf_free(&buf);
git_buf_free(&value);
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index c7ee863e7..91c3e879d 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -225,3 +225,27 @@ void test_network_remotes__add(void)
cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/remotes/addtest/*"));
cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2");
}
+
+void test_network_remotes__tagopt(void)
+{
+ const char *opt;
+ git_config *cfg;
+
+ cl_git_pass(git_repository_config(&cfg, _repo));
+
+ git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
+ cl_git_pass(git_remote_save(_remote));
+ cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
+ cl_assert(!strcmp(opt, "--tags"));
+
+ git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_NONE);
+ cl_git_pass(git_remote_save(_remote));
+ cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
+ cl_assert(!strcmp(opt, "--no-tags"));
+
+ git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
+ cl_git_pass(git_remote_save(_remote));
+ cl_assert(git_config_get_string(&opt, cfg, "remote.test.tagopt") == GIT_ENOTFOUND);
+
+ git_config_free(cfg);
+}