All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Early HEAD resolution in push.default = current
@ 2013-05-29 19:21 Ramkumar Ramachandra
  2013-05-29 19:21 ` [PATCH 1/3] push: factor out the detached HEAD error message Ramkumar Ramachandra
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-29 19:21 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

The commit message in [3/3] is rewritten although I've mentioned the
original motivation at the end.

No other changes.

Ramkumar Ramachandra (3):
  push: factor out the detached HEAD error message
  push: fail early with detached HEAD and current
  push: make push.default = current resolve HEAD early

 builtin/push.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

-- 
1.8.3.12.gbd56588

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] push: factor out the detached HEAD error message
  2013-05-29 19:21 [PATCH v2 0/3] Early HEAD resolution in push.default = current Ramkumar Ramachandra
@ 2013-05-29 19:21 ` Ramkumar Ramachandra
  2013-05-29 19:21 ` [PATCH 2/3] push: fail early with detached HEAD and current Ramkumar Ramachandra
  2013-05-29 19:21 ` [PATCH 3/3] push: make push.default = current use resolved HEAD Ramkumar Ramachandra
  2 siblings, 0 replies; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-29 19:21 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

With push.default set to upstream or simple, and a detached HEAD, git
push prints the following error:

  $ git push
  fatal: You are not currently on a branch.
  To push the history leading to the current (detached HEAD)
  state now, use

    git push ram HEAD:<name-of-remote-branch>

This error is not unique to upstream or simple: current cannot push with
a detached HEAD either.  So, factor out the error string in preparation
for using it in current.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/push.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/builtin/push.c b/builtin/push.c
index 909c34d..ef3aa97 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"
-- 
1.8.3.12.gbd56588

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] push: fail early with detached HEAD and current
  2013-05-29 19:21 [PATCH v2 0/3] Early HEAD resolution in push.default = current Ramkumar Ramachandra
  2013-05-29 19:21 ` [PATCH 1/3] push: factor out the detached HEAD error message Ramkumar Ramachandra
@ 2013-05-29 19:21 ` Ramkumar Ramachandra
  2013-05-29 19:34   ` Junio C Hamano
  2013-05-29 19:21 ` [PATCH 3/3] push: make push.default = current use resolved HEAD Ramkumar Ramachandra
  2 siblings, 1 reply; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-29 19:21 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

Setting push.default to current adds the refspec "HEAD" for the
transport layer to handle.  If "HEAD" doesn't resolve to a branch (and
since no refspec rhs is specified), the push fails after some time with
a cryptic error message:

  $ git push
  error: unable to push to unqualified destination: HEAD
  The destination refspec neither matches an existing ref on the remote nor
  begins with refs/, and we are unable to guess a prefix based on the source ref.
  error: failed to push some refs to 'git@github.com:artagnon/git'

Fail early with a nicer error message:

  $ git push
  fatal: You are not currently on a branch.
  To push the history leading to the current (detached HEAD)
  state now, use

    git push ram HEAD:<name-of-remote-branch>

