-
Notifications
You must be signed in to change notification settings - Fork 0
/
kdiffdirs
executable file
·44 lines (36 loc) · 1.15 KB
/
kdiffdirs
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
#!/bin/bash
#
# Kaleidoscope diff of only the Git-version-controlled files in a pair of directories.
# Optionally, limit the common subdirectories that will be compared.
#
set -e
if [[ -z "$2" ]]; then
echo 'Usage: '`basename "$0"`' DIR DIR'
echo ' '`basename "$0"`' DIR DIR SUBDIR...'
exit 1
fi
old="$1"
shift
new="$1"
shift
# $@ is now the list of subdirs, if any
echo -e "Comparing $old\t$@"
echo -e " $new\t$@"
gitlocation() {
cd $1; echo "$(basename $(git rev-parse --show-toplevel))/$(git rev-parse --show-prefix)"
}
label="$(gitlocation $old) | $(gitlocation $new)"
# for each path of a version-controlled files in either $old or $new...
cat <(cd $old && git ls-files "$@") <(cd $new && git ls-files "$@") | sort -u | while IFS= read -r path; do
a="${old%%/}/$path"
b="${new%%/}/$path"
# ... represent missing files (new additions & deletions) ...
if [[ ! -f "$a" ]]; then
a=/dev/null
fi
if [[ ! -f "$b" ]]; then
b=/dev/null
fi
# ... and send the file to ksdiff only if there are changes
diff -q "$a" "$b" > /dev/null || ksdiff --partial-changeset --label "$label" --relative-path "$path" "$a" "$b" < /dev/null
done