File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ cherrypick_merge () {
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+ cherrypick_merge $STAT $LEFT_COMMIT $RIGHT_COMMIT
87+
88+
You can’t perform that action at this time.
0 commit comments