Last active
January 2, 2018 06:26
-
-
Save Pr0methean/cd892f342cf755f8efbdde18e75cafbf to your computer and use it in GitHub Desktop.
Shell script for splitting a pull request
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/bash | |
new_branch() { | |
ID=$(cat /proc/sys/kernel/random/uuid) | |
git checkout dev | |
git branch ${ID} | |
git checkout ${ID} | |
} | |
try_build() { | |
mvn -q -DskipTests clean test-compile | |
if [ $? -eq 0 ]; then | |
git add . | |
git commit -m "$1" | |
git push | |
hub pull-request -b dev -m "$1" | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
checkout_or_remove() { | |
(git checkout stylesquashed $1 && git add $1) ||\ | |
git rm $1 | |
} | |
export MAVEN_OPTS="-Xmx384m" | |
for FILE in ~/stylefixes/*; do | |
new_branch | |
for CHECKOUT_FILE in $(cat ${FILE}); do | |
checkout_or_remove ${CHECKOUT_FILE} | |
done | |
# First try entire package | |
try_build "Fix CheckStyle issues in ${FILE}" || ( | |
# Failed: try one file at a time | |
git commit -m "Commit failed build so it doesn't dangle" | |
for CHECKOUT_FILE in $(cat ${FILE}); do | |
new_branch | |
checkout_or_remove ${CHECKOUT_FILE} | |
try_build "Fix CheckStyle issues in ${CHECKOUT_FILE:28}" || ( | |
git commit -m "Commit failed build so it doesn't dangle" | |
# That also failed, so put it in the leftovers branch | |
git checkout style_leftovers | |
git pull --commit origin style_leftovers | |
checkout_or_remove ${CHECKOUT_FILE} | |
git commit -m "Add leftover file ${CHECKOUT_FILE}" | |
git push | |
while [ ! $? ]; do | |
git pull --commit origin style_leftovers | |
git push | |
done | |
) | |
done | |
) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment