Jeff King <p...@peff.net> writes:

> Since 39ee4c6c2f (branch: record creation of renamed branch
> in HEAD's log, 2017-02-20), a rename on the currently
> checked out branch will create two entries in the HEAD
> reflog: one where the branch goes away (switching to the
> null oid), and one where it comes back (switching away from
> the null oid).
> ...
> The resulting behavior may not be the _best_ thing to do in
> the long run (for example, we show both reflog entries each
> with the same commit id), but it's a simple way to fix the
> problem without risking further regressions.
>
> Signed-off-by: Jeff King <p...@peff.net>
> ---
> I do still think it would be worth looking into making this rename
> create a single reflog entry, but that's largely orthogonal to making
> the display code sane(r).

I agree with this assessment.

>  reflog-walk.c     |  2 ++
>  t/t3200-branch.sh | 11 +++++++++++
>  2 files changed, 13 insertions(+)
>
> diff --git a/reflog-walk.c b/reflog-walk.c
> index ed99437ad2..b7e489ad32 100644
> --- a/reflog-walk.c
> +++ b/reflog-walk.c
> @@ -259,6 +259,8 @@ void fake_reflog_parent(struct reflog_walk_info *info, 
> struct commit *commit)
>               /* a root commit, but there are still more entries to show */
>               reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
>               logobj = parse_object(&reflog->noid);
> +             if (!logobj)
> +                     logobj = parse_object(&reflog->ooid);
>       }

For the current 'maint', this would need to be backported to the
uchar[20] interface (which is trivial to do, and merging it upwards
while adjusting it back to "struct object_id" is also trivial; there
is no need to resend).

Thanks.  Will queue.

>       if (!logobj || logobj->type != OBJ_COMMIT) {
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index 48d152b9a9..dd37ac47c5 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -162,6 +162,17 @@ test_expect_success 'git branch -M baz bam should add 
> entries to .git/logs/HEAD'
>       grep "^0\{40\}.*$msg$" .git/logs/HEAD
>  '
>  
> +test_expect_success 'resulting reflog can be shown by log -g' '
> +     oid=$(git rev-parse HEAD) &&
> +     cat >expect <<-EOF &&
> +     HEAD@{0} $oid $msg
> +     HEAD@{1} $oid $msg
> +     HEAD@{2} $oid checkout: moving from foo to baz
> +     EOF
> +     git log -g --format="%gd %H %gs" -3 HEAD >actual &&
> +     test_cmp expect actual
> +'
> +
>  test_expect_success 'git branch -M baz bam should succeed when baz is 
> checked out as linked working tree' '
>       git checkout master &&
>       git worktree add -b baz bazdir &&

Reply via email to