Skip to content

Commit

Permalink
fix: bug with detecting deleted files
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 authored Oct 1, 2023
1 parent 1d6a375 commit 312b11e
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,46 @@ if [[ "$INPUT_MATCH_GITIGNORE_FILES" == "true" ]]; then
fi

if [[ -n "$INPUT_FILES_PATTERN_FILE" ]]; then
TRACKED_FILES=$(git diff --diff-filter=ACMUXTRD --name-only | { grep -x -E -f "$INPUT_FILES_PATTERN_FILE" || true; } | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
TRACKED_FILES=$(git diff --diff-filter=ACMUXTR --name-only | { grep -x -E -f "$INPUT_FILES_PATTERN_FILE" || true; } | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')

# Find untracked changes
# shellcheck disable=SC2086
UNTRACKED_OR_IGNORED_FILES=$(git status $GIT_STATUS_EXTRA_ARGS | awk '{print $NF}' | { grep -x -E -f "$INPUT_FILES_PATTERN_FILE" || true; } | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')

# Find unstaged deleted files
UNSTAGED_DELETED_FILES=$(git ls-files --deleted | { grep -x -E -f "$INPUT_FILES_PATTERN_FILE" || true; } | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
else
TRACKED_FILES=$(git diff --diff-filter=ACMUXTRD --name-only | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
TRACKED_FILES=$(git diff --diff-filter=ACMUXTR --name-only | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')

# Find untracked changes
# shellcheck disable=SC2086
UNTRACKED_OR_IGNORED_FILES=$(git status $GIT_STATUS_EXTRA_ARGS | awk '{print $NF}' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')

# Find unstaged deleted files
UNSTAGED_DELETED_FILES=$(git ls-files --deleted | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
fi

CHANGED_FILES=""

if [[ -n "$TRACKED_FILES" && -n "$UNTRACKED_OR_IGNORED_FILES" ]]; then
CHANGED_FILES="$TRACKED_FILES|$UNTRACKED_OR_IGNORED_FILES"
elif [[ -n "$TRACKED_FILES" && -z "$UNTRACKED_OR_IGNORED_FILES" ]]; then
CHANGED_FILES="$TRACKED_FILES"
elif [[ -n "$UNTRACKED_OR_IGNORED_FILES" && -z "$TRACKED_FILES" ]]; then
CHANGED_FILES="$UNTRACKED_OR_IGNORED_FILES"
fi
# Function to concatenate non-empty strings with a separator
concatenate() {
local separator=$1
shift
local result=""
for str in "$@"; do
if [[ -n $str ]]; then
if [[ -n $result ]]; then
result+="$separator$str"
else
result="$str"
fi
fi
done
echo "$result"
}

# Concatenate non-empty strings with a '|' separator
CHANGED_FILES=$(concatenate "|" "$TRACKED_FILES" "$UNTRACKED_OR_IGNORED_FILES" "$UNSTAGED_DELETED_FILES")

CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{gsub(/\|/,"\n"); print $0;}' | sort -u | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')

Expand Down

0 comments on commit 312b11e

Please sign in to comment.