Re: $> git branch splat response considered harmful

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

 



On Thu, Aug 8, 2019 at 2:20 PM Bryan Turner <bturner@xxxxxxxxxxxxx> wrote:
>
> On Thu, Aug 8, 2019 at 2:08 PM <jim.cromie@xxxxxxxxx> wrote:
> >
> > fwiw,
> >
> > jimc@frodo:~/prj-1/capnproto.git$ git branch -l
> > * master
> >
> > I find the splat in the response unhelpful
> > when wrapped in shell for loop, the splat expands into everything in
> > current directory
> >
> > jimc@frodo:~/prj-1/capnproto.git$ for b in `git branch -l`; do echo $b; done
> > appveyor.yml
> > c++
> > CMakeLists.txt
> > CONTRIBUTORS
> > ...
> >
> > it would be nice if some flag combo would suppress that splat.
> > save me from fugly brittle sh $IFS fiddlery and incomplete workarounds
>
> Have you tried "git for-each-ref --format="%(refname:short)"
> refs/heads/"? That's going to provide short names for branches without
> any indicator for the default branch, and without any special
> ordering.

More generally, I think you should take a look at `git help git` and
check out the difference between "porcelain" and "plumbing" commands.
The former, of which `git branch` is one, are intended for interactive
use and not really meant for scripting or piping. You can usually come
up with an equivalent from the plumbing commands, which Bryan has
suggested for you with `git for-each-ref`.  Git project tries very
hard to maintain output format of the plumbing commands so as to not
break folks' scripts, but such promises aren't usually made for
porcelain commands.

-- 
Emily Shaffer



[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]

  Powered by Linux