Re: Strange behavior (possible bug) using bash command subsitution with "git branch"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/8/09 3:03 PM, "Jeff King" <peff@xxxxxxxx> wrote:

> On Sun, Nov 08, 2009 at 11:49:55PM +0100, Björn Steinbrink wrote:
> 
>>> I ran into a weird situation while working on a script, which is best
>>> described with a little snippet from my gitosis-admin repository:
>>> 
>>>     $ git branch
>>>     * master
>>      ^^^
>> 
>>>     $ branch=$(git branch)
>>>     $ echo $branch
>>>     gitosis.conf keydir master
>> 
>> Your shell expands the *, thus echo sees all the things in the current
>> directory. Use 'echo "$branch"' and you'll see what you expected.
> 
> And more to the point, this is just one reason why one should use
> for-each-ref when scripting (the other is that git-branch's output is
> considered porcelain, and is not guaranteed to remain stable). E.g.:
> 
>   git for-each-ref --format='%(refname:short)' refs/heads/
> 
> would produce the output the original poster wanted.

Ah, sweet, I did not know about that. I ended up doing something entirely
different (short form: my original idea about what I wanted to do was wrong)
but that's very helpful for the future.

Thanks,
Kate Ebneter (who is gradually learning more and more about git)

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]