-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-incoming.sh
executable file
·57 lines (48 loc) · 1.64 KB
/
git-incoming.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
# Usage: git-incoming [-d] [<upstream>] [<head> [<limit>]]
# Show commits on <upstream> that do not exist on current branch.
#
# see https://github.com/rtomayko/dotfiles/blob/d60d94c8b2dada1d4d21ad8f4cd1bb3d02505968/bin/git-incoming
# bail out with message to stderr and exit status 1
die() {
echo "$(basename $0):" "$@" 1>&2
exit 1
}
# colors
SHA=$(git config --get-color 'color.branch.local')
ADD=$(git config --get-color 'color.diff.new')
REM=$(git config --get-color 'color.diff.old')
RESET=$(git config --get-color '' 'reset')
# check for -d / --diff argument
diff=false
if [ "$1" = '-d' -o "$1" = '--diff' ]
then diff=true
shift
fi
# use tracking branch if no upstream given
if [ $# -eq 0 ]
then
# get the current branch in refs/heads/<branch> form
ref=$(git symbolic-ref -q HEAD)
test -n "$ref" ||
die "you're not on a branch"
# just the branch name please
branch=$(echo "$ref" | sed 's@^refs/heads/@@')
test -n "$branch" ||
die "you're in a weird place; get on a local branch"
# grab remote name for current branch
remote=$(git config --get "branch.$branch.remote" || true)
# grab tracked branch name for current branch
merge=$(git config branch.$branch.merge) ||
die "branch $branch isn't tracking a remote branch and no <upstream> given"
# make it so
set -- "$remote/$(echo "$merge" |sed 's@^refs/heads/@@')"
fi
if $diff
then git diff HEAD..."$1"
else
git cherry -v HEAD "$@" |
cut -c1-9,43- |
sed -e "s/^\(.\) \(.......\)/\1 $SHA\2$RESET/" |
sed -e "s/^-/$REM-$RESET/" -e "s/^+/$ADD+$RESET/"
fi