2013-11-01 4 views
24

के बाद "गिट सबमिशन फ़ोरैच" कमांड के साथ सबोडोड्यूल पर लूपिंग जारी रखें मेरे पास एक प्रोजेक्ट है जिसमें कई सबोड्यूल हैं। मैं निम्न आदेश के साथ प्रत्येक submodule से अधिक लूप करना चाहते हैं:गैर-शून्य निकास

git submodule foreach npm install

और मैं स्क्रिप्ट प्रत्येक submodule भले ही एक submodule एक (गैर शून्य रिटर्न कोड) त्रुटि देता है अधिक पाशन जारी रखना चाहते हैं। वर्तमान में, किसी भी सबमिशन में इस कमांड को चलाने से एक गैर-शून्य रिटर्न कोड गिट को शेष सबोड्यूल पर लूपिंग रोक देगा।

इसे पूरा करने के तरीके पर कोई सिफारिशें?

+0

Git submodule foreach 'सूत' – danday74

उत्तर

60

बस अपने आदेश हमेशा एक 0 कोड इसलिए की तरह वापसी कर

:: : 
    Null command. 

    No effect; the command does nothing. 

    Exit Status: 
    Always succeeds. 

हमेशा सफल होता है:)

+6

'Git submodule foreach 'NPM स्थापित || सच 'वही करेगा। –

+0

यह विंडोज पर काम नहीं करता है। माना गया था? यहां तक ​​कि बैश का उपयोग करके \ ' \' केवल पहले को निष्पादित करने का प्रयास करें और वैसे भी तोड़ें। –

+0

@ मार्सेलोफिल्लो: गिट बैश का उपयोग करने का प्रयास करें। – MaBe

2

आप यह topic देख सकते हैं।

मैं GIT का उपयोग नहीं करते, लेकिन अगर आप .gitmodules फ़ाइलों का पता कर सकते हैं, यह प्रत्येक submodules के लिए पाश करने के लिए आसान हो सकता है:

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

या:

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

इस reminder on how to read a command output with a loop in Bash देखें । bash में help : से

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. 

आदेश ::

git submodule foreach 'npm install || :' 

यह मैनुअल से लिया जाता है: git help submodule

संबंधित मुद्दे