-
Notifications
You must be signed in to change notification settings - Fork 30
/
git_diff_image
executable file
·81 lines (68 loc) · 1.36 KB
/
git_diff_image
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
#!/bin/bash
set -euo pipefail
name="$1"
f1="${2-/dev/null}"
f2="${5-/dev/null}"
name1="a/$name"
name2="b/$name"
if [ "$f1" = /dev/null ]
then
name1=/dev/null
fi
if [ "$f2" = /dev/null ]
then
name2=/dev/null
fi
if diff "$f1" "$f2" >/dev/null
then
exit 0
fi
readlink_f()
{
if [ $(uname) = 'Darwin' ]
then
local f=$(readlink "$1")
if [ -z "$f" ]
then
f="$1"
fi
local d=$(dirname "$f")
local b=$(basename "$f")
if [ -d "$d" ]
then
(cd "$d" && echo "$(pwd -P)/$b")
elif [[ "$d" = /* ]]
then
echo "$f"
elif [[ "$d" = ./* ]]
then
echo "$(pwd -P)/${f/.\//}"
else
echo "$(pwd -P)/$f"
fi
else
readlink -f "$1"
fi
}
thisdir="$(dirname $(readlink_f "$0"))"
e_flag=''
if [ -z "${GIT_DIFF_IMAGE_ENABLED-}" ] || \
! which compare > /dev/null || \
! which montage > /dev/null
then
e_flag='-e'
fi
o_flag=''
if [ -n "${GIT_DIFF_IMAGE_OUTPUT_DIR-}" ]
then
mkdir -p "$GIT_DIFF_IMAGE_OUTPUT_DIR"
destfile=''
if [ "$name1" = '/dev/null' ]
then
destfile=$(basename "$name1")
else
destfile=$(basename "$name2")
fi
o_flag="-o $GIT_DIFF_IMAGE_OUTPUT_DIR/$destfile"
fi
exec "$thisdir/diff-image" $e_flag $o_flag -n "$name1" -N "$name2" "$f1" "$f2"