dahlbyk / posh-git

A PowerShell environment for Git
http://dahlbyk.github.io/posh-git/
MIT License
7.62k stars 801 forks source link

Which shell is used to executed commands from 'git submodule foreach' #519

Closed Paebbels closed 6 years ago

Paebbels commented 6 years ago

System Details

Issue Description

I'm running the following script from git-bash.exe:

echo "Rename all remotes from default name 'origin' to 'gitlab'..."
echo "Main repository"
if [[ $(git remote | head -n 1) == "origin" ]]; then
  echo "  Renaming \"origin\" to \"gitlab\""
  git remote rename origin gitlab
else
  echo "  Nothing to do."
fi
echo "  git submodule foreach --recursive 'if [[ $(git remote | head -n 1) == \"origin\" ]]; then echo \"  Renaming \\\"origin\\\" to \\\"gitlab\\\"\"; git remote rename origin gitlab; else echo \"  Nothing to do.\"; fi'"
git submodule foreach --recursive 'if [[ $(git remote | head -n 1) == "origin" ]]; then echo "  Renaming \"origin\" to \"gitlab\""; git remote rename origin gitlab; else echo "  Nothing to do."; fi'

I would like to translate this script into a PowerShell script, but the last line gives me some problems. The foreach subcommand of git submodule has problems in executing the embedded Bash code.

What shell is used by the command, when invoked from PowerShell through PoSh-Git? It doesn't seam to be the bash from within Git's MSYS (MinGW) environment.

These are the reported messages:

Entering 'ipxact/axis-counter'
C:\Program Files\Git\mingw64/libexec/git-core\git-submodule: line 355: if [[ $(git remote | head -n 1) == origin ]]; then echo -e : command not found
Stopping at 'ipxact/axis-counter'; script returned non-zero status.

The git-bash reports the following default shell:

Patrick Lehmann@PLC2-Paebbels MINGW64 ~
$ /usr/bin/sh --version
GNU bash, version 4.4.12(1)-release (x86_64-pc-msys)
dahlbyk commented 6 years ago

What shell is used by the command, when invoked from PowerShell through PoSh-Git? It doesn't seam to be the bash from within Git's MSYS (MinGW) environment.

posh-git doesn't (shouldn't?) change anything about how git itseld executes. You are most likely encountering a difference in how Bash and PowerShell handle escaping characters (` vs \). Can you share your PowerShell translation?

I'm poor enough at troubleshooting those situations (usually for filter-branch) that I just use Git Bash as needed. If you really must translate to PowerShell, posting to StackOverflow might find you a better answer if we can't help here.

I am going to close for now; please reopen if this does seem to be a problem in our code.