diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-06-06 12:19:00 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-06-06 12:19:00 -0700 |
commit | 36a22e4b6c5c8a16c9a0ea308017c0cad2d1d679 (patch) | |
tree | 5166e0f50d55c4a5f78cf4ead9d73364693e418d /builtin | |
parent | 2fc0c022e60f54be55d6065b9a8abccdc0f67bab (diff) | |
parent | 0f075b220862e729eb3873a1c1496b923d17c2d4 (diff) | |
download | git-36a22e4b6c5c8a16c9a0ea308017c0cad2d1d679.tar.gz git-36a22e4b6c5c8a16c9a0ea308017c0cad2d1d679.tar.xz |
Merge branch 'rr/push-head'
"git push $there HEAD:branch" did not resolve HEAD early enough, so
it was easy to flip it around while push is still going on and push
out a branch that the user did not originally intended when the
command was started.
* rr/push-head:
push: make push.default = current use resolved HEAD
push: fail early with detached HEAD and current
push: factor out the detached HEAD error message
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/push.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/builtin/push.c b/builtin/push.c index 909c34dfd..2d84d1072 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -113,17 +113,19 @@ static NORETURN int die_push_simple(struct branch *branch, struct remote *remote remote->name, branch->name, advice_maybe); } +static const char message_detached_head_die[] = + N_("You are not currently on a branch.\n" + "To push the history leading to the current (detached HEAD)\n" + "state now, use\n" + "\n" + " git push %s HEAD:<name-of-remote-branch>\n"); + static void setup_push_upstream(struct remote *remote, int simple) { struct strbuf refspec = STRBUF_INIT; struct branch *branch = branch_get(NULL); if (!branch) - die(_("You are not currently on a branch.\n" - "To push the history leading to the current (detached HEAD)\n" - "state now, use\n" - "\n" - " git push %s HEAD:<name-of-remote-branch>\n"), - remote->name); + die(_(message_detached_head_die), remote->name); if (!branch->merge_nr || !branch->merge || !branch->remote_name) die(_("The current branch %s has no upstream branch.\n" "To push the current branch and set the remote as upstream, use\n" @@ -173,6 +175,8 @@ static void warn_unspecified_push_default_configuration(void) static void setup_default_push_refspecs(struct remote *remote) { + struct branch *branch; + switch (push_default) { default: case PUSH_DEFAULT_UNSPECIFIED: @@ -192,7 +196,10 @@ static void setup_default_push_refspecs(struct remote *remote) break; case PUSH_DEFAULT_CURRENT: - add_refspec("HEAD"); + branch = branch_get(NULL); + if (!branch) + die(_(message_detached_head_die), remote->name); + add_refspec(branch->name); break; case PUSH_DEFAULT_NOTHING: |