OSX: find,xargs guru?

hello,

bash 4.2+
osx 10.11.6

i looking for a nice compact one-liner and need a little help using find and xargs

i'm writing a script to recursively search through directories looking for git and hg repos and update them.

this bit of code searches and finds them git repos.

find `pwd` -depth -name .git -type d |  xargs -P 8 -I {} dirname {} 

i want to operate several git commands once in the directory.

for example,

git stash; git pull; git submodule update; git gc

how to

pushd

a directory? run the commands? and then

 popd

the directories?

continue to next? how to handle any if any errors if git chokes? if error go to next directory?

thanks

find `pwd` is a bit redundant, find . would do

How about:

find . -depth -name .git -type d | while read DIR
do
        (
                cd "$DIR" && git stash && git pull && git submodule update && git gc
        )
done
1 Like

Thanks, that worked.

1 Like