-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-rel
executable file
·44 lines (39 loc) · 891 Bytes
/
git-rel
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
#!/usr/bin/env sh
# Taken from https://github.com/ahmedelgabri/dotfiles/blob/master/extra/bin/git-rel
# Usage: git-rel [<ref>]
# Shows the relationship between the current branch and <ref>. With no <ref>,
# the current branch's remote tracking branch is used.
#
# Examples:
#
# $ git-rel
# 15 ahead
# 11 behind
#
# $ git-rel v1.1
# 230 ahead
strip_prefix() {
echo "$@" |
sed 's@refs/heads/@@'
}
current_branch() {
git symbolic-ref -q HEAD |
sed 's@refs/heads/@@'
}
tracking_branch() {
remote=$(git config --get branch."$(current_branch)".remote)
merge=$(git config --get branch."$(current_branch)".merge)
echo "$remote/$(strip_prefix "$merge")"
}
ref="${1:-$(tracking_branch)}"
git rev-list --left-right --abbrev-commit --abbrev "$ref"...HEAD |
cut -c1 |
sort |
uniq -c |
tr '\n' ',' |
sed "
s/>/ahead/
s/</behind/
s/,$//g
s/,/, /g
"