Created
June 10, 2011 14:07
-
-
Save rob-b/1018888 to your computer and use it in GitHub Desktop.
git glp # with no args will show unpushed changs
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 | |
function git_current_tracking | |
{ | |
local BRANCH="$(git describe --contains --all HEAD)" | |
local REMOTE="$(git config branch.$BRANCH.remote)" | |
local MERGE="$(git config branch.$BRANCH.merge)" | |
if [ -n "$REMOTE" -a -n "$MERGE" ] | |
then | |
echo "$REMOTE/$(echo "$MERGE" | sed 's#^refs/heads/##')" | |
else | |
echo "\"$BRANCH\" is not a tracking branch." >&2 | |
return 1 | |
fi | |
} | |
# don't use the pager if in word-diff mode | |
pager="$(echo "$*" | grep -q -- '--word-diff' && echo --no-pager)" | |
# use reverse mode if we have a range | |
reverse="$(echo "$*" | grep -q '\.\.' && echo --reverse)" | |
# if we have no non-option args then default to listing unpushed commits in reverse moode | |
if ! (for ARG in "$@"; do echo "$ARG" | grep -v '^-'; done) | grep -q . && git_current_tracking > /dev/null 2>&1 | |
then | |
default_range="$(git_current_tracking)..HEAD" | |
reverse='--reverse' | |
else | |
default_range='' | |
fi | |
git $pager slog $reverse "$@" $default_range |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment