Skip to content

Commit 0f476ff

Browse files
committed
feat: setting to switch to specific branch after cloning
1 parent c17f469 commit 0f476ff

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

info.plist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,27 @@ end run</string>
18321832
<key>variable</key>
18331833
<string>fork_on_clone</string>
18341834
</dict>
1835+
<dict>
1836+
<key>config</key>
1837+
<dict>
1838+
<key>default</key>
1839+
<string></string>
1840+
<key>placeholder</key>
1841+
<string>dev</string>
1842+
<key>required</key>
1843+
<false/>
1844+
<key>trim</key>
1845+
<true/>
1846+
</dict>
1847+
<key>description</key>
1848+
<string>Branch: If this branch exists, will switch to it after cloning. Leave empty to disable.</string>
1849+
<key>label</key>
1850+
<string></string>
1851+
<key>type</key>
1852+
<string>textfield</string>
1853+
<key>variable</key>
1854+
<string>default_branch</string>
1855+
</dict>
18351856
<dict>
18361857
<key>config</key>
18371858
<dict>

scripts/clone-repo.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@ fi
2525
# Open in terminal via Alfred
2626
echo -n "$local_repo_folder/$reponame"
2727

28+
cd "$reponame" || return 1
29+
2830
#───────────────────────────────────────────────────────────────────────────────
29-
# RESTORE MTIME
3031

31-
cd "$reponame" || return 1
32+
# SWITCH TO DEFAULT BRANCH
33+
if [[ -n "$default_branch" ]]; then
34+
# `git switch` fails silently if the branch does not exist
35+
git switch "$default_branch" &> /dev/null
36+
fi
3237

33-
# https://stackoverflow.com/a/36243002/22114136
38+
# RESTORE MTIME
3439
if [[ "$restore_mtime" == "1" ]]; then
40+
# https://stackoverflow.com/a/36243002/22114136
3541
git ls-tree -r -t --full-name --name-only HEAD | while read -r file; do
3642
timestamp=$(git log --pretty=format:%cd --date=format:%Y%m%d%H%M.%S -1 HEAD -- "$file")
3743
touch -t "$timestamp" "$file"
3844
done
3945
fi
4046

41-
#───────────────────────────────────────────────────────────────────────────────
4247
# FORK ON CLONE (if not owner)
43-
4448
# INFO Alfred stores checkbox settings as `"1"` or `"0"`, and variables in stringified form.
4549
if [[ "$ownerOfRepo" != "true" && "$fork_on_clone" == "1" ]]; then
4650
if [[ ! -x "$(command -v gh)" ]]; then print "\`gh\` not installed." && return 1; fi

0 commit comments

Comments
 (0)