-
-
Save ColinRyan/0bc69d579f0fc35b123a46ce06617b67 to your computer and use it in GitHub Desktop.
automation of a common scenario that occurs when dealing with pull request reviews
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
# 1) Pick a branch ($1) | |
# 2) stash | |
# 3) checkout | |
# 4) updated files from last commit | |
# 5) commit and push if new edits made | |
# 6) back to previous branch | |
# 7) pop stash | |
g () { | |
cd $(git rev-parse --show-toplevel) | |
echo "" > ~/.g3old | |
echo "" > ~/.g3new | |
oldStashCount=$(git stash list | wc -l) | |
if [ ! -z "$1" ]; then | |
git stash | |
git checkout $1 | |
fi | |
oldIFS="$IFS" | |
IFS=' | |
' | |
IFS=${IFS:0:1} | |
options=('done') | |
options+=($(git diff --name-only HEAD~1 HEAD)) | |
IFS="$oldIFS" | |
echo "" | |
PS3='Select a file to edit:' | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
'done') break;; | |
*) md5sum $opt >>~/.g3old;vim $opt;md5sum $opt >> ~/.g3new; | |
esac | |
done | |
echo "" | |
old=$(md5sum ~/.g3old | cut -d" " -f1) | |
new=$(md5sum ~/.g3new | cut -d" " -f1) | |
if [ "$old" != "$new" ] ; then | |
git add -u | |
options=("*BUG-FIX*" "*REFACTORING*" "*CONFIG*" "*FEATURE*") | |
PS3='Select a commit tag:' | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
*) tag=$opt; break;; | |
esac | |
done | |
read -p 'Create a commit message:' msg | |
git commit -m "$tag:$msg" | |
git push origin HEAD | |
fi | |
if [ ! -z "$1" ]; then | |
git checkout - | |
newStashCount=$(git stash list | wc -l) | |
if [ $newStashCount -gt $oldStashCount ]; then | |
git stash pop | |
fi | |
fi | |
cd - | |
} | |
__git_complete g _git_checkout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment