-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-diff-wrapper.sh
More file actions
executable file
·66 lines (55 loc) · 1.92 KB
/
Copy pathgit-diff-wrapper.sh
File metadata and controls
executable file
·66 lines (55 loc) · 1.92 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
#!/bin/bash
set -euo pipefail
# Usage: CMSCOUT_KEEP_UNCHANGED=1 git -c diff.external=git-diff-wrapper.sh log --ext-diff -p
# Git external diff wrapper: maps git's protocol args ($1 path, $2/$5 content files,
# $8 rename name) to `cmscout -B $2 -A $5 a/$1 b/${8-$1}`; -B/-A carry the contents.
# Unmerged paths arrive as a single path argument (merge conflicts).
if [ "$#" -eq 1 ]; then
echo "* Unmerged path $1"
exit 0
fi
if [ "$#" -lt 7 ]; then
echo "git-diff-wrapper.sh: expected Git external diff arguments" >&2
exit 2
fi
old_name="$1"
old_content="$2"
# $3 = old hex, $4 = old mode
new_content="$5"
# $6 = new hex, $7 = new mode
# $8 = new file name (only present for renames); fall back to old name
new_name="${8:-$old_name}"
# Resolve the cmscout binary relative to this script's location.
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cmscout_bin="${script_dir}/cmscout"
if [ ! -x "$cmscout_bin" ]; then
cmscout_bin="$(command -v cmscout 2>/dev/null || echo cmscout)"
fi
# Skip-unchanged flag
skip_flags="--skip-unchanged"
if [ "${CMSCOUT_KEEP_UNCHANGED-}" = "1" ]; then
skip_flags=""
fi
# NO_COLOR (https://no-color.org): when present and non-empty, disable ANSI color.
no_color_flags=""
if [ -n "${NO_COLOR-}" ]; then
no_color_flags="--no-color"
fi
# Added/removed body style flags (case separation for testing)
# CMSCOUT_ADDED_STYLE=white|green, CMSCOUT_REMOVED_STYLE=white|red
added_flags=""
if [ -n "${CMSCOUT_ADDED_STYLE-}" ]; then
added_flags="--added-style=$CMSCOUT_ADDED_STYLE"
fi
removed_flags="--removed-style=red"
if [ -n "${CMSCOUT_REMOVED_STYLE-}" ]; then
removed_flags="--removed-style=$CMSCOUT_REMOVED_STYLE"
fi
if [ -n "${CMSCOUT_WORD_DIFF-}" ]; then
word_diff="--word-diff --ignore-all-space"
else
word_diff="--ignore-all-space"
fi
"$cmscout_bin" $no_color_flags $skip_flags $added_flags $removed_flags $word_diff \
-B "$old_content" -A "$new_content" \
"a/$old_name" "b/$new_name"