From 50332812e918bc5b211c4d4c97494c870b42ba86 Mon Sep 17 00:00:00 2001 From: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> Date: Fri, 31 Mar 2023 06:34:02 +1300 Subject: [PATCH] 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 --- scripts/helpers/restyle-diff.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/helpers/restyle-diff.sh b/scripts/helpers/restyle-diff.sh index bf428dc1ea7a17..6b5f25cd259400 100755 --- a/scripts/helpers/restyle-diff.sh +++ b/scripts/helpers/restyle-diff.sh @@ -23,7 +23,7 @@ # Usage: # restyle-diff.sh [ref] # -# if unspecified, ref defaults to "master" +# if unspecified, ref defaults to upstream/master (or master) # here=${0%/*} @@ -31,6 +31,7 @@ here=${0%/*} set -e CHIP_ROOT=$(cd "$here/../.." && pwd) +cd "$CHIP_ROOT" restyle-paths() { if hash restyle-path 2>/dev/null; then @@ -41,7 +42,11 @@ restyle-paths() { fi } -cd "$CHIP_ROOT" -declare -a paths="($(git diff --ignore-submodules --name-only "${1:-master}"))" +ref="$1" +if [[ -z "$ref" ]]; then + ref="master" + git remote | grep -qxF upstream && ref="upstream/master" +fi +declare -a paths="($(git diff --ignore-submodules --name-only --merge-base "$ref"))" restyle-paths "${paths[@]}"