Just like in the upstream and simple cases.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/push.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/builtin/push.c b/builtin/push.c
index ef3aa97..a79038c 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -175,6 +175,8 @@ static void warn_unspecified_push_default_configuration(void)
 
 static void setup_default_push_refspecs(struct remote *remote)
 {
+	struct branch *branch = branch_get(NULL);
+
 	switch (push_default) {
 	default:
 	case PUSH_DEFAULT_UNSPECIFIED:
@@ -194,6 +196,8 @@ static void setup_default_push_refspecs(struct remote *remote)
 		break;
 
 	case PUSH_DEFAULT_CURRENT:
+		if (!branch)
+			die(_(message_detached_head_die), remote->name);
 		add_refspec("HEAD");
 		break;
 
-- 
1.8.3.12.gbd56588

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] push: make push.default = current use resolved HEAD
  2013-05-29 19:21 [PATCH v2 0/3] Early HEAD resolution in push.default = current Ramkumar Ramachandra
  2013-05-29 19:21 ` [PATCH 1/3] push: factor out the detached HEAD error message Ramkumar Ramachandra
  2013-05-29 19:21 ` [PATCH 2/3] push: fail early with detached HEAD and current Ramkumar Ramachandra
@ 2013-05-29 19:21 ` Ramkumar Ramachandra
  2 siblings, 0 replies; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-29 19:21 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

With this change, the output of the push (with push.default set to
current) changes subtly from:

  $ git push
  ...
   * [new branch]      HEAD -> push-current-head

to:

  $ git push
  ...
   * [new branch]      push-current-head -> push-current-head

This patch was written with a different motivation. There is a problem
unique to push.default = current:

  # on branch push-current-head
  $ git push
  # on another terminal
  $ git checkout master
  # return to the first terminal
  # the push tried to push master!

This happens because the 'git checkout' on the second terminal races
with the 'git push' on the first terminal.  Although this patch does not
solve the core problem (there is still no guarantee that 'git push' on
the first terminal will resolve HEAD before 'git checkout' changes HEAD
on the second), it works in practice.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/push.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/push.c b/builtin/push.c
index a79038c..d819487 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -198,7 +198,7 @@ static void setup_default_push_refspecs(struct remote *remote)
 	case PUSH_DEFAULT_CURRENT:
 		if (!branch)
 			die(_(message_detached_head_die), remote->name);
-		add_refspec("HEAD");
+		add_refspec(branch->name);
 		break;
 
 	case PUSH_DEFAULT_NOTHING:
-- 
1.8.3.12.gbd56588

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] push: fail early with detached HEAD and current
  2013-05-29 19:21 ` [PATCH 2/3] push: fail early with detached HEAD and current Ramkumar Ramachandra
@ 2013-05-29 19:34   ` Junio C Hamano
  2013-05-29 19:37     ` Ramkumar Ramachandra
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2013-05-29 19:34 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List

Ramkumar Ramachandra <artagnon@gmail.com> writes:

> Setting push.default to current adds the refspec "HEAD" for the
> transport layer to handle.  If "HEAD" doesn't resolve to a branch (and
> since no refspec rhs is specified), the push fails after some time with
> a cryptic error message:
>
>   $ git push
>   error: unable to push to unqualified destination: HEAD
>   The destination refspec neither matches an existing ref on the remote nor
>   begins with refs/, and we are unable to guess a prefix based on the source ref.
>   error: failed to push some refs to 'git@github.com:artagnon/git'
>
> Fail early with a nicer error message:
>
>   $ git push
>   fatal: You are not currently on a branch.
>   To push the history leading to the current (detached HEAD)
>   state now, use
>
>     git push ram HEAD:<name-of-remote-branch>
>
> Just like in the upstream and simple cases.
>
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> ---
>  builtin/push.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/builtin/push.c b/builtin/push.c
> index ef3aa97..a79038c 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -175,6 +175,8 @@ static void warn_unspecified_push_default_configuration(void)
>  
>  static void setup_default_push_refspecs(struct remote *remote)
>  {
> +	struct branch *branch = branch_get(NULL);
> +
>  	switch (push_default) {
>  	default:
>  	case PUSH_DEFAULT_UNSPECIFIED:
> @@ -194,6 +196,8 @@ static void setup_default_push_refspecs(struct remote *remote)
>  		break;
>  
>  	case PUSH_DEFAULT_CURRENT:
> +		if (!branch)
> +			die(_(message_detached_head_die), remote->name);
>  		add_refspec("HEAD");
>  		break;

This means well, but I am not sure calling branch_get() for all
other cases that do not care about the current branch is a right
thing to do.  It's not like you need branch variable to free some
resource after done, or pass it around to callees from this
function.

Would it hurt to do

	if (!branch_get(NULL))
		die(...);

here, without the first hunk?  

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] push: fail early with detached HEAD and current
  2013-05-29 19:34   ` Junio C Hamano
@ 2013-05-29 19:37     ` Ramkumar Ramachandra
  2013-05-29 19:59       ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-29 19:37 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

Junio C Hamano wrote:
>>       case PUSH_DEFAULT_CURRENT:
>> +             if (!branch)
>> +                     die(_(message_detached_head_die), remote->name);
>>               add_refspec("HEAD");
>>               break;
>
> Would it hurt to do
>
>         if (!branch_get(NULL))
>                 die(...);
>
> here, without the first hunk?

And how would I change the add_refspec() call to take branch->name in [3/3]?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] push: fail early with detached HEAD and current
  2013-05-29 19:37     ` Ramkumar Ramachandra
@ 2013-05-29 19:59       ` Junio C Hamano
  2013-05-29 20:04         ` Ramkumar Ramachandra
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2013-05-29 19:59 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List

Ramkumar Ramachandra <artagnon@gmail.com> writes:

> Junio C Hamano wrote:
>>>       case PUSH_DEFAULT_CURRENT:
>>> +             if (!branch)
>>> +                     die(_(message_detached_head_die), remote->name);
>>>               add_refspec("HEAD");
>>>               break;
>>
>> Would it hurt to do
>>
>>         if (!branch_get(NULL))
>>                 die(...);
>>
>> here, without the first hunk?
>
> And how would I change the add_refspec() call to take branch->name in [3/3]?

By doing something like this, perhaps?

	struct ... branch;

        switch (...) {
        ...
        case it-only-matters-here:
        	branch = branch_get(NULL);
                if (!branch)
			die(...);
	}

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] push: fail early with detached HEAD and current
  2013-05-29 19:59       ` Junio C Hamano
