aboutsummaryrefslogtreecommitdiffstats
path: root/remote.c
diff options
context:
space:
mode:
authorTao Klerks <tao@klerks.biz>2022-04-29 09:56:45 +0000
committerJunio C Hamano <gitster@pobox.com>2022-04-29 11:20:55 -0700
commit8a649be7e8010085a8a3f1c9126da5c02324350e (patch)
treeee31880869adbf2497d38ffe263340bd7a9833fd /remote.c
parentbdaf1dfae71fdf120fc7253e713ccf0a06cc5558 (diff)
downloadgit-8a649be7e8010085a8a3f1c9126da5c02324350e.tar.gz
push: default to single remote even when not named origin
With "push.default=current" configured, a simple "git push" will push to the same-name branch on the current branch's branch.<name>.pushRemote, or remote.pushDefault, or origin. If none of these are defined, the push will fail with error "fatal: No configured push destination". The same "default to origin if no config" behavior applies with "push.default=matching". Other commands use "origin" as a default when there are multiple options, but default to the single remote when there is only one - for example, "git checkout <something>". This "assume the single remote if there is only one" behavior is more friendly/useful than a defaulting behavior that only uses the name "origin" no matter what. Update "git push" to also default to the single remote (and finally fall back to "origin" as default if there are several), for "push.default=current" and for other current and future remote-defaulting push behaviors. This change also modifies the behavior of ls-remote in a consistent way, so defaulting not only supplies 'origin', but any single configured remote also. Document the change in behavior, correct incorrect assumptions in related tests, and add test cases reflecting this new single-remote-defaulting behavior. Signed-off-by: Tao Klerks <tao@klerks.biz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/remote.c b/remote.c
index 42a4e7106e..930fdc9c2f 100644
--- a/remote.c
+++ b/remote.c
@@ -543,6 +543,8 @@ static const char *remotes_remote_for_branch(struct remote_state *remote_state,
}
if (explicit)
*explicit = 0;
+ if (remote_state->remotes_nr == 1)
+ return remote_state->remotes[0]->name;
return "origin";
}