2013-11-01 9 views
24

Ich habe ein Projekt, das viele Submodule enthält. Ich möchte über jedes Modul in einer Schleife mit dem folgenden Befehl:Schleife weiter über Submodule mit dem Befehl "git submodule foreach" nach einem Nicht-Null-Exit

git submodule foreach npm install

Und ich mag das Skript über jedes Modul weiterhin Looping auch wenn ein Submodul gibt einen Fehler (nicht Null Return-Code). Gegenwärtig führt ein Rückgabecode ungleich Null, der von diesem Befehl in einem Submodul ausgeht, dazu, dass Git aufhört, die verbleibenden Submodule zu durchlaufen.

Irgendwelche Empfehlungen, wie dies zu erreichen ist?

+0

git Submodul foreach 'Garn' – danday74

Antwort

60

So stellen Sie Ihren Befehl immer wieder zurückkehren ein 0 Code wie folgt:

git submodule foreach 'npm install || :' 

Dieses aus dem Handbuch entnommen wird: git help submodule:

foreach 
     Evaluates an arbitrary shell command in each checked out submodule. 
     The command has access to the variables $name, $path, $sha1 and 
     $toplevel: $name is the name of the relevant submodule section in 
     .gitmodules, $path is the name of the submodule directory relative 
     to the superproject, $sha1 is the commit as recorded in the 
     superproject, and $toplevel is the absolute path to the top-level 
     of the superproject. Any submodules defined in the superproject but 
     not checked out are ignored by this command. Unless given --quiet, 
     foreach prints the name of each submodule before evaluating the 
     command. If --recursive is given, submodules are traversed 
     recursively (i.e. the given shell command is evaluated in nested 
     submodules as well). A non-zero return from the command in any 
     submodule causes the processing to terminate. This can be 
     overridden by adding || : to the end of the command. 

     As an example, git submodule foreach 'echo $path `git rev-parse 
     HEAD`' will show the path and currently checked out commit for each 
     submodule. 

Der Befehl : von help : in bash:

:: : 
    Null command. 

    No effect; the command does nothing. 

    Exit Status: 
    Always succeeds. 

gelingt es immer:)

+6

'git Submodul foreach‚npm installieren || Wahr 'würde das Gleiche tun. –

+0

Es funktioniert nicht unter Windows. Soll das? Selbst mit Bash versuchen die \ ' \ 'nur die erste auszuführen und bricht trotzdem. –

+0

@MarceloFilho: Versuchen Sie es mit der Git-Bash. – MaBe

2

Sie konnten dieses topic sehen.

Ich benutze GIT nicht, aber wenn man die .gitmodules Dateien finden können, kann es für jede Submodule Schleife einfach sein:

<command to find all of your submodules>|while read; do 
    # ... (default use $REPLY as an item) 
done 

Oder:

while read; do 
    # ... 
done <<< "$(command to find all of your submodules)" 

Sehen Sie diese reminder on how to read a command output with a loop in Bash .