Skip to content

Commit

Permalink
feat: support to restore mtime of all files (#40)
Browse files Browse the repository at this point in the history
Restore the modification time (mtime) of all files in work tree, based
on the date of the most recent commit that modified the file.
  • Loading branch information
jeffreytse committed May 8, 2022
1 parent 185bd55 commit d51e3c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ ${SCRIPT_DIR}/script/init_environment.sh

cd ${JEKYLL_SRC}

# Restore modification time (mtime) of git files
echo "Restore modification time of all git files"
${SCRIPT_DIR}/script/restore_mtime.sh

# Check and execute pre_build_commands commands
if [[ ${PRE_BUILD_COMMANDS} ]]; then
echo "Executing pre-build commands"
Expand Down
10 changes: 10 additions & 0 deletions script/restore_mtime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Restore the modification time (mtime) of all files in work tree, based on the
# date of the most recent commit that modified the file.
for f in $(git ls-files); do
mtime=$(git log -1 --format='%at' -- "$f")
[[ "$mtime" == "" ]] && continue
mtime=$(date -d @"$mtime" "+%Y-%m-%dT%H:%M:%S")
touch -d "$mtime" "$f"
done

0 comments on commit d51e3c7

Please sign in to comment.