-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-diffdiff
More file actions
executable file
·98 lines (78 loc) · 1.91 KB
/
Copy pathgit-diffdiff
File metadata and controls
executable file
·98 lines (78 loc) · 1.91 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
#!/bin/bash
usage()
{
self=$( basename $0 )
cat << EOUSAGE
Usage: $self base1 branch1 [[base2] branch2] [-- <extra "git diff" params>]
Compares the overall change sets for two pairs of commits/branches.
Similar to range-diff, except that range-diff compares per-commit.
This compares everything at once.
Can be run with 2 to 4 branch parameters.
With 4, the differences between the first pair and the second pair are
shown. For both pairs, the "branch" is compared against the merge base
for "base" and "branch" so you don't have to find it.
Specifically, "$self A B C D" is equivalent to
"diff -u -minimal <( git diff --merge-base A B )
<( git diff --merge-base C D )"
With 3, the first parameter is used as the "base" branch for both of the
other two.
Thus "$self A B D" is equivalent to "$self A B A D".
With 2 branches, each branch is compared against their common base.
Similar to "git range-diff A...B", except I don't want to write a parser
right now.
Thus "$self A B" is equivalent to "$self B A A B". The ordering assumes
that A is the "older" branch, and so the comparison will treat its
changes as the diff's "file1".
EOUSAGE
exit 1
}
if [[ $# -lt 2 ]]
then
usage
fi
bcount=0
for f in "$@"
do
if [[ "$f" == "--" ]]
then
break
fi
bcount=$[ $bcount + 1 ]
done
if [[ $bcount -lt 2 || $bcount -gt 4 ]]
then
usage
fi
base1=$1
shift
branch1=$1
shift
if [[ $bcount -eq 2 ]]
then
# Use both branches as base and branch, swapping the apparent order
base2=$base1
branch2=$branch1
base1=$branch2
branch1=$base2
else
if [[ $bcount -eq 3 ]]
then
base2=$base1
else
base2=$1
shift
fi
branch2=$1
shift
fi
diffmb()
{
git diff --merge-base "$@"
}
if [[ -t 1 ]]
then
diffparam=( "--color=always" )
fi
diff -u --minimal "${diffparam[@]}" \
<( diffmb $base1 $branch1 "$@" ) \
<( diffmb $base2 $branch2 "$@" ) | less