diff --git a/diff-sha.sh b/diff-sha.sh index 5e064a68ef1..74b28b99f66 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -230,7 +230,7 @@ else PREVIOUS_SHA=$(git rev-parse origin/"$TARGET_BRANCH") && exit_status=$? || exit_status=$? DIFF=".." - if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then + if ! git diff --name-only --ignore-submodules=all "$CURRENT_SHA$DIFF$PREVIOUS_SHA" 1>/dev/null 2>&1; then echo "::error::Unable find a diff between $PREVIOUS_SHA and $CURRENT_SHA" exit 1 fi diff --git a/get-changed-paths.sh b/get-changed-paths.sh index bff1402becc..e3c87f0008f 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -46,27 +46,27 @@ function get_dirname_max_depth() { } function get_diff() { - local base="$1" - local sha="$2" + local base_sha="$1" + local head_sha="$2" local filter="$3" while IFS='' read -r sub; do - sub_commit_pre="$(git diff "$base$DIFF$sha" -- "$sub" | { grep '^[-]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$? + sub_commit_pre="$(git diff "$head_sha$DIFF$base_sha" -- "$sub" | { grep '^[-]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then - echo "::error::Failed to get previous commit for submodule ($sub) between: $base$DIFF$sha" + echo "::error::Failed to get previous commit for submodule ($sub) between: $head_sha$DIFF$base_sha" exit 1 fi - sub_commit_cur="$(git diff "$base$DIFF$sha" -- "$sub" | { grep '^[+]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$? + sub_commit_cur="$(git diff "$head_sha$DIFF$base_sha" -- "$sub" | { grep '^[+]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then - echo "::error::Failed to get current commit for submodule ($sub) between: $base$DIFF$sha" + echo "::error::Failed to get current commit for submodule ($sub) between: $head_sha$DIFF$base_sha" exit 1 fi if [ -n "$sub_commit_cur" ]; then ( cd "$sub" && ( - # the strange magic number is a hardcoded "empty tree" commit sha + # the strange magic number is a hardcoded "empty tree" commit base_sha get_diff "${sub_commit_pre:-4b825dc642cb6eb9a060e54bf8d69288fbee4904}" "${sub_commit_cur}" "$filter" | awk -v r="$sub" '{ print "" r "/" $0}' ) ) @@ -74,36 +74,36 @@ function get_diff() { done < <(git submodule | awk '{print $2}') if [[ "$INPUT_DIR_NAMES" == "true" ]]; then - git diff --diff-filter="$filter" --name-only --ignore-submodules=all --no-merges "$base$DIFF$sha" | xargs -I {} dirname {} | get_dirname_max_depth | uniq && exit_status=$? || exit_status=$? + git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$head_sha$DIFF$base_sha" | xargs -I {} dirname {} | get_dirname_max_depth | uniq && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then - echo "::error::Failed to get changed directories between: $base$DIFF$sha" + echo "::error::Failed to get changed directories between: $head_sha$DIFF$base_sha" exit 1 fi else - git diff --diff-filter="$filter" --name-only --ignore-submodules=all --no-merges "$base$DIFF$sha" && exit_status=$? || exit_status=$? + git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$head_sha$DIFF$base_sha" && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then - echo "::error::Failed to get changed files between: $base$DIFF$sha" + echo "::error::Failed to get changed files between: $head_sha$DIFF$base_sha" exit 1 fi fi } function get_renames() { - local base="$1" - local sha="$2" + local base_sha="$1" + local head_sha="$2" while IFS='' read -r sub; do - sub_commit_pre="$(git diff "$base$DIFF$sha" -- "$sub" | { grep '^[-]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$? + sub_commit_pre="$(git diff "$head_sha$DIFF$base_sha" -- "$sub" | { grep '^[-]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then - echo "::error::Failed to get previous commit for submodule ($sub) between: $base$DIFF$sha" + echo "::error::Failed to get previous commit for submodule ($sub) between: $head_sha$DIFF$base_sha" exit 1 fi - sub_commit_cur="$(git diff "$base$DIFF$sha" -- "$sub" | { grep '^[+]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$? + sub_commit_cur="$(git diff "$head_sha$DIFF$base_sha" -- "$sub" | { grep '^[+]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then - echo "::error::Failed to get current commit for submodule ($sub) between: $base$DIFF$sha" + echo "::error::Failed to get current commit for submodule ($sub) between: $head_sha$DIFF$base_sha" exit 1 fi @@ -118,17 +118,17 @@ function get_renames() { done < <(git submodule | awk '{print $2}') if [[ "$INPUT_DIR_NAMES" == "true" ]]; then - git log --name-status --ignore-submodules=all "$base" "$sha" | { grep -E "^R" || true; } | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' | xargs -I {} dirname {} | get_dirname_max_depth | uniq && exit_status=$? || exit_status=$? + git log --name-status --ignore-submodules=all "$head_sha" "$base_sha" | { grep -E "^R" || true; } | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' | xargs -I {} dirname {} | get_dirname_max_depth | uniq && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then - echo "::error::Failed to get renamed directories between: $base → $sha" + echo "::error::Failed to get renamed directories between: $head_sha → $base_sha" exit 1 fi else - git log --name-status --ignore-submodules=all "$base" "$sha" | { grep -E "^R" || true; } | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' && exit_status=$? || exit_status=$? + git log --name-status --ignore-submodules=all "$head_sha" "$base_sha" | { grep -E "^R" || true; } | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then - echo "::error::Failed to get renamed files between: $base → $sha" + echo "::error::Failed to get renamed files between: $head_sha → $base_sha" exit 1 fi fi