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 <bert.wesarg@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Bert Wesarg committed
Jan 27, 2020 at 08:04 UTC
923d4a5ca4f86c19247ef436e6d03d261ebce904
2 files changed
+36
-2
builtin/remote.c
+21
-1
@@ -250,6 +250,7 @@ struct branch_info {
250
char *remote_name;
251
struct string_list merge;
252
enum rebase_type rebase;
253
+ char *push_remote_name;
254
};
255
256
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)
268
char *name;
269
struct string_list_item *item;
270
struct branch_info *info;
270
- enum { REMOTE, MERGE, REBASE } type;
271
+ enum { REMOTE, MERGE, REBASE, PUSH_REMOTE } type;
272
size_t key_len;
273
274
if (!starts_with(key, "branch."))
@@ -280,6 +281,8 @@ static int config_read_branches(const char *key, const char *value, void *cb)
281
type = MERGE;
282
else if (strip_suffix(key, ".rebase", &key_len))
283
type = REBASE;
284
+ else if (strip_suffix(key, ".pushremote", &key_len))
285
+ type = PUSH_REMOTE;
286
else
287
return 0;
288
name = xmemdupz(key, key_len);
@@ -315,6 +318,11 @@ static int config_read_branches(const char *key, const char *value, void *cb)
318
*/
319
info->rebase = rebase_parse_value(value);
320
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;
326
default:
327
BUG("unexpected type=%d", type);
328
}
@@ -682,6 +690,11 @@ static int mv(int argc, const char **argv)
690
strbuf_addf(&buf, "branch.%s.remote", item->string);
691
git_config_set(buf.buf, rename.new_name);
692
}
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
+ }
698
}
699
700
if (!refspec_updated)
@@ -783,6 +796,13 @@ static int rm(int argc, const char **argv)
796
die(_("could not unset '%s'"), buf.buf);
797
}
798
}
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
+ }
806
}
807
808
/*
t/t5505-remote.sh
+15
-1
@@ -737,12 +737,14 @@ test_expect_success 'rename a remote' '
737
git clone one four &&
738
(
739
cd four &&
740
+ git config branch.master.pushRemote origin &&
741
git remote rename origin upstream &&
742
test -z "$(git for-each-ref refs/remotes/origin)" &&
743
test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
744
test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
745
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"
748
)
749
'
750
@@ -784,6 +786,18 @@ test_expect_success 'rename succeeds with existing remote.<target>.prune' '
786
git -C four.four remote rename origin upstream
787
'
788
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
+
801
cat >remotes_origin <<EOF
802
URL: $(pwd)/one
803
Push: refs/heads/master:refs/heads/upstream