]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/git-outgoing
.bashrc: alias 'rehash'
[dotfiles.git] / bin / git-outgoing
1 #!/bin/sh
2 # Usage: git-outgoing [<upstream>] [<head> [<limit>]]
3 # Show commits on current branch that do not exist on branch <upstream>.
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 # get the current branch in refs/heads/<branch> form
18 ref=$(git symbolic-ref -q HEAD)
19 test -n "$ref" ||
20 die "you're not on a branch"
21
22 # just the branch name please
23 branch=$(echo "$ref" | sed 's@^refs/heads/@@')
24 test -n "$branch" ||
25 die "you're in a weird place; get on a local branch"
26
27 # use tracking branch if no upstream given
28 if [ $# -eq 0 ]
29 then
30 remote=$(git config --get "branch.$branch.remote" || true)
31
32 merge=$(git config branch.$branch.merge) ||
33 die "branch $branch isn't tracking a remote branch and no <upstream> given"
34
35 set -- "$remote/$(echo "$merge" |sed 's@^refs/heads/@@')"
36 fi
37
38 git cherry -v "$@" |
39 cut -c1-9 -c43- |
40 sed -e "s/^\(.\) \(.......\)/\1 $SHA\2$RESET/" |
41 sed -e "s/^-/$REM-$RESET/" -e "s/^+/$ADD+$RESET/"