remote.c: introduce branch.<name>.pushremote

This new configuration variable overrides `remote.pushdefault` and `branch.<name>.remote` for pushes. When you pull from one place (e.g. your upstream) and push to another place (e.g. your own publishing repository), you would want to set `remote.pushdefault` to specify the remote to push to for all branches, and use this option to override it for a specific branch. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Apr 2, 2013 at 13:10 UTC 9f765ce62fd2d5159a3dc7f73abe30a3fbef08f7
3 files changed +34 -4
Documentation/config.txt
+15 -4
@@ -730,9 +730,19 @@ branch.<name>.remote::
730 When on branch <name>, it tells 'git fetch' and 'git push'
731 which remote to fetch from/push to. The remote to push to
732 may be overridden with `remote.pushdefault` (for all branches).
733 - If no remote is configured, or if you are not on any branch,
734 - it defaults to `origin` for fetching and `remote.pushdefault`
735 - for pushing.
733 + The remote to push to, for the current branch, may be further
734 + overridden by `branch.<name>.pushremote`. If no remote is
735 + configured, or if you are not on any branch, it defaults to
736 + `origin` for fetching and `remote.pushdefault` for pushing.
737 +
738 +branch.<name>.pushremote::
739 + When on branch <name>, it overrides `branch.<name>.remote` for
740 + pushing. It also overrides `remote.pushdefault` for pushing
741 + from branch <name>. When you pull from one place (e.g. your
742 + upstream) and push to another place (e.g. your own publishing
743 + repository), you would want to set `remote.pushdefault` to
744 + specify the remote to push to for all branches, and use this
745 + option to override it for a specific branch.
746
747 branch.<name>.merge::
748 Defines, together with branch.<name>.remote, the upstream branch
@@ -1903,7 +1913,8 @@ receive.updateserverinfo::
1913
1914 remote.pushdefault::
1915 The remote to push to by default. Overrides
1906 - `branch.<name>.remote` for all branches.
1916 + `branch.<name>.remote` for all branches, and is overridden by
1917 + `branch.<name>.pushremote` for specific branches.
1918
1919 remote.<name>.url::
1920 The URL of a remote repository. See linkgit:git-fetch[1] or
remote.c
+4
@@ -364,6 +364,10 @@ static int handle_config(const char *key, const char *value, void *cb)
364 default_remote_name = branch->remote_name;
365 explicit_default_remote_name = 1;
366 }
367 + } else if (!strcmp(subkey, ".pushremote")) {
368 + if (branch == current_branch)
369 + if (git_config_string(&pushremote_name, key, value))
370 + return -1;
371 } else if (!strcmp(subkey, ".merge")) {
372 if (!value)
373 return config_error_nonbool(key);
t/t5516-fetch-push.sh
+15
@@ -519,6 +519,21 @@ test_expect_success 'push with config remote.*.pushurl' '
519 check_push_result testrepo $the_commit heads/master
520 '
521
522 +test_expect_success 'push with config branch.*.pushremote' '
523 + mk_test up_repo heads/master &&
524 + mk_test side_repo heads/master &&
525 + mk_test down_repo heads/master &&
526 + test_config remote.up.url up_repo &&
527 + test_config remote.pushdefault side_repo &&
528 + test_config remote.down.url down_repo &&
529 + test_config branch.master.remote up &&
530 + test_config branch.master.pushremote down &&
531 + git push &&
532 + check_push_result up_repo $the_first_commit heads/master &&
533 + check_push_result side_repo $the_first_commit heads/master &&
534 + check_push_result down_repo $the_commit heads/master
535 +'
536 +
537 test_expect_success 'push with dry-run' '
538
539 mk_test testrepo heads/master &&