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