From 2a07d1823a18c2dd3e8fe86eb552e16585727727 Mon Sep 17 00:00:00 2001 From: Chris Buckley Date: Tue, 17 Feb 2026 16:17:27 +0000 Subject: [PATCH] Stop last-modified script over-committing (fixes #549) Lines may have changed close to the last_modified_at line which would result in conflicts if using stash/patch applies. --- _ci/last-modified.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/_ci/last-modified.sh b/_ci/last-modified.sh index 5f674f4d..529678ce 100755 --- a/_ci/last-modified.sh +++ b/_ci/last-modified.sh @@ -11,13 +11,27 @@ $0 ~ "---" && ++count == 2 { date="$(date +'%Y-%m-%d %H:%M %z')" awk 2>&1 | grep -q includefile && inplace=1 || inplace=0 -while read -d $'\0' file; do +patchdate () { if [ $inplace -eq 1 ]; then - awk -i inplace -v date="$date" "$awkcmd" "$file" + awk -i inplace -v date="$date" "$awkcmd" "$1" else tmp=$(mktemp) - awk -v date="$date" "$awkcmd" "$file" > "$tmp" - mv "$tmp" "$file" + awk -v date="$date" "$awkcmd" "$1" > "$tmp" + mv "$tmp" "$1" fi - git add "$file" # @todo avoid committing any other changes +} + +while read -d $'\0' file; do + # move file out and get rid of unstaged changes + tmp=$(mktemp) + cp "$file" "$tmp" + git restore "$file" + + # patch and add the file + patchdate "$file" + git add "$file" + + # restore the unstaged changes and reapply the patch + mv "$tmp" "$file" + patchdate "$file" done