git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] t6300: avoid creating refs/heads/HEAD
@ 2017-02-27  9:29 Jeff King
  2017-02-27 19:33 ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff King @ 2017-02-27  9:29 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

In one test, we use "git checkout --orphan HEAD" to create
an unborn branch. Confusingly, the resulting branch is named
"refs/heads/HEAD". The original probably meant something
like:

  git checkout --orphan orphaned-branch HEAD

Let's just use "orphaned-branch" here to make this less
confusing. Putting HEAD in the second argument is already
implied.

Signed-off-by: Jeff King <peff@peff.net>
---
This comes originally from Junio's 84679d470. I cannot see how naming
the new branch HEAD would make any difference to the test, but perhaps I
am missing something.

I noticed this while digging on a nearby issue around "git branch -m @".
This does happen to be the only test that checks that we can make a
branch called refs/heads/HEAD, and I found it because it triggers if you
try to disallow "git branch -m HEAD". :)

If we care about that, though, I think we should make an explicit test
for "git branch HEAD". But I'm not sure we _do_ care about that. Making
a branch called HEAD is moderately insane, and I don't think it would be
unreasonable for us to outlaw it at some point.

 t/t6300-for-each-ref.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index aea1dfc71..a468041c5 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -558,7 +558,7 @@ test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
 	test_when_finished "git checkout master" &&
 	git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
 	sed -e "s/^\* /  /" actual >expect &&
-	git checkout --orphan HEAD &&
+	git checkout --orphan orphaned-branch &&
 	git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
 	test_cmp expect actual
 '
-- 
2.12.0.624.gbb1b07a2c

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

* Re: [PATCH] t6300: avoid creating refs/heads/HEAD
  2017-02-27  9:29 [PATCH] t6300: avoid creating refs/heads/HEAD Jeff King
@ 2017-02-27 19:33 ` Junio C Hamano
  2017-02-27 20:51   ` Jeff King
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2017-02-27 19:33 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Jeff King <peff@peff.net> writes:

> This comes originally from Junio's 84679d470. I cannot see how naming
> the new branch HEAD would make any difference to the test, but perhaps I
> am missing something.

Nah, I think it was just a random string that came to mind and the
topic being "ah we blindly dereference something when showing %(HEAD)"
it was plausible I thought of "H E A D" as that random string before
I used my usual other random strings like frotz ;-)

> I noticed this while digging on a nearby issue around "git branch -m @".
> This does happen to be the only test that checks that we can make a
> branch called refs/heads/HEAD, and I found it because it triggers if you
> try to disallow "git branch -m HEAD". :)

About that "nearby" one, does it even make sense to do the interpret
thing on the <new> name?  I can understand "please rename the branch
I was previously on to this new name" wanting to say @{-1} when the
user does not recall the exact spelling of a long name, but I do not
quite see how "to this new name" part benefits by the "interpret
branch name" magic in the first place.

> If we care about that, though, I think we should make an explicit test
> for "git branch HEAD". But I'm not sure we _do_ care about that. Making
> a branch called HEAD is moderately insane, and I don't think it would be
> unreasonable for us to outlaw it at some point.

Yeah, at that point we would have "test_must_fail git branch HEAD".

>  t/t6300-for-each-ref.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
> index aea1dfc71..a468041c5 100755
> --- a/t/t6300-for-each-ref.sh
> +++ b/t/t6300-for-each-ref.sh
> @@ -558,7 +558,7 @@ test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
>  	test_when_finished "git checkout master" &&
>  	git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
>  	sed -e "s/^\* /  /" actual >expect &&
> -	git checkout --orphan HEAD &&
> +	git checkout --orphan orphaned-branch &&
>  	git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
>  	test_cmp expect actual
>  '

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

* Re: [PATCH] t6300: avoid creating refs/heads/HEAD
  2017-02-27 19:33 ` Junio C Hamano
@ 2017-02-27 20:51   ` Jeff King
  2017-02-27 21:19     ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff King @ 2017-02-27 20:51 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Mon, Feb 27, 2017 at 11:33:23AM -0800, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > This comes originally from Junio's 84679d470. I cannot see how naming
> > the new branch HEAD would make any difference to the test, but perhaps I
> > am missing something.
> 
> Nah, I think it was just a random string that came to mind and the
> topic being "ah we blindly dereference something when showing %(HEAD)"
> it was plausible I thought of "H E A D" as that random string before
> I used my usual other random strings like frotz ;-)

