git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Can @{-N} always be used where a branch name is expected?
@ 2017-11-19 18:09 Kaartic Sivaraam
  0 siblings, 0 replies; only message in thread
From: Kaartic Sivaraam @ 2017-11-19 18:09 UTC (permalink / raw)
  To: Git Mailing list

I was recently digging to find if there is any special syntax accepted 
for <oldbranch> in "git branch -m <oldbranch> <newbranch>" other than 
the plain branch name. I discovered the @{-N} notation. I was trying to 
play around with it and found that it didn't work as guaranteed by the 
last sentence  of the following paragraph in the "check-ref-format" 
documentation,


     With the --branch option, it expands the “previous branch syntax” 
@{-n}. For example, @{-1} is a way to refer the last branch you were on.
     This option should be used by porcelains to accept this syntax 
anywhere a branch name is expected, so they can act as if you typed the
     branch name.


In particular the following case doesn't work,

git init test &&
cd test &&
echo "Hello" >file &&
git add file &&
git commit -m "Initial commit that will be checked out" &&
echo "Hello world" >file &&
git commit file -m "Second commit" &&
git checkout HEAD^ &&
git checkout - &&
git branch -m @{-1} initial-commit


It failed with an error,

error: refname refs/heads/d21e72600673c670b3ae803488d0cebfa949e4c3 not found
fatal: Branch rename failed


Then I digged into why it didn't work to discover that @{-N}  just 
expands to a valid checkout and not a valid "branch name". So, the 
documentation  guaranteeing that "@{-N} acts as if you typed the branch 
name" seems wrong.  That makes me think that we should avoid misleading 
the user in the "check-ref-format" documentation.

So, should we update the 'check-ref-format' doc or am I missing something?

---
Kaartic

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-11-19 18:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-19 18:09 Can @{-N} always be used where a branch name is expected? Kaartic Sivaraam

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).