Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a52ab4b

Browse files
committed
remote: tighten up reference renaming
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.
1 parent fe3b9d0 commit a52ab4b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/remote.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ static int rename_one_remote_reference(
13801380
goto cleanup;
13811381

13821382
error = git_reference_rename(
1383-
NULL, reference, git_buf_cstr(&new_name), 0,
1383+
NULL, reference, git_buf_cstr(&new_name), 1,
13841384
NULL, git_buf_cstr(&log_message));
13851385
git_reference_free(reference);
13861386

@@ -1396,18 +1396,20 @@ static int rename_remote_references(
13961396
const char *new_name)
13971397
{
13981398
int error;
1399+
git_buf buf = GIT_BUF_INIT;
13991400
git_reference *ref;
14001401
git_reference_iterator *iter;
14011402

1402-
if ((error = git_reference_iterator_new(&iter, repo)) < 0)
1403+
if ((error = git_buf_printf(&buf, GIT_REFS_REMOTES_DIR "%s/*", old_name)) < 0)
14031404
return error;
14041405

1405-
while ((error = git_reference_next(&ref, iter)) == 0) {
1406-
if (git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR)) {
1407-
git_reference_free(ref);
1408-
continue;
1409-
}
1406+
error = git_reference_iterator_glob_new(&iter, repo, git_buf_cstr(&buf));
1407+
git_buf_free(&buf);
14101408

1409+
if (error < 0)
1410+
return error;
1411+
1412+
while ((error = git_reference_next(&ref, iter)) == 0) {
14111413
if ((error = rename_one_remote_reference(ref, old_name, new_name)) < 0)
14121414
break;
14131415
}

0 commit comments

Comments
 (0)