git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-rebase: Print name of rev when using shorthand

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 14, 2014, 19:22 UTC
Message-ID
<xmqqwqerogvr.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1397419474-31999-1-git-send-email-modocache@gmail.com>
Brian Gesiak <modocache@gmail.com> writes:
Show 17 quoted lines
> The output from a successful invocation of the shorthand command
> "git rebase -" is something like "Fast-forwarded HEAD to @{-1}",
> which includes a relative reference to a revision. Other commands
> that use the shorthand "-", such as "git checkout -", typically
> display the symbolic name of the revision.
>
> Change rebase to output the symbolic name of the revision when using
> the shorthand. For the example above, the new output is
> "Fast-forwarded HEAD to master", assuming "@{-1}" is a reference to
> "master".
>
> - Use "git name-rev" to retreive the name of the rev.
> - Update the tests in light of this new behavior.
>
> Requested-by: John Keeping <john@keeping.me.uk>
> Signed-off-by: Brian Gesiak <modocache@gmail.com>
> ---

What the patch wants to implement sounds sensible, but I do not think name-rev is a right tool for this. Imagine the case where there are more than one branches whose tip points at the commit you came from. name-rev will not be able to pick correctly which one to report.

Also think what happens if you were previously on a detached HEAD?
I think you would want to use something like:
        upstream_name=$(git rev-parse --symbolic-full-name @{-1})
        if test -n "$upstream"
        then
                upstream_name=${upstream_name#refs/heads/}
        else
                upstream_name="@{-1}"
        fi
if the change is to be made at that point in the code.

I also wonder if "git rebase @{-1}" deserve a similar translation like you are giving "git rebase -".

Show 30 quoted lines
> Previous discussion on this issue:
> http://article.gmane.org/gmane.comp.version-control.git/244340
>
>  git-rebase.sh     | 2 +-
>  t/t3400-rebase.sh | 4 +---
>  2 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/git-rebase.sh b/git-rebase.sh
> index 2c75e9f..ab0e081 100755
> --- a/git-rebase.sh
> +++ b/git-rebase.sh
> @@ -455,7 +455,7 @@ then
>  	*)	upstream_name="$1"
>  		if test "$upstream_name" = "-"
>  		then
> -			upstream_name="@{-1}"
> +			upstream_name=`git name-rev --name-only @{-1}`
>  		fi
>  		shift
>  		;;
> diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
> index 80e0a95..2b99940 100755
> --- a/t/t3400-rebase.sh
> +++ b/t/t3400-rebase.sh
> @@ -91,7 +91,7 @@ test_expect_success 'rebase from ambiguous branch name' '
>  test_expect_success 'rebase off of the previous branch using "-"' '
>  	git checkout master &&
>  	git checkout HEAD^ &&
> -	git rebase @{-1} >expect.messages &&
> +	git rebase master >expect.messages &&
OK.
Show 11 quoted lines
>  	git merge-base master HEAD >expect.forkpoint &&
>  
>  	git checkout master &&
> @@ -100,8 +100,6 @@ test_expect_success 'rebase off of the previous branch using "-"' '
>  	git merge-base master HEAD >actual.forkpoint &&
>  
>  	test_cmp expect.forkpoint actual.forkpoint &&
> -	# the next one is dubious---we may want to say "-",
> -	# instead of @{-1}, in the message
>  	test_i18ncmp expect.messages actual.messages
>  '
Previous: Brian GesiakNext: Brian Gesiak
Message 2 of 6 in “git-rebase: Print name of rev when using shorthand”
  1. git-rebase: Print name of rev when using shorthandBrian Gesiak, Apr 13, 2014
  2. Junio C HamanoApr 14, 2014
  3. Brian GesiakApr 16, 2014
  4. Junio C HamanoApr 16, 2014
  5. Junio C HamanoApr 16, 2014
  6. Brian GesiakApr 16, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.