]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/git-rel
bin/git-branch-dates: Smarter automatic line truncation
[dotfiles.git] / bin / git-rel
1 #!/bin/sh
2 # Usage: git-rel [<ref>]
3 # Shows the relationship between the current branch and <ref>. With no <ref>,
4 # the current branch's remote tracking branch is used.
5 #
6 # Examples:
7 #
8 # $ git-rel
9 # 15 ahead
10 # 11 behind
11 #
12 # $ git-rel v1.1
13 # 230 ahead
14
15 strip_prefix () {
16 echo "$@" |
17 sed 's@refs/heads/@@'
18 }
19
20 current_branch () {
21 git symbolic-ref -q HEAD |
22 sed 's@refs/heads/@@'
23 }
24
25 tracking_branch () {
26 remote=$(git config --get branch.$(current_branch).remote)
27 merge=$(git config --get branch.$(current_branch).merge)
28 echo "$remote/$(strip_prefix $merge)"
29 }
30
31 ref="${1:-$(tracking_branch)}"
32
33 git rev-list --left-right --abbrev-commit --abbrev $ref...HEAD |
34 cut -c1 |
35 sort |
36 uniq -c |
37 tr '\n' ',' |
38 sed "
39 s/>/ahead/
40 s/</behind/
41 s/,$//g
42 s/,/, /g
43 "