-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit-blamed-diff
executable file
·47 lines (39 loc) · 942 Bytes
/
git-blamed-diff
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
#!/bin/sh -e
# SPDX-License-Identifier: WTFPL
tmpa=
tmpb=
cleanup () {
rm -f "$tmpa" "$tmpb"
}
blame () {
# sed to remove git-blame's obnoxious line numbers
git blame -s "$@" | sed 's/[[:digit:]]*)//'
}
case $# in
1)
arev=HEAD
brev=
;;
2)
arev="$2^"
brev="$2"
;;
*)
cat >&2 <<- EOF
usage: git blamed-diff FILE [REV]
Prints diff of FILE between REV and REV~, annotating lines with commit info.
If REV isn't specified, the diff between working directory and HEAD is used.
EOF
exit 1
;;
esac
trap cleanup EXIT
tmpa=$(mktemp blame.XXXXXX)
tmpb=$(mktemp blame.XXXXXX)
blame "$1" "$arev" > "$tmpa"
# $brev should not be quoted
# if it's empty, it should not take one argument
blame "$1" $brev > "$tmpb"
# -w to ignore git-blame's pesky alignment
diff -w -u "$tmpa" "$tmpb" \
--label "$arev" --label "${brev:-working directory}" || exit 0