From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Git Mailing list <git@vger.kernel.org>
Subject: Can @{-N} always be used where a branch name is expected?
Date: Sun, 19 Nov 2017 23:39:04 +0530 [thread overview]
Message-ID: <38b4b665-18c4-5c95-f142-aedf33bc1b5c@gmail.com> (raw)
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
reply other threads:[~2017-11-19 18:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=38b4b665-18c4-5c95-f142-aedf33bc1b5c@gmail.com \
--to=kaartic.sivaraam@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).