-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: change mtime modification script
- Loading branch information
Showing
1 changed file
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |