Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: bug with detecting deleted files #342

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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