Created
July 10, 2015 06:55
-
-
Save tomykaira/40abc2ba411be28bee67 to your computer and use it in GitHub Desktop.
save and apply patches for git submodules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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