Re: git-check-ref-format returns 1 for valid branch names
- From
Nikolai Weibull <now@bitwi.se>
- Date
- Mar 22, 2007, 21:58 UTC
- Message-ID
- <dbfc82860703221458j690d1cafve01174eda8f149ee@mail.gmail.com>
- In-Reply-To
- <Pine.LNX.4.64.0703221358420.6730@woody.linux-foundation.org>
On 3/22/07, Linus Torvalds <torvalds@linux-foundation.org> wrote:
Show 25 quoted lines
> > > On Thu, 22 Mar 2007, Junio C Hamano wrote: > > > "Nikolai Weibull" <now@bitwi.se> writes: > > > > > I'm obviously doing something wrong, but in git 1.5.0.4 > > > > > > % git check-ref-format abc > > > % echo $? > > > 1 > > > > > > What am I missing here? > > > > If you are trying to see if abc is a valid branch name, try refs/heads/abc. > > .. and before anybody wonders why it wants the "fully qualified" name, > it's because "abc" on its own is ambiguous. Is it a _tag_ called "abc", or > a branch, or what? That explains why - if you really want to verify a > ref-name, you need to give the full name.. > > On the other hand, if you don't care, and you just want "is this a valid > commit name", use > > sha1=$(git rev-parse --verify "$name"^0) || exit
Thanks for the clarification.
What I was after was a way to verify that a name is a valid new name of a branch, for the Zsh completion definition in the context of git-checkout -b <new_branch>. [1] After posting I realized that perhaps checking out the sources for git-checkout would enlighten me, which it did, as it uses git-check-ref-format "heads/$newbranch" to verify that the new branch's name is valid.
[1] It's not really going to try to complete anything here, but verify that the new branch's name is valid while the user types it in. [2] [2] Hm, perhaps completing existing branch-names makes more sense, allowing the user to create a new branch-name based on an old one.