Skip to content

Commit 7ac8044

Browse files
committed
improv(clone): display & explanations
1 parent 16dc9b9 commit 7ac8044

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

info.plist

+15-15
Original file line numberDiff line numberDiff line change
@@ -1777,41 +1777,41 @@
17771777
<key>config</key>
17781778
<dict>
17791779
<key>default</key>
1780-
<false/>
1780+
<string>10</string>
1781+
<key>placeholder</key>
1782+
<string></string>
17811783
<key>required</key>
17821784
<false/>
1783-
<key>text</key>
1784-
<string>fork when not owner</string>
1785+
<key>trim</key>
1786+
<true/>
17851787
</dict>
17861788
<key>description</key>
1787-
<string>When cloning a repository that you do not own, also create a fork an prepare the repo for e PR. (Requires the `gh` cli.)</string>
1789+
<string>Depth of the clone (`--shallow={n}`). Leave empty to not perform shallow clone.</string>
17881790
<key>label</key>
17891791
<string></string>
17901792
<key>type</key>
1791-
<string>checkbox</string>
1793+
<string>textfield</string>
17921794
<key>variable</key>
1793-
<string>fork_on_clone</string>
1795+
<string>clone_depth</string>
17941796
</dict>
17951797
<dict>
17961798
<key>config</key>
17971799
<dict>
17981800
<key>default</key>
1799-
<string>5</string>
1800-
<key>placeholder</key>
1801-
<string></string>
1801+
<false/>
18021802
<key>required</key>
18031803
<false/>
1804-
<key>trim</key>
1805-
<true/>
1804+
<key>text</key>
1805+
<string>fork when not owner</string>
18061806
</dict>
18071807
<key>description</key>
1808-
<string>Depth of the clone (`--shallow={n}`)</string>
1808+
<string>When cloning a repository that you do not own, also create a fork an prepare the repo for e PR. (Requires the `gh` cli.)</string>
18091809
<key>label</key>
18101810
<string></string>
18111811
<key>type</key>
1812-
<string>textfield</string>
1812+
<string>checkbox</string>
18131813
<key>variable</key>
1814-
<string>clone_depth</string>
1814+
<string>fork_on_clone</string>
18151815
</dict>
18161816
<dict>
18171817
<key>config</key>
@@ -1824,7 +1824,7 @@
18241824
<string>restore mtime</string>
18251825
</dict>
18261826
<key>description</key>
1827-
<string></string>
1827+
<string>`git clone` normally erases modification time of files. It can be restored from the commit log, though. However, this the modification time then only goes as far back as the oldest commit, so you might want to increase clone depth.</string>
18281828
<key>label</key>
18291829
<string></string>
18301830
<key>type</key>

scripts/clone-repo.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ url="[email protected]:$source_repo.git" # use SSH instead of https
99
[[ ! -e "$local_repo_folder" ]] && mkdir -p "$local_repo_folder"
1010
cd "$local_repo_folder" || return 1
1111

12+
#───────────────────────────────────────────────────────────────────────────────
13+
# CLONE
1214
# validate depth, minimum 2
1315
# WARN depth=2 ensures that amending a shallow commit does not result in a
1416
# new commit without parent, effectively destroying git history (!!)
1517
[[ $clone_depth =~ ^[0-9]+$ && $clone_depth -ge 2 ]] || clone_depth=2
1618

17-
git clone --depth="$clone_depth" "$url" --no-single-branch --no-tags # get branches, but not tags
19+
if [[ $clone_depth -eq 0 ]]; then
20+
git clone "$url" --no-single-branch --no-tags # get branches, but not tags
21+
else
22+
git clone "$url" --depth="$clone_depth" --no-single-branch --no-tags
23+
fi
1824

1925
# Open in terminal via Alfred
2026
echo -n "$local_repo_folder/$reponame"
2127

2228
#───────────────────────────────────────────────────────────────────────────────
23-
# RESTORE MTIME
29+
# RESTORE MTIME
2430

2531
cd "$reponame" || return 1
2632

scripts/my-github-repos.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function run() {
2727
// CONFIG
2828
const username = $.getenv("github_username");
2929
const localRepoFolder = $.getenv("local_repo_folder");
30+
const depthInfo = $.getenv("clone_depth") ? ` (depth ${$.getenv("clone_depth")})` : "";
3031

3132
// determine local repos
3233
const localRepos = {};
@@ -76,7 +77,7 @@ function run() {
7677
// changes when repo is local
7778
repo.local = localRepos[repo.name];
7879
const mainArg = repo.local?.path || repo.html_url;
79-
const terminalActionDesc = repo.local ? "Open in Terminal" : "Shallow Clone";
80+
const terminalActionDesc = repo.local ? "Open in Terminal" : "Shallow Clone" + depthInfo;
8081
// open in terminal when local, clone when not
8182
const terminalArg = repo.local?.path || repo.html_url;
8283
if (repo.local) {

scripts/public-github-repo-search.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ function run(argv) {
6666
}
6767

6868
const forkOnClone = $.getenv("fork_on_clone") === "1";
69+
const depthInfo = $.getenv("clone_depth") ? ` (depth ${$.getenv("clone_depth")})` : "";
6970
const apiURL = `https://api.github.com/search/repositories?q=${encodeURIComponent(query)}`;
7071

7172
/** @type {AlfredItem[]} */
7273
const repos = JSON.parse(httpRequest(apiURL))
7374
.items.filter((/** @type {GithubRepo} */ repo) => !(repo.fork || repo.archived))
7475
.map((/** @type {GithubRepo} */ repo) => {
75-
console.log("🪚 " + repo.full_name);
76-
7776
// calculate relative date
7877
// INFO pushed_at refers to commits only https://github.com/orgs/community/discussions/24442
7978
// CAVEAT pushed_at apparently also includes pushes via PR :(
@@ -86,8 +85,7 @@ function run(argv) {
8685
repo.description,
8786
].join(" · ");
8887

89-
const cloneSubtitle = "⌃: Shallow Clone" + (forkOnClone ? " & Fork" : "");
90-
88+
const cloneSubtitle = "⌃: Shallow Clone " + depthInfo + (forkOnClone ? " & Fork" : "");
9189
const secondUrl = repo.homepage || repo.html_url + "/releases";
9290

9391
return {

0 commit comments

Comments
 (0)