Skip to content

Instantly share code, notes, and snippets.

@simonwhitaker
Created February 16, 2011 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonwhitaker/829481 to your computer and use it in GitHub Desktop.
Save simonwhitaker/829481 to your computer and use it in GitHub Desktop.
#!/bin/bash
# A simple shell script for helping you do code reviews on patch files. Feed
# in the SHA1 for the commit the patch builds on and the path to the patch
# file and it'll spin up a new branch for you, check it out and apply the
# patch. You can now use your favourite diff tool to review the patch.
usage() {
printf "usage: %s <sha> <patchfile>\n" $(basename $0)
echo
echo "Creates a new branch based at <sha>, checks "
echo "it out and applies <patchfile>"
}
main() {
if [ $# -lt 2 ]; then
usage
exit 1
fi
SHA="$1"
PATCHFILE="$2"
PF_NAME=$(basename $PATCHFILE)
BRANCH="cr/${PF_NAME}"
echo "Creating branch ${BRANCH} at ${SHA}"
git branch $BRANCH $SHA || exit 1
git checkout $BRANCH || exit 1
git apply --whitespace=nowarn $PATCHFILE || exit 1
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment