Skip to content

Commit 923d4a5

Browse files
bertwesarggitster
authored andcommitted
remote rename/remove: handle branch.<name>.pushRemote config values
When renaming or removing a remote with git remote rename X Y git remote remove X Git already renames/removes any config values from branch.<name>.remote = X to branch.<name>.remote = Y As branch.<name>.pushRemote also names a remote, it now also renames or removes these config values from branch.<name>.pushRemote = X to branch.<name>.pushRemote = Y Signed-off-by: Bert Wesarg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ceff1a1 commit 923d4a5

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

builtin/remote.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ struct branch_info {
250250
char *remote_name;
251251
struct string_list merge;
252252
enum rebase_type rebase;
253+
char *push_remote_name;
253254
};
254255

255256
static struct string_list branch_list = STRING_LIST_INIT_NODUP;
@@ -267,7 +268,7 @@ static int config_read_branches(const char *key, const char *value, void *cb)
267268
char *name;
268269
struct string_list_item *item;
269270
struct branch_info *info;
270-
enum { REMOTE, MERGE, REBASE } type;
271+
enum { REMOTE, MERGE, REBASE, PUSH_REMOTE } type;
271272
size_t key_len;
272273

273274
if (!starts_with(key, "branch."))
@@ -280,6 +281,8 @@ static int config_read_branches(const char *key, const char *value, void *cb)
280281
type = MERGE;
281282
else if (strip_suffix(key, ".rebase", &key_len))
282283
type = REBASE;
284+
else if (strip_suffix(key, ".pushremote", &key_len))
285+
type = PUSH_REMOTE;
283286
else
284287
return 0;
285288
name = xmemdupz(key, key_len);
@@ -315,6 +318,11 @@ static int config_read_branches(const char *key, const char *value, void *cb)
315318
*/
316319
info->rebase = rebase_parse_value(value);
317320
break;
321+
case PUSH_REMOTE:
322+
if (info->push_remote_name)
323+
warning(_("more than one %s"), orig_key);
324+
info->push_remote_name = xstrdup(value);
325+
break;
318326
default:
319327
BUG("unexpected type=%d", type);
320328
}
@@ -682,6 +690,11 @@ static int mv(int argc, const char **argv)
682690
strbuf_addf(&buf, "branch.%s.remote", item->string);
683691
git_config_set(buf.buf, rename.new_name);
684692
}
693+
if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) {
694+
strbuf_reset(&buf);
695+
strbuf_addf(&buf, "branch.%s.pushremote", item->string);
696+
git_config_set(buf.buf, rename.new_name);
697+
}
685698
}
686699

687700
if (!refspec_updated)
@@ -783,6 +796,13 @@ static int rm(int argc, const char **argv)
783796
die(_("could not unset '%s'"), buf.buf);
784797
}
785798
}
799+
if (info->push_remote_name && !strcmp(info->push_remote_name, remote->name)) {
800+
strbuf_reset(&buf);
801+
strbuf_addf(&buf, "branch.%s.pushremote", item->string);
802+
result = git_config_set_gently(buf.buf, NULL);
803+
if (result && result != CONFIG_NOTHING_SET)
804+
die(_("could not unset '%s'"), buf.buf);
805+
}
786806
}
787807

788808
/*

t/t5505-remote.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,14 @@ test_expect_success 'rename a remote' '
737737
git clone one four &&
738738
(
739739
cd four &&
740+
git config branch.master.pushRemote origin &&
740741
git remote rename origin upstream &&
741742
test -z "$(git for-each-ref refs/remotes/origin)" &&
742743
test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
743744
test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
744745
test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
745-
test "$(git config branch.master.remote)" = "upstream"
746+
test "$(git config branch.master.remote)" = "upstream" &&
747+
test "$(git config branch.master.pushRemote)" = "upstream"
746748
)
747749
'
748750

@@ -784,6 +786,18 @@ test_expect_success 'rename succeeds with existing remote.<target>.prune' '
784786
git -C four.four remote rename origin upstream
785787
'
786788

789+
test_expect_success 'remove a remote' '
790+
git clone one four.five &&
791+
(
792+
cd four.five &&
793+
git config branch.master.pushRemote origin &&
794+
git remote remove origin &&
795+
test -z "$(git for-each-ref refs/remotes/origin)" &&
796+
test_must_fail git config branch.master.remote &&
797+
test_must_fail git config branch.master.pushRemote
798+
)
799+
'
800+
787801
cat >remotes_origin <<EOF
788802
URL: $(pwd)/one
789803
Push: refs/heads/master:refs/heads/upstream

0 commit comments

Comments
 (0)