The man page for git push claims:
--repo=<repository>
This option is only relevant if no <repository> argument is passed
in the invocation. In this case, git-push derives the remote name
from the current branch: If it tracks a remote branch, then that
remote repository is pushed to. Otherwise, the name "origin" is
used. For this latter case, this option can be used to override the
name "origin". In other words, the difference between these two
commands
git push public #1
git push --repo=public #2
is that #1 always pushes to "public" whereas #2 pushes to "public"
only if the current branch does not track a remote branch. This is
useful if you write an alias or script around git-push.
However, I'm sitting here looking at the code and I don't see how this
is possible. I've also done some testing. So I think the man page lies
and that forms (1) and (2) are equivalent as shown.
cmd_push() is:
const char *repo = NULL; /* default repository */
struct option options[] = {
...
OPT_STRING( 0 , "repo", &repo, "repository", "repository"),
...
}
argc = parse_options(argc, argv, options, push_usage, 0);
if (argc > 0) {
repo = argv[0];
set_refspecs(argv + 1, argc - 1);
}
rc = do_push(repo, flags);
So if the user specifies --repo, then its value is assigned to *repo by
parse_options. If the user otherwise specifies a repository w/o --repo, that
will be argv[0] after parse_options, so it will get assigned to *repo. Assuming
no other arguments, set_refspecs gets called with argc = 0 and returns w/o doing
anything.
So the only difference I can see is that form #1 allows the user to specify a
refspec on the command line. Form #2 does not since the first
non-dashed argument gets assigned to *repo, so:
$ git push --repo src:dst
would assign src:dst to *repo, which would choke.
So, what's the point of the --repo dashed-option then?
j.
Tap...tap...tap... is this thing on? :-)
On Fri, Feb 20, 2009 at 4:16 AM, Jay Soffian [off-list ref] wrote:
The man page for git push claims:
--repo=<repository>
This option is only relevant if no <repository> argument is passed
in the invocation. In this case, git-push derives the remote name
from the current branch: If it tracks a remote branch, then that
remote repository is pushed to. Otherwise, the name "origin" is
used. For this latter case, this option can be used to override the
name "origin". In other words, the difference between these two
commands
git push public #1
git push --repo=public #2
is that #1 always pushes to "public" whereas #2 pushes to "public"
only if the current branch does not track a remote branch. This is
useful if you write an alias or script around git-push.
However, I'm sitting here looking at the code and I don't see how this
is possible. I've also done some testing. So I think the man page lies
and that forms (1) and (2) are equivalent as shown.
cmd_push() is:
const char *repo = NULL; /* default repository */
struct option options[] = {
...
OPT_STRING( 0 , "repo", &repo, "repository", "repository"),
...
}
argc = parse_options(argc, argv, options, push_usage, 0);
if (argc > 0) {
repo = argv[0];
set_refspecs(argv + 1, argc - 1);
}
rc = do_push(repo, flags);
So if the user specifies --repo, then its value is assigned to *repo by
parse_options. If the user otherwise specifies a repository w/o --repo, that
will be argv[0] after parse_options, so it will get assigned to *repo. Assuming
no other arguments, set_refspecs gets called with argc = 0 and returns w/o doing
anything.
So the only difference I can see is that form #1 allows the user to specify a
refspec on the command line. Form #2 does not since the first
non-dashed argument gets assigned to *repo, so:
$ git push --repo src:dst
would assign src:dst to *repo, which would choke.
So, what's the point of the --repo dashed-option then?
j.
The --repo=myorigin option is supposed to change the default fallback
remote from "origin" to "myorigin", but not override any direct argument
nor config info of tracking branches. Add tests for this. (currently 2
known breakages)
Signed-off-by: Michael J Gruber <redacted>
---
Tap tap tap....
This is an R for Comments on the desired behaviour of git push with
respect to --repo. I think the tests below expose that the current
behaviour does not match the current doc. I'm messing around in the code
but can't quite produce a match with the doc yet. Before investing more
time I'm wondering whether the code should adjusted to the doc or vice
versa...
The code change I'm experimenting with right now is making
default_remote_name a global and passing it from push. Does not look
nice (esp. w.r.t. libification) but seems to ibe the minimally invasive
solution.
t/t5516-fetch-push.sh | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 89649e7..8393366 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -419,6 +419,41 @@ test_expect_success 'push with config remote.*.push = HEAD' '
git config --remove-section remote.there
git config --remove-section branch.master
+test_expect_success 'push with --repo=repourl from non-tracking branch' '
+
+ mk_test heads/master &&
+ git push --repo=testrepo &&
+ check_push_result $the_commit heads/master
+'
+
+# set up fake remote config
+test_expect_success 'push with --repo=remoterepo from non-tracking branch' '
+
+ mk_test heads/master &&
+ git config remote.testremote.url testrepo &&
+ git push --repo=testremote &&
+ check_push_result $the_commit heads/master
+'
+
+# set up fake tracking info; testrepo exists, origin does not.
+test_expect_failure 'push with --repo=repo from tracking branch with bad config' '
+
+ mk_test heads/master &&
+ git config branch.master.remote origin &&
+ test_must_fail git push --repo=testrepo
+'
+
+test_expect_failure 'push with --repo=repo from tracking branch with good config' '
+
+ mk_test heads/master &&
+ git config branch.master.remote testrepo &&
+ git push --repo=origin &&
+ check_push_result $the_commit heads/master
+'
+
+# clean up fake remote and tracking info
+git config --unset-all branch.master.remote
+
test_expect_success 'push with dry-run' '
mk_test heads/master &&
--
1.6.2.rc1.30.gd43c