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+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ function update_branches() {
5+ git fetch origin > /dev/null 2>&1 || true
6+ }
7+
8+ function get_branch_diff() {
9+ local COMPARE_WITH_BRANCH=" ${1} "
10+ local BRANCH_TO_COMPARE=" HEAD"
11+ local FILES
12+
13+ echo " Running branch diff"
14+ echo " Comparing: ${BRANCH_TO_COMPARE} "
15+ echo " with : ${COMPARE_WITH_BRANCH} "
16+ echo
17+
18+ update_branches
19+
20+ FILES=$( git diff --name-only " ${BRANCH_TO_COMPARE} ...${COMPARE_WITH_BRANCH} " )
21+
22+ if [ -z " ${FILES} " ]; then
23+ echo " No changes detected between branches."
24+ return
25+ fi
26+
27+ echo " Files changed..."
28+ echo " ${FILES} "
29+ echo
30+
31+ echo " Generating branch diff..."
32+ git diff --unified=5 " ${BRANCH_TO_COMPARE} ...${COMPARE_WITH_BRANCH} "
33+ }
34+
35+ function main() {
36+ if [[ $# -lt 1 ]]; then
37+ echo " Usage: $0 BRANCH_TO_COMPARE_WITH"
38+ exit 1
39+ fi
40+
41+ get_branch_diff " $@ "
42+ }
43+
44+ main " $@ "
You can’t perform that action at this time.
0 commit comments