Skip to content

Commit ebc9856

Browse files
committed
Add a script to generate the diff between 2 branches
1 parent 31ffe53 commit ebc9856

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

bin/git-bc-diff-branch

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
# Copyright 2017 Bright Computing Holding BV.
3+
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
USAGE="\
19+
git bc-diff-branch
20+
21+
Generates the diff between 2 branches considering only the files
22+
modified from the common ancestor from the left commit and
23+
the right commit.
24+
25+
Usage:
26+
git bc-diff-branch [options]
27+
28+
Options:
29+
-s, --stat Enable git diff stat feature
30+
-l, --left Left branch
31+
-r, --right Right branch
32+
33+
34+
"
35+
SCRIPT=`readlink -f $0`
36+
DIR=`dirname $SCRIPT`
37+
38+
. $DIR/bc-env.sh
39+
40+
41+
STAT=0
42+
while [ $# -gt 0 ]; do
43+
ARG=$1
44+
case "$ARG" in
45+
--help|-h)
46+
HELP=1
47+
;;
48+
--stat|-s)
49+
shift
50+
STAT=1
51+
;;
52+
--left|-l)
53+
shift
54+
LEFT_COMMIT=$1
55+
;;
56+
--right|-r)
57+
shift
58+
RIGHT_COMMIT=$1
59+
;;
60+
--*)
61+
die "unrecognised option: $ARG" ;;
62+
esac
63+
shift
64+
done
65+
66+
if [ "$HELP" -eq 1 ] || [ -z "$LEFT_COMMIT" ] || [ -z "$RIGHT_COMMIT" ]; then
67+
usage
68+
fi
69+
70+
71+
perform_diff() {
72+
STAT=""
73+
if [ "$1" -eq "1" ]; then
74+
STAT="--stat"
75+
fi
76+
77+
LEFT_COMMIT=$2
78+
RIGHT_COMMIT=$3
79+
80+
COMMON_ANCESTOR=$(git merge-base $LEFT_COMMIT $RIGHT_COMMIT)
81+
FILES=$(git show --pretty="" --name-only $COMMON_ANCESTOR..HEAD)
82+
83+
git diff $STAT $LEFT_COMMIT $RIGHT_COMMIT $FILES
84+
}
85+
86+
perform_diff $STAT $LEFT_COMMIT $RIGHT_COMMIT
87+
88+

0 commit comments

Comments
 (0)