@ 2013-05-29 20:04         ` Ramkumar Ramachandra
  0 siblings, 0 replies; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-29 20:04 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

Here: put this at the end of the series and autosquash.

-- 8< --
From: Ramkumar Ramachandra <artagnon@gmail.com>
Date: Thu, 30 May 2013 01:29:59 +0530
Subject: [PATCH] fixup! HEAD~2

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/push.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/builtin/push.c b/builtin/push.c
index d819487..2d84d10 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -175,7 +175,7 @@ static void
warn_unspecified_push_default_configuration(void)

 static void setup_default_push_refspecs(struct remote *remote)
 {
-       struct branch *branch = branch_get(NULL);
+       struct branch *branch;

        switch (push_default) {
        default:
@@ -196,6 +196,7 @@ static void setup_default_push_refspecs(struct
remote *remote)
                break;

        case PUSH_DEFAULT_CURRENT:
+               branch = branch_get(NULL);
                if (!branch)
                        die(_(message_detached_head_die), remote->name);
                add_refspec(branch->name);
-- 
1.8.3.12.gbd56588

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] push: fail early with detached HEAD and current
  2013-05-21 18:23 [PATCH 0/3] Fixing volatile HEAD in push.default = current Ramkumar Ramachandra
@ 2013-05-21 18:23 ` Ramkumar Ramachandra
  0 siblings, 0 replies; 9+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-21 18:23 UTC (permalink / raw)
  To: Git List

Setting push.default to current adds the refspec "HEAD" for the
transport layer to handle.  If "HEAD" doesn't resolve to a branch (and
since no refspec rhs is specified), the push fails after some time with
a cryptic error message:

  $ git push
  error: unable to push to unqualified destination: HEAD
  The destination refspec neither matches an existing ref on the remote nor
  begins with refs/, and we are unable to guess a prefix based on the source ref.
  error: failed to push some refs to 'git@github.com:artagnon/git'

Fail early with a nicer error message:

  $ git push
  fatal: You are not currently on a branch.
  To push the history leading to the current (detached HEAD)
  state now, use

    git push ram HEAD:<name-of-remote-branch>

Just like in the upstream and simple cases.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/push.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/builtin/push.c b/builtin/push.c
index ef3aa97..a79038c 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -175,6 +175,8 @@ static void warn_unspecified_push_default_configuration(void)
 
 static void setup_default_push_refspecs(struct remote *remote)
 {
+	struct branch *branch = branch_get(NULL);
+
 	switch (push_default) {
 	default:
 	case PUSH_DEFAULT_UNSPECIFIED:
@@ -194,6 +196,8 @@ static void setup_default_push_refspecs(struct remote *remote)
 		break;
 
 	case PUSH_DEFAULT_CURRENT:
+		if (!branch)
+			die(_(message_detached_head_die), remote->name);
 		add_refspec("HEAD");
 		break;
 
-- 
1.8.3.rc3.7.gc1ff30b

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-05-29 20:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-29 19:21 [PATCH v2 0/3] Early HEAD resolution in push.default = current Ramkumar Ramachandra
2013-05-29 19:21 ` [PATCH 1/3] push: factor out the detached HEAD error message Ramkumar Ramachandra
2013-05-29 19:21 ` [PATCH 2/3] push: fail early with detached HEAD and current Ramkumar Ramachandra
2013-05-29 19:34   ` Junio C Hamano
2013-05-29 19:37     ` Ramkumar Ramachandra
2013-05-29 19:59       ` Junio C Hamano
2013-05-29 20:04         ` Ramkumar Ramachandra
2013-05-29 19:21 ` [PATCH 3/3] push: make push.default = current use resolved HEAD Ramkumar Ramachandra
  -- strict thread matches above, loose matches on Subject: below --
2013-05-21 18:23 [PATCH 0/3] Fixing volatile HEAD in push.default = current Ramkumar Ramachandra
2013-05-21 18:23 ` [PATCH 2/3] push: fail early with detached HEAD and current Ramkumar Ramachandra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.