OK, thanks for confirming.

> > I noticed this while digging on a nearby issue around "git branch -m @".
> > This does happen to be the only test that checks that we can make a
> > branch called refs/heads/HEAD, and I found it because it triggers if you
> > try to disallow "git branch -m HEAD". :)
> 
> About that "nearby" one, does it even make sense to do the interpret
> thing on the <new> name?  I can understand "please rename the branch
> I was previously on to this new name" wanting to say @{-1} when the
> user does not recall the exact spelling of a long name, but I do not
> quite see how "to this new name" part benefits by the "interpret
> branch name" magic in the first place.

Yeah, it's arguable whether the "new" side of a rename should do any
interpretation at all. At the same time, the bug is in the underlying
function that assumes you can slap "refs/heads/" in front of the results
of interpret_branch_name(). And that function gets used in a lot of
places, including the "old" side of a rename. So:

  git branch @{-1} foo

should clearly work. Doing:

  git branch @{upstream} foo

is more debatable. It _does_ work, but only if your upstream is actually
a local branch (otherwise it tries to rename refs/heads/origin/master or
some such nonsense. It happens to fail most of the time because you
probably don't have such a branch, but it's still wrong to even look at
that).

I suspect there are a lot of other places that are less clear cut. E.g.,
I think just:

  git branch foo bar

will put "foo" through the same interpretation. So you could do:

  git branch -f @{-1} bar

Is that insane? Maybe. But it does work now.

-Peff

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

* Re: [PATCH] t6300: avoid creating refs/heads/HEAD
  2017-02-27 20:51   ` Jeff King
@ 2017-02-27 21:19     ` Junio C Hamano
  2017-02-27 21:41       ` Jeff King
  2017-02-27 21:44       ` Junio C Hamano
  0 siblings, 2 replies; 8+ messages in thread
From: Junio C Hamano @ 2017-02-27 21:19 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Jeff King <peff@peff.net> writes:

> I suspect there are a lot of other places that are less clear cut. E.g.,
> I think just:
>
>   git branch foo bar
>
> will put "foo" through the same interpretation. So you could do:
>
>   git branch -f @{-1} bar
>
> Is that insane? Maybe. But it does work now.

No, it _is_ very sensible, so is "git checkout -B @{-1} <someplace>"

Perhaps interpret-branch-name that does not error out when given "@"
is what is broken?  I suspect that calling interpret_empty_at() from
that function is fundamentally flawed.  The "@" end user types never
means refs/heads/HEAD, and HEAD@{either reflog or -1} would not mean
anything that should be taken as a branch_name, either.  

So perhaps what interpret_empty_at() does is necessary for the "four
capital letters is too many to type, so just type one key while
holding a shift", but it should be called from somewhere else, and
not from interpret_branch_name()?






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

* Re: [PATCH] t6300: avoid creating refs/heads/HEAD
  2017-02-27 21:19     ` Junio C Hamano
@ 2017-02-27 21:41       ` Jeff King
  2017-02-27 22:18         ` Junio C Hamano
  2017-02-27 21:44       ` Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Jeff King @ 2017-02-27 21:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Mon, Feb 27, 2017 at 01:19:29PM -0800, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > I suspect there are a lot of other places that are less clear cut. E.g.,
> > I think just:
> >
> >   git branch foo bar
> >
> > will put "foo" through the same interpretation. So you could do:
> >
> >   git branch -f @{-1} bar
> >
> > Is that insane? Maybe. But it does work now.
> 
> No, it _is_ very sensible, so is "git checkout -B @{-1} <someplace>"
> 
> Perhaps interpret-branch-name that does not error out when given "@"
> is what is broken?  I suspect that calling interpret_empty_at() from
> that function is fundamentally flawed.  The "@" end user types never
> means refs/heads/HEAD, and HEAD@{either reflog or -1} would not mean
> anything that should be taken as a branch_name, either.
> 
> So perhaps what interpret_empty_at() does is necessary for the "four
> capital letters is too many to type, so just type one key while
> holding a shift", but it should be called from somewhere else, and
> not from interpret_branch_name()?

I think _most_ of interpret_branch_name() is in the same boat. The
"@{upstream}" mark is not likely to give you a branch in refs/heads
either.

