Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 86 lines (71 sloc) 1.815 kB
617fe96 @mjdominus initial commit
authored
1 #!/bin/sh
377402d @mjdominus comments and usage notes
authored
2 #
3 # This prepares a brief summary of how your current branch has diverged
4 # from a corresponding remote branch. A typical use is:
5 # git vee origin
6 #
7 # if the currently-checked-out branch is master, this will compare
8 # master and origin/master.
9 #
367cea2 correct comment
Mark Dominus authored
10 # It uses git log --cherry-mark, so you need at least git 1.7.4.1.
377402d @mjdominus comments and usage notes
authored
11 # If --cherry-mark doesn't work, delete that option from this script.
12 #
13 # Usage:
442f23f @mjdominus default to using current HEAD and its remote tracking branch, if any
authored
14 # git vee # compare current head branch and its remote tracking branch
377402d @mjdominus comments and usage notes
authored
15 # git vee remote # compare current head branch and its analog on the remote
16 # git vee remote branch # compare branch and remote/branch
17 # git vee branch # compare HEAD and branch
18 # git vee branch1 branch2 # compare branch1 and branch2
19 #
617fe96 @mjdominus initial commit
authored
20
21 DIE=false;
22
23 equal_commits () {
24 [ $(git rev-parse $A) = $(git rev-parse $B) ]
25 }
26
27 valid_ref () {
28 git rev-parse -q --verify $1 >/dev/null
29 }
30
31 is_remote () {
32 git remote | grep -q "^$1"'$'
33 }
34
35 die_later () {
36 echo $* 1>&2;
37 DIE=true
38 }
39
40 die_now () {
41 $DIE && exit 1
42 }
43
865cab5 @mjdominus more error checking in git-vee
authored
44 die () {
45 echo 1>&2 "$@"
46 exit 1
47 }
48
617fe96 @mjdominus initial commit
authored
49 usage () {
442f23f @mjdominus default to using current HEAD and its remote tracking branch, if any
authored
50 echo "Usage: $0 [remote] [branch]" 1>&2
617fe96 @mjdominus initial commit
authored
51 echo " $0 branch-a [branch-b]" 1>&2
52 exit 2
53 }
54
55 case $# in
442f23f @mjdominus default to using current HEAD and its remote tracking branch, if any
authored
56 0) Y=$(git get current-branch-name);
865cab5 @mjdominus more error checking in git-vee
authored
57 [ -z "$Y" ] && die "Couldn't get current branch name"
442f23f @mjdominus default to using current HEAD and its remote tracking branch, if any
authored
58 X=$(git get branch-remote $Y);
865cab5 @mjdominus more error checking in git-vee
authored
59 [ -z "$X" ] && die "Couldn't find remote tracking branch for '$Y'"
442f23f @mjdominus default to using current HEAD and its remote tracking branch, if any
authored
60 ;;
617fe96 @mjdominus initial commit
authored
61 1) X=$1 Y=HEAD;;
62 2) X=$1 Y=$2;;
63 *) usage ;;
64 esac
65
66 if is_remote $X; then
67 if [ $Y = HEAD ]; then
cede063 @mjdominus bug fix: git-vee didn't always identify HEAD correctly
authored
68 Y=$(git get current-branch-name)
617fe96 @mjdominus initial commit
authored
69 fi
70 A=$Y B="$X/$Y"
71 else
72 A=$X; B=$Y;
73 fi
74
75 valid_ref $A || die_later "$A: unknown commit"
76 valid_ref $B || die_later "$B: unknown commit"
77 die_now
78
79 if equal_commits $A $B ; then
80 echo "$A and $B are identical"
81 exit 0;
82 fi
83
84 git log --decorate --cherry-mark --oneline --graph --boundary $A"..."$B
85
Something went wrong with that request. Please try again.