remote.c: introduce remote.pushdefault
This new configuration variable defines the default remote to push to, and overrides `branch.<name>.remote` for all branches. It is useful in the typical triangular-workflow setup, where the remote you're fetching from is different from the remote you're pushing to. 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
224c2171637ee71c36cb6b0ed314d14216725d6f
3 files changed
+29
-3
Documentation/config.txt
+10
-3
@@ -727,9 +727,12 @@ branch.autosetuprebase::
727
This option defaults to never.
728
729
branch.<name>.remote::
730
- When in branch <name>, it tells 'git fetch' and 'git push' which
731
- remote to fetch from/push to. It defaults to `origin` if no remote is
732
- configured. `origin` is also used if you are not on any branch.
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.
736
737
branch.<name>.merge::
738
Defines, together with branch.<name>.remote, the upstream branch
@@ -1898,6 +1901,10 @@ receive.updateserverinfo::
1901
If set to true, git-receive-pack will run git-update-server-info
1902
after receiving data from git-push and updating refs.
1903
1904
+remote.pushdefault::
1905
+ The remote to push to by default. Overrides
1906
+ `branch.<name>.remote` for all branches.
1907
+
1908
remote.<name>.url::
1909
The URL of a remote repository. See linkgit:git-fetch[1] or
1910
linkgit:git-push[1].
remote.c
+7
@@ -389,9 +389,16 @@ static int handle_config(const char *key, const char *value, void *cb)
389
add_instead_of(rewrite, xstrdup(value));
390
}
391
}
392
+
393
if (prefixcmp(key, "remote."))
394
return 0;
395
name = key + 7;
396
+
397
+ /* Handle remote.* variables */
398
+ if (!strcmp(name, "pushdefault"))
399
+ return git_config_string(&pushremote_name, key, value);
400
+
401
+ /* Handle remote.<name>.* variables */
402
if (*name == '/') {
403
warning("Config remote shorthand cannot begin with '/': %s",
404
name);
t/t5516-fetch-push.sh
+12
@@ -497,6 +497,18 @@ test_expect_success 'push with config remote.*.push = HEAD' '
497
check_push_result testrepo $the_first_commit heads/local
498
'
499
500
+test_expect_success 'push with remote.pushdefault' '
501
+ mk_test up_repo heads/master &&
502
+ mk_test down_repo heads/master &&
503
+ test_config remote.up.url up_repo &&
504
+ test_config remote.down.url down_repo &&
505
+ test_config branch.master.remote up &&
506
+ test_config remote.pushdefault down &&
507
+ git push &&
508
+ check_push_result up_repo $the_first_commit heads/master &&
509
+ check_push_result down_repo $the_commit heads/master
510
+'
511
+
512
test_expect_success 'push with config remote.*.pushurl' '
513
514
mk_test testrepo heads/master &&