Skip to content

Commit ca5deb3

Browse files
Make restyle-diff pick a better base to restyle against (#25887)
- Default to upstream/master if upstream exists - Use --merge-base to restrict to files changes on current branch
1 parent 21aa4d6 commit ca5deb3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

scripts/helpers/restyle-diff.sh

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
# Usage:
2424
# restyle-diff.sh [ref]
2525
#
26-
# if unspecified, ref defaults to "master"
26+
# if unspecified, ref defaults to upstream/master (or master)
2727
#
2828

2929
here=${0%/*}
3030

3131
set -e
3232

3333
CHIP_ROOT=$(cd "$here/../.." && pwd)
34+
cd "$CHIP_ROOT"
3435

3536
restyle-paths() {
3637
if hash restyle-path 2>/dev/null; then
@@ -41,7 +42,11 @@ restyle-paths() {
4142
fi
4243
}
4344

44-
cd "$CHIP_ROOT"
45-
declare -a paths="($(git diff --ignore-submodules --name-only "${1:-master}"))"
45+
ref="$1"
46+
if [[ -z "$ref" ]]; then
47+
ref="master"
48+
git remote | grep -qxF upstream && ref="upstream/master"
49+
fi
4650

51+
declare -a paths="($(git diff --ignore-submodules --name-only --merge-base "$ref"))"
4752
restyle-paths "${paths[@]}"

0 commit comments

Comments
 (0)