Skip to content

Commit 01e6f86

Browse files
committed
fix: add retry logic for SHA256, show local branches only, exec shell on cd
1 parent 64912e1 commit 01e6f86

2 files changed

Lines changed: 36 additions & 27 deletions

File tree

.github/workflows/release.yaml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,26 @@ jobs:
8989
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
9090
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
9191
92-
# Get SHA256 of the script from release
93-
SHA256=$(curl -sL "https://github.com/${{ github.repository }}/releases/download/${TAG}/git-wt" | shasum -a 256 | cut -d' ' -f1)
94-
echo "sha256=$SHA256" >> "$GITHUB_OUTPUT"
92+
# Download asset using gh CLI (more reliable than curl for fresh releases)
93+
# Retry up to 5 times with 10s delay to handle CDN propagation
94+
for i in {1..5}; do
95+
echo "Attempt $i: Downloading release asset..."
96+
if gh release download "$TAG" --pattern 'git-wt' --output /tmp/git-wt --clobber; then
97+
# Verify it's actually the script (not an error page)
98+
if head -1 /tmp/git-wt | grep -q '^#!/'; then
99+
SHA256=$(shasum -a 256 /tmp/git-wt | cut -d' ' -f1)
100+
echo "sha256=$SHA256" >> "$GITHUB_OUTPUT"
101+
echo "Successfully got SHA256: $SHA256"
102+
exit 0
103+
else
104+
echo "Downloaded file doesn't look like a script, retrying..."
105+
fi
106+
fi
107+
echo "Download failed or invalid, waiting 10s before retry..."
108+
sleep 10
109+
done
110+
echo "Failed to download release asset after 5 attempts"
111+
exit 1
95112
96113
- name: Clone homebrew-devsetup
97114
run: |

bin/git-wt

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ while IFS= read -r line; do
245245
fi
246246
done < <(git -C "$GIT_ROOT" worktree list --porcelain | grep "^worktree " | cut -d' ' -f2-)
247247

248-
# Build branch list from local and remote refs
248+
# Build branch list from local branches only
249249
declare -A BRANCHES
250250

251251
# Get local branches
@@ -255,16 +255,6 @@ while IFS= read -r branch; do
255255
fi
256256
done < <(git -C "$GIT_ROOT" branch --format='%(refname:short)' 2>/dev/null || echo "")
257257

258-
# Get remote branches (without origin/ prefix, excluding HEAD)
259-
while IFS= read -r branch; do
260-
if [[ -n "$branch" ]] && [[ "$branch" != "origin/HEAD" ]]; then
261-
local_name="${branch#origin/}"
262-
if [[ -z "${BRANCHES[$local_name]:-}" ]]; then
263-
BRANCHES["$local_name"]=1
264-
fi
265-
fi
266-
done < <(git -C "$GIT_ROOT" branch -r --format='%(refname:short)' 2>/dev/null || echo "")
267-
268258
# Build menu options
269259
MENU_OPTIONS=()
270260
MENU_OPTIONS+=("📁 (create new worktree)")
@@ -322,22 +312,17 @@ case "$SELECTED" in
322312
mkdir -p "$(dirname "$GIT_ROOT/$WORKTREE_PATH")"
323313
git -C "$GIT_ROOT" worktree add -b "$BRANCH_NAME" "$WORKTREE_PATH" "$BASE_BRANCH"
324314

315+
FINAL_PATH="$(cd "$GIT_ROOT/$WORKTREE_PATH" && pwd)"
325316
echo ""
326-
echo "Created worktree at: $(cd "$GIT_ROOT/$WORKTREE_PATH" && pwd)"
317+
echo "Created worktree at: $FINAL_PATH"
327318
echo "Branch: $BRANCH_NAME (based on $BASE_BRANCH)"
328-
329-
# Print the path for cd (can be captured by caller)
330-
echo ""
331-
echo "WORKTREE_PATH=$(cd "$GIT_ROOT/$WORKTREE_PATH" && pwd)"
332319
;;
333320

334321
"📂 [existing]"*)
335322
# Extract path from selection
336-
WORKTREE_PATH=$(echo "$SELECTED" | sed 's/.*→ //')
323+
FINAL_PATH=$(echo "$SELECTED" | sed 's/.*→ //')
337324
echo ""
338-
echo "Selected existing worktree: $WORKTREE_PATH"
339-
echo ""
340-
echo "WORKTREE_PATH=$WORKTREE_PATH"
325+
echo "Selected existing worktree: $FINAL_PATH"
341326
;;
342327

343328
"🔄 (switch repository)")
@@ -356,7 +341,8 @@ case "$SELECTED" in
356341
WORKTREE_PATH="../${REPO_NAME}.worktrees/${SAFE_BRANCH}"
357342

358343
if [[ -d "$GIT_ROOT/$WORKTREE_PATH" ]]; then
359-
echo "Worktree already exists at: $(cd "$GIT_ROOT/$WORKTREE_PATH" && pwd)"
344+
FINAL_PATH="$(cd "$GIT_ROOT/$WORKTREE_PATH" && pwd)"
345+
echo "Worktree already exists at: $FINAL_PATH"
360346
else
361347
mkdir -p "$(dirname "$GIT_ROOT/$WORKTREE_PATH")"
362348

@@ -368,11 +354,17 @@ case "$SELECTED" in
368354
else
369355
git -C "$GIT_ROOT" worktree add "$WORKTREE_PATH" "$BRANCH_NAME"
370356
fi
371-
echo "Created worktree at: $(cd "$GIT_ROOT/$WORKTREE_PATH" && pwd)"
357+
FINAL_PATH="$(cd "$GIT_ROOT/$WORKTREE_PATH" && pwd)"
358+
echo "Created worktree at: $FINAL_PATH"
372359
fi
373360

374361
echo "Branch: $BRANCH_NAME"
375-
echo ""
376-
echo "WORKTREE_PATH=$(cd "$GIT_ROOT/$WORKTREE_PATH" && pwd)"
377362
;;
378363
esac
364+
365+
# Change to worktree directory and start new shell
366+
if [[ -n "${FINAL_PATH:-}" ]] && [[ -d "$FINAL_PATH" ]]; then
367+
echo ""
368+
echo "Changing to: $FINAL_PATH"
369+
cd "$FINAL_PATH" && exec "$SHELL"
370+
fi

0 commit comments

Comments
 (0)