]> git.phdru.name Git - git-scripts.git/commitdiff
Fead: Add `set-last-commit-date-changed`
authorOleg Broytman <phd@phdru.name>
Mon, 22 Jan 2024 14:41:31 +0000 (17:41 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 22 Jan 2024 14:41:31 +0000 (17:41 +0300)
hooks/post-checkout/set-last-commit-date-changed [new file with mode: 0755]

diff --git a/hooks/post-checkout/set-last-commit-date-changed b/hooks/post-checkout/set-last-commit-date-changed
new file mode 100755 (executable)
index 0000000..4074707
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# post-checkout hook that changes timestamps on changed files
+# to that one of the last commit (head) if branch was changed
+
+prev_HEAD="$1"
+new_HEAD="$2"
+new_branch="$3"
+
+if [ "$new_branch" = 1 ]; then
+   commit_date="`git show --format='%cD' | head -1`" &&
+   touch --date="$commit_date" `git diff --name-only HEAD~`
+fi
+
+exit 0