1

I used to use commands like

git submodule foreach git status

or for commands that may fail

git submodule foreach "git checkout develop || true"

So now I created a alias for the first form and it works OK

git config --global alias.all '!f(){ git submodule foreach "git $@"; }; f'

I then try to do it also for the second form and it doesn't work at all

git config --global alias.all '!f(){ git submodule foreach "git $@ || true"; }; f'

Note that I can still use it the first one like

git all "checkout develop || true"

but that looks like unnecessary typing when using an alias.

The error it gives in the example above using 'git all' is error: pathspec 'develop || true' did not match any file(s) known to git

while in the 'submodules' it outputs an error but it continues to the next submodule.

Any pointer on how to fix that second version?

Cheers.

amsmota
  • 171
  • 2
  • 11

1 Answers1

1

Works for me (almost):

$ git config alias.all

$ git config alias.all '!f(){ git submodule foreach "git $@ || true"; }; f'

$ git config alias.all
!f(){ git submodule foreach "git $@ || true"; }; f

$ git all checkout master
Entering 'genxml'
/usr/lib/git-core/git-submodule: 342: /usr/lib/git-core/git-submodule: git checkout: not found
Stopping at 'genxml'; script returned non-zero status.

Hmm, that strange, I expected it to work the same way as the following:

$ git all "checkout master"
Entering 'genxml'
error: pathspec 'master' did not match any file(s) known to git.
Entering 'third-party/c14n2'
Already on 'master'
Your branch is up-to-date with 'origin/master'.
Entering 'third-party/cmclib'
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
Entering 'third-party/eplant'
Already on 'master'
Your branch is up-to-date with 'origin/master'.
Entering 'third-party/pycryptoserver'
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
Entering 'third-party/ufod'
warning: unable to rmdir ufod/xsd: Directory not empty
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

At least that works as expected.

phd
  • 82,685
  • 13
  • 120
  • 165
  • Hi, thanks for that, it's not exactly what i wanted to achieve, and what bugs me more is that I don't understand why if it works on the CLI doesn't work on the alias. Anyway, your answer is closer than mine so I'll accept it. Cheers. – amsmota Oct 25 '19 at 13:06