add collect_new_files

This commit is contained in:
2026-03-26 09:32:50 +02:00
parent 45c23fb721
commit 66b5992547
2 changed files with 181 additions and 88 deletions

92
scripts/collect_new_files.sh Executable file
View File

@@ -0,0 +1,92 @@
#!/bin/bash
# Collect newly created files from a range of commits into new_files.zip
set -e
# Load recent commits into an array
mapfile -t COMMITS < <(git log --oneline -30)
echo "Recent commits:"
echo "─────────────────────────────────────────────────"
for i in "${!COMMITS[@]}"; do
printf " %2d) %s\n" "$((i + 1))" "${COMMITS[$i]}"
done
echo "─────────────────────────────────────────────────"
echo ""
read -rp "Select START commit # (older): " START_NUM
read -rp "Select END commit # (newer): " END_NUM
# Validate input
if ! [[ "$START_NUM" =~ ^[0-9]+$ ]] || ! [[ "$END_NUM" =~ ^[0-9]+$ ]]; then
echo "Error: please enter valid numbers"
exit 1
fi
if [ "$START_NUM" -lt 1 ] || [ "$START_NUM" -gt ${#COMMITS[@]} ] || \
[ "$END_NUM" -lt 1 ] || [ "$END_NUM" -gt ${#COMMITS[@]} ]; then
echo "Error: number out of range (1-${#COMMITS[@]})"
exit 1
fi
if [ "$END_NUM" -ge "$START_NUM" ]; then
echo "Error: END commit must be newer (lower number) than START commit"
exit 1
fi
# Extract commit hashes (first word of each line)
COMMIT_FROM=$(echo "${COMMITS[$((START_NUM - 1))]}" | awk '{print $1}')
COMMIT_TO=$(echo "${COMMITS[$((END_NUM - 1))]}" | awk '{print $1}')
echo ""
echo "Scanning commits from $COMMIT_FROM to $COMMIT_TO..."
echo ""
# Collect all newly added files across the commit range
# --diff-filter=A means only "Added" files
# Use COMMIT_FROM~1 so the range includes the start commit itself
NEW_FILES=$(git diff --diff-filter=A --name-only "$COMMIT_FROM~1".."$COMMIT_TO")
if [ -z "$NEW_FILES" ]; then
echo "No new files found in the given commit range."
exit 0
fi
echo "New files found:"
echo "─────────────────────────────────────────────────"
echo "$NEW_FILES"
echo "─────────────────────────────────────────────────"
echo ""
# Filter to only files that still exist on disk
EXISTING_FILES=()
MISSING_FILES=()
while IFS= read -r file; do
if [ -f "$file" ]; then
EXISTING_FILES+=("$file")
else
MISSING_FILES+=("$file")
fi
done <<< "$NEW_FILES"
if [ ${#MISSING_FILES[@]} -gt 0 ]; then
echo "Skipping ${#MISSING_FILES[@]} file(s) no longer on disk:"
for f in "${MISSING_FILES[@]}"; do
echo " - $f"
done
echo ""
fi
if [ ${#EXISTING_FILES[@]} -eq 0 ]; then
echo "No files to zip (all were deleted since)."
exit 0
fi
# Remove old zip if it exists
rm -f new_files.zip
zip -j new_files.zip "${EXISTING_FILES[@]}"
echo ""
echo "Done! ${#EXISTING_FILES[@]} file(s) added to new_files.zip"

View File

@@ -218,6 +218,7 @@ echo "{
\"authType\": \"password\",
\"ignore\": [
\".git\",
\".env\",
\".gosync.json\",
\".vscode\",
\".DS_Store\",
@@ -258,10 +259,10 @@ add_to_gitignore ".gosync.json"
# Go through scripts, add variables and add them to project folder
if [ "$SFTP_ONLY" = true ]; then
# Sftp only scripts
scripts=("local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh")
scripts=("local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh" "collect_new_files.sh")
else
# All scripts
scripts=("watch-build.sh" "local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh" "split-conflicts.sh")
scripts=("watch-build.sh" "local-remote.sh" "remote-local.sh" "sftp-watch.sh" "ssh.sh" "split-conflicts.sh", "collect_new_files.sh")
fi
for script in "${scripts[@]}"; do