{"thread":{"id":"51610","subject":"$> git branch splat response considered harmful","startedAt":"2019-08-08T21:08:36Z","lastAt":"2019-08-09T18:59:02Z","messageCount":6,"participants":["jim.cromie@gmail.com","Bryan Turner","Emily Shaffer","SZEDER Gábor","Junio C Hamano","Philip Oakley"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"380172","messageId":"CAJfuBxx5R28cjUj1v+mB4J+uUpbTMWnYowrCc=iOAbOcqWX-_w@mail.gmail.com","threadId":"51610","inReplyTo":null,"subject":"$> git branch splat response considered harmful","fromName":"","fromEmail":"jim.cromie@gmail.com","sentAt":"2019-08-08T21:08:06Z","receivedAt":"2019-08-08T21:08:36Z","isPatch":false,"sender":{"key":"jim.cromie@gmail.com","avatar":null},"body":"fwiw,\n\njimc@frodo:~/prj-1/capnproto.git$ git branch -l\n* master\n\nI find the splat in the response unhelpful\nwhen wrapped in shell for loop, the splat expands into everything in\ncurrent directory\n\njimc@frodo:~/prj-1/capnproto.git$ for b in `git branch -l`; do echo $b; done\nappveyor.yml\nc++\nCMakeLists.txt\nCONTRIBUTORS\n...\n\nit would be nice if some flag combo would suppress that splat.\nsave me from fugly brittle sh $IFS fiddlery and incomplete workarounds\n\ngit branch -l  # no splat\n  master\ngit branch # splat ok for back-compat (if you think it necessary)\n  * master\n\nit appears that by convention, checked out branch is both 1st in list,\nand splatted,\nperhaps _DIRTY_, JUNK, or maybe \"\" would be good 1st line of response\nif not on a branch ?\n\nalso, I found no mention of the splat in the man page.\n"},{"id":"380174","messageId":"CAGyf7-FUsfKpr+HzOpS9TqE+x7GTnsVKki94gXzMVRwnnweC9g@mail.gmail.com","threadId":"51610","inReplyTo":"CAJfuBxx5R28cjUj1v+mB4J+uUpbTMWnYowrCc=iOAbOcqWX-_w@mail.gmail.com","subject":"Re: $> git branch splat response considered harmful","fromName":"Bryan Turner","fromEmail":"bturner@atlassian.com","sentAt":"2019-08-08T21:20:23Z","receivedAt":"2019-08-08T21:20:37Z","isPatch":false,"sender":{"key":"bturner@atlassian.com","avatar":"https://gravatar.com/avatar/16bcf3167981c1ef7c804e502642366d888a35b0d0b0a4ca01fdc442aa1acb1e?d=mp&s=160"},"body":"On Thu, Aug 8, 2019 at 2:08 PM <jim.cromie@gmail.com> wrote:\n>\n> fwiw,\n>\n> jimc@frodo:~/prj-1/capnproto.git$ git branch -l\n> * master\n>\n> I find the splat in the response unhelpful\n> when wrapped in shell for loop, the splat expands into everything in\n> current directory\n>\n> jimc@frodo:~/prj-1/capnproto.git$ for b in `git branch -l`; do echo $b; done\n> appveyor.yml\n> c++\n> CMakeLists.txt\n> CONTRIBUTORS\n> ...\n>\n> it would be nice if some flag combo would suppress that splat.\n> save me from fugly brittle sh $IFS fiddlery and incomplete workarounds\n\nHave you tried \"git for-each-ref --format=\"%(refname:short)\"\nrefs/heads/\"? That's going to provide short names for branches without\nany indicator for the default branch, and without any special\nordering.\n"},{"id":"380175","messageId":"CAJoAoZ=K0LhCmnEUk1rsan2J5APzcye7+RryjBG+mKgjGf6qzA@mail.gmail.com","threadId":"51610","inReplyTo":"CAGyf7-FUsfKpr+HzOpS9TqE+x7GTnsVKki94gXzMVRwnnweC9g@mail.gmail.com","subject":"Re: $> git branch splat response considered harmful","fromName":"Emily Shaffer","fromEmail":"emilyshaffer@google.com","sentAt":"2019-08-08T21:28:05Z","receivedAt":"2019-08-08T21:28:19Z","isPatch":false,"sender":{"key":"nasamuffin@google.com","avatar":"https://avatars.githubusercontent.com/u/1606826?v=4"},"body":"On Thu, Aug 8, 2019 at 2:20 PM Bryan Turner <bturner@atlassian.com> wrote:\n>\n> On Thu, Aug 8, 2019 at 2:08 PM <jim.cromie@gmail.com> wrote:\n> >\n> > fwiw,\n> >\n> > jimc@frodo:~/prj-1/capnproto.git$ git branch -l\n> > * master\n> >\n> > I find the splat in the response unhelpful\n> > when wrapped in shell for loop, the splat expands into everything in\n> > current directory\n> >\n> > jimc@frodo:~/prj-1/capnproto.git$ for b in `git branch -l`; do echo $b; done\n> > appveyor.yml\n> > c++\n> > CMakeLists.txt\n> > CONTRIBUTORS\n> > ...\n> >\n> > it would be nice if some flag combo would suppress that splat.\n> > save me from fugly brittle sh $IFS fiddlery and incomplete workarounds\n>\n> Have you tried \"git for-each-ref --format=\"%(refname:short)\"\n> refs/heads/\"? That's going to provide short names for branches without\n> any indicator for the default branch, and without any special\n> ordering.\n\nMore generally, I think you should take a look at `git help git` and\ncheck out the difference between \"porcelain\" and \"plumbing\" commands.\nThe former, of which `git branch` is one, are intended for interactive\nuse and not really meant for scripting or piping. You can usually come\nup with an equivalent from the plumbing commands, which Bryan has\nsuggested for you with `git for-each-ref`.  Git project tries very\nhard to maintain output format of the plumbing commands so as to not\nbreak folks' scripts, but such promises aren't usually made for\nporcelain commands.\n\n-- \nEmily Shaffer\n"},{"id":"380176","messageId":"20190808213002.GI20404@szeder.dev","threadId":"51610","inReplyTo":"CAJfuBxx5R28cjUj1v+mB4J+uUpbTMWnYowrCc=iOAbOcqWX-_w@mail.gmail.com","subject":"Re: $> git branch splat response considered harmful","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-08-08T21:30:02Z","receivedAt":"2019-08-08T21:30:10Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, Aug 08, 2019 at 03:08:06PM -0600, jim.cromie@gmail.com wrote:\n> fwiw,\n> \n> jimc@frodo:~/prj-1/capnproto.git$ git branch -l\n> * master\n> \n> I find the splat in the response unhelpful\n> when wrapped in shell for loop, the splat expands into everything in\n> current directory\n> \n> jimc@frodo:~/prj-1/capnproto.git$ for b in `git branch -l`; do echo $b; done\n> appveyor.yml\n> c++\n> CMakeLists.txt\n> CONTRIBUTORS\n> ...\n> \n> it would be nice if some flag combo would suppress that splat.\n> save me from fugly brittle sh $IFS fiddlery and incomplete workarounds\n\n'git branch' is not intended for scripting, try 'git for-each-ref'\ninstead.  The equivalent command should be:\n\n  git for-each-ref --format='%(refname:strip=2)' refs/heads/\n\n> also, I found no mention of the splat in the man page.\n\nIt's in the first sentence of the description :)\n\n  If --list is given, or if there are no non-option arguments, existing\n  branches are listed; the current branch will be highlighted in green\n  and marked with an asterisk.\n\n"},{"id":"380177","messageId":"xmqqo90ze3eq.fsf@gitster-ct.c.googlers.com","threadId":"51610","inReplyTo":"CAJoAoZ=K0LhCmnEUk1rsan2J5APzcye7+RryjBG+mKgjGf6qzA@mail.gmail.com","subject":"Re: $> git branch splat response considered harmful","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-08-08T21:46:37Z","receivedAt":"2019-08-08T21:46:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Emily Shaffer <emilyshaffer@google.com> writes:\n\n> More generally, I think you should take a look at `git help git` and\n> check out the difference between \"porcelain\" and \"plumbing\" commands.\n> The former, of which `git branch` is one, are intended for interactive\n> use and not really meant for scripting or piping. You can usually come\n> up with an equivalent from the plumbing commands, which Bryan has\n> suggested for you with `git for-each-ref`.  Git project tries very\n> hard to maintain output format of the plumbing commands so as to not\n> break folks' scripts, but such promises aren't usually made for\n> porcelain commands.\n\nThanks for a detailed response.\n\nGit project promises that output format of the Porcelain commands is\nsubject to change, in order to support human eyeballs better.\n\nUnless documented otherwise (e.g. \"git status --porcelain\"), it is\nunwise to try parsing porcelain output---your script may break any\ntime and you get to keep both halves.\n\nThat is not the same as saying \"do not script using Porcelain\".\nSending the output directly to the end user (e.g. compute the\nrevision range in your script that finally calls \"git log\" using\nthat computed revision range) is perfectly fine.\n\nThanks.\n"},{"id":"380236","messageId":"5f533351-3d77-3859-fe27-b3d96b0b8b30@iee.email","threadId":"51610","inReplyTo":"CAJoAoZ=K0LhCmnEUk1rsan2J5APzcye7+RryjBG+mKgjGf6qzA@mail.gmail.com","subject":"Re: $> git branch splat response considered harmful","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2019-08-09T18:01:13Z","receivedAt":"2019-08-09T18:59:02Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"On 08/08/2019 22:28, Emily Shaffer wrote:\n> On Thu, Aug 8, 2019 at 2:20 PM Bryan Turner <bturner@atlassian.com> wrote:\n>> On Thu, Aug 8, 2019 at 2:08 PM <jim.cromie@gmail.com> wrote:\n>>> fwiw,\n>>>\n>>> jimc@frodo:~/prj-1/capnproto.git$ git branch -l\n>>> * master\n>>>\n>>> I find the splat in the response unhelpful\n>>> when wrapped in shell for loop, the splat expands into everything in\n>>> current directory\n>>>\n>>> jimc@frodo:~/prj-1/capnproto.git$ for b in `git branch -l`; do echo $b; done\n>>> appveyor.yml\n>>> c++\n>>> CMakeLists.txt\n>>> CONTRIBUTORS\n>>> ...\n>>>\n>>> it would be nice if some flag combo would suppress that splat.\n>>> save me from fugly brittle sh $IFS fiddlery and incomplete workarounds\n>> Have you tried \"git for-each-ref --format=\"%(refname:short)\"\n>> refs/heads/\"? That's going to provide short names for branches without\n>> any indicator for the default branch, and without any special\n>> ordering.\n> More generally, I think you should take a look at `git help git` and\n> check out the difference between \"porcelain\" and \"plumbing\" commands.\n> The former, of which `git branch` is one, are intended for interactive\n> use and not really meant for scripting or piping. You can usually come\n> up with an equivalent from the plumbing commands, which Bryan has\n> suggested for you with `git for-each-ref`.  Git project tries very\n> hard to maintain output format of the plumbing commands so as to not\n> break folks' scripts, but such promises aren't usually made for\n> porcelain commands.\n>\nI think this (the broad Q&A) also suggests that the porcelain command \ndocumentation could be more helpful for pointing to the appropriate \nplumbing commands for these scripting issues (and it could reduce list \nnoise..).\n--\nPhilip\n"}]}