-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-review
More file actions
executable file
·102 lines (85 loc) · 1.87 KB
/
git-review
File metadata and controls
executable file
·102 lines (85 loc) · 1.87 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
set -o errexit
git_log_format="%C(green)%h %C(red)%<(25,trunc)%ad %C(blue)%<(20,trunc)%aN%C(auto)%d %C(reset)%s"
function main() {
local interactive=""
local upstream=""
local head=""
while [ $# -gt 0 ]; do
case "$1" in
--help|-h)
echo "Just read the source code: $0"
shift
return 0
;;
--interactive|--review-individual-commits|-i)
interactive=1
shift
break
;;
--)
shift
break
;;
--*|-*)
echo "Invalid option $1";
shift
return 1
;;
*)
break
esac
shift
done
echo "$@"
if [ $# -gt 2 ]; then
echo "Usage: git review [options] [[upstream] branch_or_commit]"
exit 1
elif [[ $# -eq 2 ]]; then
upstream="$1"
head=${2:-$(git symbolic-ref --short HEAD)}
else
head=${1:-$(git symbolic-ref --short HEAD)}
upstream=$(git rev-parse --short --symbolic-full-name "${head}@{upstream}")
upstream=${upstream#refs/remotes/}
fi
declare -a revisions
rev_range="${upstream}..${head}"
echo "Reviewing: $rev_range"
revisions=( $(git rev-list --topo-order --reverse "$rev_range") )
if [ ${#revisions[@]} -eq 0 ]; then
echo "Nothing to review"
return 0
fi
echo
git_log --graph --boundary --format="${git_log_format}%n" "$rev_range" --
if [ "$interactive" ]; then
echo
echo "Showing diffs for each of the above commits one-by-one."
echo
for rev in ${revisions[@]}; do
echo
git_log --format="${git_log_format}" --stat "${rev}^!"
echo
confirm_run git difftool --dir-diff --no-prompt "$rev"~ "$rev"
done
else
merge_base=$(git merge-base "$upstream" "$head")
confirm_run git difftool --dir-diff --no-prompt "$merge_base" "$head"
fi
}
function git_log() {
git --no-pager log --date=iso8601 "$@"
}
function confirm_run() {
printf "$ "; printf "%q " "$@"; echo
read -p "Run command [Y]? " response
case "$response" in
y|Y|yes|Yes|YES|"")
"$@"
;;
*)
;;
esac
}
main "$@"