git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git branch in Bash subshell "$(git branch -a)" including ls output as part of return?

From
AJAlex Jones <ajones@netsertive.com>
Date
Dec 7, 2015, 16:52 UTC
Message-ID
<CAJGk2Wx4B=AHFxkJep=yYVKU9UyJieazoNaC44W5yBXoMi+gdg@mail.gmail.com>
Hello Folks,

I am Running OSX 10.10.5 Yosemite along with git 2.6.3 installed via homebrew package manager.

I recently stumbled across the following bug in some scripting I was doing. "git branch -a --list" and "git branch -a" seem to include the output of an "ls" command if executed as part of a subshell in a bash script. I can't speculate to the reason.

Script goal: Delete all branches aside from master in the repository Example outputs from several commands repo:

ls output:

ajonespro:Deploy_Script ajones$ ls -l total 0 drwxr-xr-x 11 ajones wheel 374 Dec 7 10:50 AppDeploy drwxr-xr-x 11 ajones wheel 374 Dec 7 11:15 WebDeploy

git branch -a output:
ajonespro:Deploy_Script ajones$ git branch -a
* DWH_concurrent_api
  Email_No_Error_If_No_Old_Version
  IT/configs_in_app_support
  PHP_Build_Repo
  master
  remotes/origin/DWH_concurrent_api
  remotes/origin/Email_No_Error_If_No_Old_Version
  remotes/origin/IT/configs_in_app_support
  remotes/origin/PHP_Build_Repo
  remotes/origin/master
echo $(git branch -a) output:

ajonespro:Deploy_Script ajones$ echo $(git branch -a) AppDeploy WebDeploy DWH_concurrent_api Email_No_Error_If_No_Old_Version IT/configs_in_app_support PHP_Build_Repo master remotes/origin/DWH_concurrent_api remotes/origin/Email_No_Error_If_No_Old_Version remotes/origin/IT/configs_in_app_support remotes/origin/PHP_Build_Repo remotes/origin/master

While it might be hard to see from that output, The first two "branches" in the subshell's output are actually the directories contained within the repo. If I place a file at the root it includes that in the branch list as well. Since my test file "test.txt" (not shown in example) and "WebDeploy" are sorted before all the branches, I suspect some output buffer is being accidentally being written to.

Has any experienced this before, and can anyone reproduce it on a different configuration? I wouldn't be surprised if it was some weird bug with Apple's included terminal, but since I've only observed it with git branch, I thought I'd try contact git maintainers first.

Next: Charles Bailey
Message 1 of 4 in “git branch in Bash subshell "$(git branch -a)" including ls output as part of return?”
  1. Alex JonesDec 7, 2015
  2. Charles BaileyDec 7, 2015
  3. Charles BaileyDec 7, 2015
  4. Alex JonesDec 7, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.