Skip to content

Instantly share code, notes, and snippets.

@tomykaira
Created July 10, 2015 06:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomykaira/40abc2ba411be28bee67 to your computer and use it in GitHub Desktop.
Save tomykaira/40abc2ba411be28bee67 to your computer and use it in GitHub Desktop.
save and apply patches for git submodules
#!/bin/sh -e
separator="----8<----8<----8<----8<----"
function make_chunk {
cd $1
if ! git diff --exit-code --ignore-submodules --quiet; then
echo "${PWD#$root}/"
git --no-pager diff --no-color --ignore-submodules
echo "$separator"
fi
}
case "$1" in
"make" )
root=$PWD
make_chunk $PWD
for module in $(git submodule foreach --recursive 'echo $toplevel/$path' | grep -v Entering); do
make_chunk $module
done
;;
"apply")
root=$PWD
while read pwd; do
patch=""
while read line; do
if [ "$line" = "$separator" ]; then
break
fi
patch="$patch"$'\n'"$line"
done
echo Patching $root$pwd
cd $root$pwd
echo "$patch" | patch -p1 --forward --force || true
done
;;
*)
echo "Unknown command"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment