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