-
Notifications
You must be signed in to change notification settings - Fork 609
Expand file tree
/
Copy pathworktree-delete.sh
More file actions
executable file
·41 lines (33 loc) · 1.1 KB
/
worktree-delete.sh
File metadata and controls
executable file
·41 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <name>" >&2
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
for WORKTREE_NAME in "$@"; do
WORKTREE_DIR="$REPO_ROOT/.worktrees/$WORKTREE_NAME"
if [[ ! -d "$WORKTREE_DIR" ]]; then
echo "Warning: worktree directory not found: $WORKTREE_DIR — skipping" >&2
continue
fi
# Capture branch name before removal
BRANCH_NAME="$(git -C "$WORKTREE_DIR" branch --show-current 2>/dev/null || true)"
echo "Removing worktree '$WORKTREE_NAME'..."
git -C "$REPO_ROOT" worktree remove "$WORKTREE_DIR"
echo " Removed: $WORKTREE_DIR"
if [[ -n "$BRANCH_NAME" ]]; then
if [[ -t 0 ]]; then
read -r -p " Delete branch '$BRANCH_NAME'? [y/N] " REPLY
echo
else
REPLY="n"
fi
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
git -C "$REPO_ROOT" branch -d "$BRANCH_NAME"
echo " Deleted branch: $BRANCH_NAME"
fi
fi
echo " Done."
done