Last active
August 29, 2015 14:28
-
-
Save kevsmith/93030c3c24b439ba69f1 to your computer and use it in GitHub Desktop.
git commands for quickly iterating on code locally
This file contains hidden or 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 | |
# Put this script in your path and execute it like so: | |
# `git checkpoint` | |
# or | |
# `git checkpoint lib/foo/foo_thing.ex` | |
# Bail as soon as an error happens | |
set -e | |
function exit_cleanup { | |
popd >& /dev/null | |
} | |
function add_files { | |
while [ "$#" != "0" ]; | |
do | |
git add $1 | |
echo "Added $1 to checkpoint" | |
shift | |
done | |
} | |
# Push working dir so we don't confuse the user later | |
pushd . >& /dev/null | |
# Pop previously pushed working dir when we're done | |
trap "exit_cleanup" SIGHUP | |
trap "exit_cleanup" SIGINT | |
trap "exit_cleanup" SIGTERM | |
# Get last commit | |
last_commit=`git reflog -n 1` | |
# Is checkpoint commit? | |
# A checkpoint commit is a commit when the word | |
# "CHECKPOINT" appears verbatim in the comments. | |
is_ckpt=`echo ${last_commit} | grep CHECKPOINT | wc -l | sed -e 's/^[ \t]*//'` | |
# Get root of git repo | |
git_root=`git rev-parse --show-toplevel` | |
# args to use when commit | |
commit_args="-m \"CHECKPOINT\"" | |
# If comment for last commit is "WIP" or "CHECKPOINT" | |
# then amend previous commit since it's local only. | |
if [ "${is_ckpt}" == "1" ]; then | |
commit_args="${commit_args} --amend" | |
fi | |
# Explicitly add any files mentioned by the user | |
add_files $@ | |
# Run the git commit | |
cd ${git_root} && git commit ${commit_args} |
This file contains hidden or 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 | |
# Put this script in your path and call it like so: | |
# `git is-checkpoint` | |
# Get last commit | |
last_commit=`git reflog -n 1` | |
# Was last commit a checkpoint commit? | |
is_ckpt=`echo ${last_commit} | grep CHECKPOINT | wc -l | sed -e 's/^[ \t]*//'` | |
# Get root of git repo | |
git_root=`git rev-parse --show-toplevel` | |
# args to use when commit | |
commit_args="-m \"CHECKPOINT\"" | |
if [ "${is_ckpt}" == "1" ]; then | |
# if last commit was a checkpoint commit then | |
# print "yes" on stdout and exit w/status 0. | |
echo "yes" | |
exit 0 | |
else | |
# if last commit wasn't a checkpoint commit then | |
# print "no" on stdout and exit with w/status 1. | |
echo "no" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment