-
Notifications
You must be signed in to change notification settings - Fork 6
/
git-graph
executable file
·79 lines (71 loc) · 1.7 KB
/
git-graph
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
# Show a pretty `git log` with a graph.
#
# Usage:
#
# $ git graph [-a|-ac] [-d] [-l] ...
#
# -a: print "author" datetimes (default: "committer")
# -ac: print "author" and "committer" datetimes
# -A: order commits by author date (default: committer date)
# -C: show committer name and email (default: author)
# -d: render ISO datetimes (default: "relative")
# -e: show author/committer email (default: name)
# -l: render "local" datetimes (default: "relative")
# -u: include upstream ("tracked") branch
#
# Other args are passed through to `git log`
set -e
args=()
author_fmt="%an"
date_order=--date-order
show_committer=
show_email=
email_color=cyan
date_fmt='%cd'
date_style="relative"
include_upstream=
while [ $# -gt 0 ]; do
arg="$1"; shift
case "$arg" in
-a) date_fmt="%ad" ;;
-ac) date_fmt="%ad %C(green)%cd" ;;
-A) date_order=--author-date-order ;;
-C) show_committer=1 ;;
-d) date_style="iso" ;;
-e) show_email=1 ;;
-l) date_style="local" ;;
-u) include_upstream=1 ;;
*) args+=("$arg") ;;
esac
done
if [ -n "$show_committer" ]; then
if [ -n "$show_email" ]; then
author_fmt="%cn %C($email_color)<%ce>"
else
author_fmt="%cn"
fi
else
if [ -n "$show_email" ]; then
author_fmt="%an %C($email_color)<%ae>"
else
author_fmt="%an"
fi
fi
if [ -n "$include_upstream" ]; then
args+=("$(git tracked-branch)")
fi
set -- "${args[@]}"
style=--graph
for arg in "$@"; do
if [ "$arg" = "--no-walk" ]; then
style=--no-walk
break
fi
done
git log \
"$style" \
"--format=%C(auto)%h %C(blue)${date_fmt} %C(red)${author_fmt}%C(reset)%C(auto)%d %s" \
"--date=$date_style" \
"$date_order" \
"$@"