Skip to content

Commit 62de96c

Browse files
committed
feat: option to restore mtime on clone
1 parent 8c0492e commit 62de96c

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

info.plist

+20-1
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@
17551755
<key>config</key>
17561756
<dict>
17571757
<key>default</key>
1758-
<string>2</string>
1758+
<string>5</string>
17591759
<key>placeholder</key>
17601760
<string></string>
17611761
<key>required</key>
@@ -1772,6 +1772,25 @@
17721772
<key>variable</key>
17731773
<string>clone_depth</string>
17741774
</dict>
1775+
<dict>
1776+
<key>config</key>
1777+
<dict>
1778+
<key>default</key>
1779+
<false/>
1780+
<key>required</key>
1781+
<false/>
1782+
<key>text</key>
1783+
<string>restore mtime</string>
1784+
</dict>
1785+
<key>description</key>
1786+
<string></string>
1787+
<key>label</key>
1788+
<string></string>
1789+
<key>type</key>
1790+
<string>checkbox</string>
1791+
<key>variable</key>
1792+
<string>restore_mtime</string>
1793+
</dict>
17751794
</array>
17761795
<key>version</key>
17771796
<string>0.10.1</string>

scripts/clone-repo.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,29 @@ cd "$local_repo_folder" || return 1
1313
# WARN depth=2 ensures that amending a shallow commit does not result in a
1414
# new commit without parent, effectively destroying git history (!!)
1515
[[ $clone_depth =~ ^[0-9]+$ && $clone_depth -ge 2 ]] || clone_depth=2
16+
1617
git clone --depth="$clone_depth" "$url" --no-single-branch --no-tags # get branches, but not tags
1718

1819
# Open in terminal via Alfred
1920
echo -n "$local_repo_folder/$reponame"
2021

22+
#───────────────────────────────────────────────────────────────────────────────
23+
# RESTORE MTIME
24+
25+
cd "$reponame" || return 1
26+
27+
# https://stackoverflow.com/a/36243002/22114136
28+
if [[ "$restore_mtime" == "1" ]]; then
29+
for file in $(git ls-tree -r -t --full-name --name-only HEAD); do
30+
timestamp=$(git log --pretty=format:%cd --date=format:%Y%m%d%H%M.%S -1 HEAD -- "$file")
31+
touch -t "$timestamp" "$file"
32+
done
33+
fi
34+
2135
#───────────────────────────────────────────────────────────────────────────────
2236
# FORK ON CLONE (if owner)
2337

2438
if [[ "$ownerOfRepo" != "1" && "$fork_on_clone" == "1" ]]; then
25-
cd "$reponame" || return 1
2639
if [[ ! -x "$(command -v gh)" ]]; then print "\`gh\` not installed." && return 1; fi
2740

2841
gh repo fork --remote=false

0 commit comments

Comments
 (0)