So in practice, I think strbuf_check_branch_ref() could probably get by
with just calling interpret_nth_prior_checkout(). Or if you prefer, to
rip everything out of interpret_branch_name() except that. :) But that
other stuff has to go somewhere, and there are some challenges with the
recursion from reinterpret().

The "other" stuff could sometimes be useful, I guess. It's not _always_
wrong to do:

  git branch -f @{upstream} foo

It depends on what your @{upstream} resolves to. Switching to just using
interpret_nth_prior_checkout() would break the case when it resolves to
a local branch. I'm not sure if we're OK with that or not. If we want to
keep all the existing cases working, I think we need something like the
"not_in_refs_heads" patch I posted elsewhere.

-Peff

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

* Re: [PATCH] t6300: avoid creating refs/heads/HEAD
  2017-02-27 21:19     ` Junio C Hamano
  2017-02-27 21:41       ` Jeff King
@ 2017-02-27 21:44       ` Junio C Hamano
  2017-02-27 21:46         ` Jeff King
  1 sibling, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2017-02-27 21:44 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> ...  I suspect that calling interpret_empty_at() from
> that function is fundamentally flawed.  The "@" end user types never
> means refs/heads/HEAD, and HEAD@{either reflog or -1} would not mean
> anything that should be taken as a branch_name, either.  

The latter should read "HEAD@{either reflog or -1 or 'upstream'}"

Or do we make HEAD@{upstream} to mean "deref HEAD to learn the
current branch name and then take its upstream"?  If so @@{upstream}
might logically make sense, but I do not see why @{upstream} without
HEAD or @ is not sufficient to begin with, so...


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

* Re: [PATCH] t6300: avoid creating refs/heads/HEAD
  2017-02-27 21:44       ` Junio C Hamano
@ 2017-02-27 21:46         ` Jeff King
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff King @ 2017-02-27 21:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Mon, Feb 27, 2017 at 01:44:26PM -0800, Junio C Hamano wrote:

> Junio C Hamano <gitster@pobox.com> writes:
> 
> > ...  I suspect that calling interpret_empty_at() from
> > that function is fundamentally flawed.  The "@" end user types never
> > means refs/heads/HEAD, and HEAD@{either reflog or -1} would not mean
> > anything that should be taken as a branch_name, either.  
> 
> The latter should read "HEAD@{either reflog or -1 or 'upstream'}"
> 
> Or do we make HEAD@{upstream} to mean "deref HEAD to learn the
> current branch name and then take its upstream"?  If so @@{upstream}
> might logically make sense, but I do not see why @{upstream} without
> HEAD or @ is not sufficient to begin with, so...

Yes, HEAD@{upstream} and @@{upstream} are both resolved to the actual
branch name. I also was puzzled whether there was any real use over just
@{upstream}. But it does work, and if you had a script which looked for,
say, $branch@{upstream}, you'd probably want branch=HEAD to keep
working.

The "branch=@" case I am less sympathetic to, as it was mainly supposed
to be a command-line convenience. But it _does_ work now.

-Peff

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

* Re: [PATCH] t6300: avoid creating refs/heads/HEAD
  2017-02-27 21:41       ` Jeff King
@ 2017-02-27 22:18         ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2017-02-27 22:18 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Jeff King <peff@peff.net> writes:

> The "other" stuff could sometimes be useful, I guess. It's not _always_
> wrong to do:
>
>   git branch -f @{upstream} foo
>
> It depends on what your @{upstream} resolves to. Switching to just using
> interpret_nth_prior_checkout() would break the case when it resolves to
> a local branch. I'm not sure if we're OK with that or not. If we want to
> keep all the existing cases working, I think we need something like the
> "not_in_refs_heads" patch I posted elsewhere.

I haven't seen that patch, but yes, telling the caller if the
returned value is meant to be used inside refs/heads/ is the right
approach and makes it possible for "@{upstream}" (and just "@") to
be handled sensibly in "git branch -m @{that at-mark thing}".


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

end of thread, other threads:[~2017-02-27 23:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-27  9:29 [PATCH] t6300: avoid creating refs/heads/HEAD Jeff King
2017-02-27 19:33 ` Junio C Hamano
2017-02-27 20:51   ` Jeff King
2017-02-27 21:19     ` Junio C Hamano
2017-02-27 21:41       ` Jeff King
2017-02-27 22:18         ` Junio C Hamano
2017-02-27 21:44       ` Junio C Hamano
2017-02-27 21:46         ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).