zhekaus
zhekaus

Reputation: 3194

commit changes in the submodules with the only command

I am trying to commit changes made in a few submodules:

$ git submodule foreach git commit -m 'fixed header guards'
Entering 'libs/BaseDisplay'
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
fatal: run_command returned non-zero status for libs/BaseDisplay
.

I see process stops on the first submodule which is up to date... However, there are many other submodules which have staged files. How to commit changes made in such submodule with the only command?

Upvotes: 4

Views: 722

Answers (1)

Ondrej K.
Ondrej K.

Reputation: 9664

Short version, change your command to:

git submodule foreach "git commit -m 'fixed header guards' || :"

Longer version: As man page states:

A non-zero return from the command in any submodule causes the processing to terminate.

And recommends:

This can be overridden by adding || : to the end of the command.

What this does is:

An OR list has the form

command1 || command2

command2 is executed if, and only if, command1 returns a non-zero exit status. The return status of AND and OR lists is the exit status of the last command executed in the list.

And : is bash's nop: do nothing, (and always) return success.

Double quotes around the command part of submodule foreach ensure it all gets passed to git as a single argument and the shell you're calling it from does not parse the || : bit itself.

Upvotes: 7

Related Questions