Skip to content

Commit

Permalink
Update diff
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Dec 19, 2022
1 parent 5b64877 commit 19b79bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion diff-sha.sh
Expand Up @@ -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
Expand Down
42 changes: 21 additions & 21 deletions get-changed-paths.sh
Expand Up @@ -46,64 +46,64 @@ 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}'
)
)
fi
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

Expand All @@ -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
Expand Down

0 comments on commit 19b79bb

Please sign in to comment.