summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-06-06 01:09:49 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-06-06 01:09:49 +0200
commita52ab4b82a06f3a4e6065ecfa1b27917b4ba216b (patch)
tree525b35ea1aac298b5c94f03758ef0c5e8ab7cd94
parentfe3b9d07317732830a3416187e2946979caafc92 (diff)
downloadlibgit2-cmn/remote-rename-fixes.tar.gz
remote: tighten up reference renamingcmn/remote-rename-fixes
Tighten up which references we consider for renaming so we don't try to rename unrelated ones and end up with unexplained references. If there is a reference on the target namespace, git overwrites it, so let's do the same.
-rw-r--r--src/remote.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/remote.c b/src/remote.c
index 0c82433d1..0d1a88ea7 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1380,7 +1380,7 @@ static int rename_one_remote_reference(
goto cleanup;
error = git_reference_rename(
- NULL, reference, git_buf_cstr(&new_name), 0,
+ NULL, reference, git_buf_cstr(&new_name), 1,
NULL, git_buf_cstr(&log_message));
git_reference_free(reference);
@@ -1396,18 +1396,20 @@ static int rename_remote_references(
const char *new_name)
{
int error;
+ git_buf buf = GIT_BUF_INIT;
git_reference *ref;
git_reference_iterator *iter;
- if ((error = git_reference_iterator_new(&iter, repo)) < 0)
+ if ((error = git_buf_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0)
return error;
- while ((error = git_reference_next(&ref, iter)) == 0) {
- if (git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR)) {
- git_reference_free(ref);
- continue;
- }
+ error = git_reference_iterator_glob_new(&iter, repo, git_buf_cstr(&buf));
+ git_buf_free(&buf);
+ if (error < 0)
+ return error;
+
+ while ((error = git_reference_next(&ref, iter)) == 0) {
if ((error = rename_one_remote_reference(ref, old_name, new_name)) < 0)
break;
}