git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* $> git branch splat response considered harmful
@ 2019-08-08 21:08 jim.cromie
  2019-08-08 21:20 ` Bryan Turner
  2019-08-08 21:30 ` SZEDER Gábor
  0 siblings, 2 replies; 6+ messages in thread
From: jim.cromie @ 2019-08-08 21:08 UTC (permalink / raw)
  To: git

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

git branch -l  # no splat
  master
git branch # splat ok for back-compat (if you think it necessary)
  * master

it appears that by convention, checked out branch is both 1st in list,
and splatted,
perhaps _DIRTY_, JUNK, or maybe "" would be good 1st line of response
if not on a branch ?

also, I found no mention of the splat in the man page.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: $> git branch splat response considered harmful
  2019-08-08 21:08 $> git branch splat response considered harmful jim.cromie
@ 2019-08-08 21:20 ` Bryan Turner
  2019-08-08 21:28   ` Emily Shaffer
  2019-08-08 21:30 ` SZEDER Gábor
  1 sibling, 1 reply; 6+ messages in thread
From: Bryan Turner @ 2019-08-08 21:20 UTC (permalink / raw)
  To: jim.cromie; +Cc: Git Users

On Thu, Aug 8, 2019 at 2:08 PM <jim.cromie@gmail.com> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: $> git branch splat response considered harmful
  2019-08-08 21:20 ` Bryan Turner
@ 2019-08-08 21:28   ` Emily Shaffer
  2019-08-08 21:46     ` Junio C Hamano
  2019-08-09 18:01     ` Philip Oakley
  0 siblings, 2 replies; 6+ messages in thread
From: Emily Shaffer @ 2019-08-08 21:28 UTC (permalink / raw)
  To: Bryan Turner; +Cc: jim.cromie, Git Users

On Thu, Aug 8, 2019 at 2:20 PM Bryan Turner <bturner@atlassian.com> wrote:
>
> On Thu, Aug 8, 2019 at 2:08 PM <jim.cromie@gmail.com> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: $> git branch splat response considered harmful
  2019-08-08 21:08 $> git branch splat response considered harmful jim.cromie
  2019-08-08 21:20 ` Bryan Turner
@ 2019-08-08 21:30 ` SZEDER Gábor
  1 sibling, 0 replies; 6+ messages in thread
From: SZEDER Gábor @ 2019-08-08 21:30 UTC (permalink / raw)
  To: jim.cromie; +Cc: git

On Thu, Aug 08, 2019 at 03:08:06PM -0600, jim.cromie@gmail.com 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

'git branch' is not intended for scripting, try 'git for-each-ref'
instead.  The equivalent command should be:

  git for-each-ref --format='%(refname:strip=2)' refs/heads/

> also, I found no mention of the splat in the man page.

It's in the first sentence of the description :)

  If --list is given, or if there are no non-option arguments, existing
  branches are listed; the current branch will be highlighted in green
  and marked with an asterisk.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: $> git branch splat response considered harmful
  2019-08-08 21:28   ` Emily Shaffer
@ 2019-08-08 21:46     ` Junio C Hamano
  2019-08-09 18:01     ` Philip Oakley
  1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2019-08-08 21:46 UTC (permalink / raw)
  To: Emily Shaffer; +Cc: Bryan Turner, jim.cromie, Git Users

Emily Shaffer <emilyshaffer@google.com> writes:

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

Thanks for a detailed response.

Git project promises that output format of the Porcelain commands is
subject to change, in order to support human eyeballs better.

Unless documented otherwise (e.g. "git status --porcelain"), it is
unwise to try parsing porcelain output---your script may break any
time and you get to keep both halves.

That is not the same as saying "do not script using Porcelain".
Sending the output directly to the end user (e.g. compute the
revision range in your script that finally calls "git log" using
that computed revision range) is perfectly fine.

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: $> git branch splat response considered harmful
  2019-08-08 21:28   ` Emily Shaffer
  2019-08-08 21:46     ` Junio C Hamano
@ 2019-08-09 18:01     ` Philip Oakley
  1 sibling, 0 replies; 6+ messages in thread
From: Philip Oakley @ 2019-08-09 18:01 UTC (permalink / raw)
  To: Emily Shaffer, Bryan Turner; +Cc: jim.cromie, Git Users

On 08/08/2019 22:28, Emily Shaffer wrote:
> On Thu, Aug 8, 2019 at 2:20 PM Bryan Turner <bturner@atlassian.com> wrote:
>> On Thu, Aug 8, 2019 at 2:08 PM <jim.cromie@gmail.com> 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.
>
I think this (the broad Q&A) also suggests that the porcelain command 
documentation could be more helpful for pointing to the appropriate 
plumbing commands for these scripting issues (and it could reduce list 
noise..).
--
Philip

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-08-09 18:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-08 21:08 $> git branch splat response considered harmful jim.cromie
2019-08-08 21:20 ` Bryan Turner
2019-08-08 21:28   ` Emily Shaffer
2019-08-08 21:46     ` Junio C Hamano
2019-08-09 18:01     ` Philip Oakley
2019-08-08 21:30 ` SZEDER Gábor

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