Skip to content

Commit 2a07d18

Browse files
committed
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.
1 parent 6b45a28 commit 2a07d18

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

_ci/last-modified.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,27 @@ $0 ~ "---" && ++count == 2 {
1111
date="$(date +'%Y-%m-%d %H:%M %z')"
1212
awk 2>&1 | grep -q includefile && inplace=1 || inplace=0
1313

14-
while read -d $'\0' file; do
14+
patchdate () {
1515
if [ $inplace -eq 1 ]; then
16-
awk -i inplace -v date="$date" "$awkcmd" "$file"
16+
awk -i inplace -v date="$date" "$awkcmd" "$1"
1717
else
1818
tmp=$(mktemp)
19-
awk -v date="$date" "$awkcmd" "$file" > "$tmp"
20-
mv "$tmp" "$file"
19+
awk -v date="$date" "$awkcmd" "$1" > "$tmp"
20+
mv "$tmp" "$1"
2121
fi
22-
git add "$file" # @todo avoid committing any other changes
22+
}
23+
24+
while read -d $'\0' file; do
25+
# move file out and get rid of unstaged changes
26+
tmp=$(mktemp)
27+
cp "$file" "$tmp"
28+
git restore "$file"
29+
30+
# patch and add the file
31+
patchdate "$file"
32+
git add "$file"
33+
34+
# restore the unstaged changes and reapply the patch
35+
mv "$tmp" "$file"
36+
patchdate "$file"
2337
done

0 commit comments

Comments
 (0)