Skip to content

Commit

Permalink
ci: change mtime modification script
Browse files Browse the repository at this point in the history
  • Loading branch information
jolars committed May 31, 2024
1 parent 928c587 commit 5ed3c1e
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions .github/scripts/fix-mtime
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
#!/usr/bin/env sh
#!/bin/sh -e

git ls-tree -r --name-only HEAD | while read filename; do
unixtime=$(git log -1 --format="%at" -- "${filename}")
touchtime=$(date -d @$unixtime +'%Y%m%d%H%M.%S')
touch -t ${touchtime} "${filename}"
OS=${OS:-$(uname)}

if [ "$OS" = 'Darwin' ]; then
get_touch_time() {
date -r "${unixtime}" +'%Y%m%d%H%M.%S'
}
else
# default Linux
get_touch_time() {
date -d @"${unixtime}" +'%Y%m%d%H%M.%S'
}
fi

# all git files
git ls-tree -r --name-only HEAD >.git_ls-tree_r_name-only_HEAD

# modified git files
git diff --name-only >.git_diff_name-only

# minus https://stackoverflow.com/questions/1370996/minus-operation-on-two-files-using-linux-commands
# only restore files not modified
comm -2 -3 .git_ls-tree_r_name-only_HEAD .git_diff_name-only | while read -r filename; do
unixtime=$(git log -1 --format="%at" -- "${filename}")
touchtime=$(get_touch_time)
echo "${touchtime}" "${filename}"
touch -t "${touchtime}" "${filename}"
done

rm .git_ls-tree_r_name-only_HEAD .git_diff_name-only

0 comments on commit 5ed3c1e

Please sign in to comment.