-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-divergence
executable file
·59 lines (50 loc) · 1.18 KB
/
git-divergence
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
58
59
#!/bin/bash
set -e
(
function branch() {
git branch 2>/dev/null | grep -e '^*' | tr -d '\* '
}
function ensure_valid_ref() {
ref=$1
(
set +e
git show-ref $ref > /dev/null
if [[ $? == 1 ]]; then
echo "$0: bad ref: $ref"
exit 1
fi
)
}
function show_rev() {
rev=$1
git log -1 $rev --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
echo
git di $rev^..$rev | diffstat
echo
}
if [[ $# == 2 ]]; then
LOCAL=$1
REMOTE=$2
elif [[ $# == 1 ]]; then
LOCAL=`branch`
REMOTE=$1
else
LOCAL=`branch`
REMOTE=origin/$LOCAL
fi
ensure_valid_ref $LOCAL
ensure_valid_ref $REMOTE
echo "changes from local ${LOCAL} to remote ${REMOTE}:"
echo
echo incoming:
echo
for rev in `git rev-list $LOCAL..$REMOTE`; do
show_rev $rev
done
echo
echo outgoing:
echo
for rev in `git rev-list $REMOTE..$LOCAL`; do
show_rev $rev
done
) | less -XFr