[PATCH 1/2] t3203: test 'detached at' after checkout --detach

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/2] t3203: test 'detached at' after checkout --detach

Matthieu Moy
This currently fails: the output is 'HEAD detached at HEAD'.
---
 t/t3203-branch-output.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index f51d0f3..bf24dbf 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -106,6 +106,19 @@ EOF
  test_i18ncmp expect actual
 '
 
+test_expect_failure 'git branch shows detached HEAD properly after checkout --detach' '
+ git checkout master &&
+ cat >expect <<EOF &&
+* (HEAD detached at $(git rev-parse --short HEAD^0))
+  branch-one
+  branch-two
+  master
+EOF
+ git checkout --detach &&
+ git branch >actual &&
+ test_i18ncmp expect actual
+'
+
 test_expect_success 'git branch shows detached HEAD properly after moving' '
  cat >expect <<EOF &&
 * (HEAD detached from $(git rev-parse --short HEAD))
--
2.5.0.402.g8854c44

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/2] status: don't say 'HEAD detached at HEAD'

Matthieu Moy
After using "git checkout --detach", the reflog is left with an entry
like

  checkout: moving from ... to HEAD

This message is parsed to generate the 'HEAD detached at' message in
'git branch' and 'git status', which leads to the not-so-useful message
'HEAD detached at HEAD'.

Instead, when parsing such reflog entry, resolve HEAD to the
corresponding commit in the reflog, so that the message becomes 'HEAD
detached at $sha1'.
---
Another possible fix is to avoid creating such reflog entry. But
anyway, this patch remains a good thing to do and it does fix the
issue.

I won't have time to work on fixing the reflog soon, but it may be a
nice microproject.

 t/t3203-branch-output.sh | 2 +-
 wt-status.c              | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index bf24dbf..16efe7a 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -106,7 +106,7 @@ EOF
  test_i18ncmp expect actual
 '
 
-test_expect_failure 'git branch shows detached HEAD properly after checkout --detach' '
+test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
  git checkout master &&
  cat >expect <<EOF &&
 * (HEAD detached at $(git rev-parse --short HEAD^0))
diff --git a/wt-status.c b/wt-status.c
index c327fe8..3e3b8c0 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1319,6 +1319,12 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
  hashcpy(cb->nsha1, nsha1);
  for (end = target; *end && *end != '\n'; end++)
  ;
+ if (!memcmp(target, "HEAD", end - target)) {
+ /* HEAD is relative. Resolve it to the right reflog entry. */
+ strbuf_addstr(&cb->buf,
+      find_unique_abbrev(nsha1, DEFAULT_ABBREV));
+ return 1;
+ }
  strbuf_add(&cb->buf, target, end - target);
  return 1;
 }
--
2.5.0.402.g8854c44

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] status: don't say 'HEAD detached at HEAD'

MichaelJGruber
Matthieu Moy venit, vidit, dixit 27.09.2015 17:13:

> After using "git checkout --detach", the reflog is left with an entry
> like
>
>   checkout: moving from ... to HEAD
>
> This message is parsed to generate the 'HEAD detached at' message in
> 'git branch' and 'git status', which leads to the not-so-useful message
> 'HEAD detached at HEAD'.
>
> Instead, when parsing such reflog entry, resolve HEAD to the
> corresponding commit in the reflog, so that the message becomes 'HEAD
> detached at $sha1'.
> ---
> Another possible fix is to avoid creating such reflog entry. But
> anyway, this patch remains a good thing to do and it does fix the
> issue.
>
> I won't have time to work on fixing the reflog soon, but it may be a
> nice microproject.
>
>  t/t3203-branch-output.sh | 2 +-
>  wt-status.c              | 6 ++++++
>  2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
> index bf24dbf..16efe7a 100755
> --- a/t/t3203-branch-output.sh
> +++ b/t/t3203-branch-output.sh
> @@ -106,7 +106,7 @@ EOF
>   test_i18ncmp expect actual
>  '
>  
> -test_expect_failure 'git branch shows detached HEAD properly after checkout --detach' '
> +test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
>   git checkout master &&
>   cat >expect <<EOF &&
>  * (HEAD detached at $(git rev-parse --short HEAD^0))
> diff --git a/wt-status.c b/wt-status.c
> index c327fe8..3e3b8c0 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -1319,6 +1319,12 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
>   hashcpy(cb->nsha1, nsha1);
>   for (end = target; *end && *end != '\n'; end++)
>   ;
> + if (!memcmp(target, "HEAD", end - target)) {
> + /* HEAD is relative. Resolve it to the right reflog entry. */
> + strbuf_addstr(&cb->buf,
> +      find_unique_abbrev(nsha1, DEFAULT_ABBREV));
> + return 1;
> + }
>   strbuf_add(&cb->buf, target, end - target);
>   return 1;
>  }
>

Reviewed and compile tested, thanks.

Junio will also want your s-o-by, though ;)

(Typically we don't introduce a failing test separately like 1/2 any
more and do it in 1 patch, but I don't care either way.)

Michael
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] status: don't say 'HEAD detached at HEAD'

Matthieu Moy-2
Michael J Gruber <[hidden email]> writes:

> Junio will also want your s-o-by, though ;)

Argh, sorry. I normally have an alias to do this for me, but my
git-send-email is temporarily broken and I forget to sign-off
explicitly.

I see that Junio already queued the patches in pu.

In case it matters, both patches are

Signed-off-by: Matthieu Moy <[hidden email]>

and I can resend if needed.

--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html