@@ -17,10 +17,6 @@ if [ -z "$repo_root" ]; then
1717fi
1818
1919branch_name=" $( git branch --show-current 2> /dev/null || true) "
20- if [ -z " $branch_name " ]; then
21- echo " cwrm must target a worktree on a branch." >&2
22- exit 1
23- fi
2420
2521git_dir=" $( git rev-parse --path-format=absolute --git-dir) "
2622common_dir=" $( git rev-parse --path-format=absolute --git-common-dir) "
@@ -41,10 +37,14 @@ if command -v tmux >/dev/null 2>&1 && tmux has-session -t "$session_name" 2>/dev
4137 tmux_session_exists=true
4238fi
4339
44- if $tmux_session_exists ; then
40+ if $tmux_session_exists && [ -n " $branch_name " ] ; then
4541 printf ' Delete tmux session "%s", worktree "%s", and branch "%s"? [y/N] ' " $session_name " " $repo_root " " $branch_name "
46- else
42+ elif $tmux_session_exists ; then
43+ printf ' Delete tmux session "%s" and worktree "%s"? [y/N] ' " $session_name " " $repo_root "
44+ elif [ -n " $branch_name " ]; then
4745 printf ' Delete worktree "%s" and branch "%s"? [y/N] ' " $repo_root " " $branch_name "
46+ else
47+ printf ' Delete worktree "%s"? [y/N] ' " $repo_root "
4848fi
4949read -r answer
5050
@@ -53,8 +53,10 @@ case "$answer" in
5353 git -C " $main_worktree_root " worktree remove " $repo_root "
5454 echo " Removed worktree: $repo_root "
5555
56- git -C " $main_worktree_root " branch -d " $branch_name "
57- echo " Deleted branch: $branch_name "
56+ if [ -n " $branch_name " ]; then
57+ git -C " $main_worktree_root " branch -d " $branch_name "
58+ echo " Deleted branch: $branch_name "
59+ fi
5860
5961 if $tmux_session_exists ; then
6062 tmux kill-session -t " $session_name "
0 commit comments