wtcode 0.1.3__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wtcode
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Launch your favorite code tool in a git worktree
5
5
  Author-email: Jaeho Shin <netj@sparcs.org>
6
6
  License-Expression: MIT
@@ -59,7 +59,7 @@ wtcode [BRANCH] [CMD [CMD-ARGS...]]
59
59
  wtcode --exec CMD [CMD-ARGS...]
60
60
  ```
61
61
 
62
- - **`BRANCH`** -- Git branch or worktree name. If omitted and [fzf](https://github.com/junegunn/fzf) is available, interactively select one. Prefix with `:` to create a new branch (use `:::name` to avoid fzf matching the colons).
62
+ - **`BRANCH`** -- Git branch or worktree name. If omitted and [fzf](https://github.com/junegunn/fzf) is available, interactively select one. Surround with `:` to create a new branch (use `:::name` or `name:::` to avoid fzf matching the colons).
63
63
  - **`CMD`** -- Command to launch in the worktree. Defaults to `$WTCODE_CMD`, or the first available of: `claude`, `aider`, `codex`, `$SHELL`.
64
64
  - **`--exec`** -- Skip the branch argument; select interactively via fzf, then launch `CMD`.
65
65
  - **`--help`** / **`--version`** -- Show help or version info.
@@ -41,7 +41,7 @@ wtcode [BRANCH] [CMD [CMD-ARGS...]]
41
41
  wtcode --exec CMD [CMD-ARGS...]
42
42
  ```
43
43
 
44
- - **`BRANCH`** -- Git branch or worktree name. If omitted and [fzf](https://github.com/junegunn/fzf) is available, interactively select one. Prefix with `:` to create a new branch (use `:::name` to avoid fzf matching the colons).
44
+ - **`BRANCH`** -- Git branch or worktree name. If omitted and [fzf](https://github.com/junegunn/fzf) is available, interactively select one. Surround with `:` to create a new branch (use `:::name` or `name:::` to avoid fzf matching the colons).
45
45
  - **`CMD`** -- Command to launch in the worktree. Defaults to `$WTCODE_CMD`, or the first available of: `claude`, `aider`, `codex`, `$SHELL`.
46
46
  - **`--exec`** -- Skip the branch argument; select interactively via fzf, then launch `CMD`.
47
47
  - **`--help`** / **`--version`** -- Show help or version info.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "wtcode"
7
- version = "0.1.3"
7
+ version = "0.1.4"
8
8
  description = "Launch your favorite code tool in a git worktree"
9
9
  license = "MIT"
10
10
  readme = "README.md"
@@ -1,3 +1,3 @@
1
1
  """wtcode -- launch your favorite code tool in a git worktree."""
2
2
 
3
- __version__ = "0.1.3"
3
+ __version__ = "0.1.4"
@@ -16,7 +16,7 @@ ${WTCODE_DEBUG:+set -x}
16
16
  sed 's/^-//; s/-$//' # trim leading/trailing hyphens
17
17
  }
18
18
 
19
- WTCODE_VERSION=0.1.3
19
+ WTCODE_VERSION=0.1.4
20
20
  --version() { echo "wtcode $WTCODE_VERSION"; }
21
21
  --help() {
22
22
  cat <<USAGE
@@ -27,8 +27,9 @@ Usage: wtcode [BRANCH] [CMD [CMD-ARGS...]]
27
27
 
28
28
  BRANCH Git branch or worktree name to switch to.
29
29
  If omitted and fzf is available, interactively select one.
30
- Prefix with ':' to force creating a new branch
31
- (use multiple colons to avoid fzf matching, e.g., :::my-branch).
30
+ Surround with ':' to force creating a new branch
31
+ (use multiple colons to avoid fzf matching, e.g., :::my-branch
32
+ or my-branch:::).
32
33
 
33
34
  CMD Command to launch in the worktree (default: \$WTCODE_CMD,
34
35
  or first available of: ${WTCODE_CMDS_TO_TRY[*]}, \$SHELL).
@@ -127,13 +128,14 @@ WTCODE_CMDS_TO_TRY=(
127
128
  exit 1
128
129
  fi
129
130
 
130
- # check if branch name starts with ':' to force new branch creation
131
- # supports multiple colons (e.g., :::my-branch) to avoid fzf matching
131
+ # leading or trailing ':' forces new branch creation
132
+ # multiple colons (e.g., :::my-branch or my-branch:::) help avoid fzf matching
132
133
  local force_new_branch=false
133
- if [[ $branch_name == :* ]]; then
134
+ if [[ $branch_name == :* || $branch_name == *: ]]; then
134
135
  force_new_branch=true
135
136
  branch_name=${branch_name##+(:)}
136
- : ${branch_name:?non-empty branch name required after ':'}
137
+ branch_name=${branch_name%%+(:)}
138
+ : ${branch_name:?non-empty branch name required around ':'}
137
139
  fi
138
140
 
139
141
  # sanitize free-form text into a valid git branch name
@@ -155,6 +157,19 @@ WTCODE_CMDS_TO_TRY=(
155
157
  done
156
158
  fi
157
159
 
160
+ # if the branch is already checked out on a worktree, use that worktree
161
+ # regardless of its directory name — avoids "already checked out" failures
162
+ # when branches and worktree directories have drifted apart (e.g., after
163
+ # something like claude ran `git checkout` inside a worktree)
164
+ if ! $force_new_branch && [[ -z ${remote_branch-} ]]; then
165
+ local existing_worktree
166
+ existing_worktree=$(git for-each-ref --format='%(worktreepath)' "refs/heads/$branch_name" 2>/dev/null)
167
+ if [[ -n $existing_worktree ]]; then
168
+ --msg "branch '$branch_name' is checked out at: $existing_worktree"
169
+ cd "$existing_worktree"
170
+ return 0
171
+ fi
172
+ fi
158
173
 
159
174
  # 2. create or switch to the worktree
160
175
  cd "$(git rev-parse --show-toplevel)"
@@ -167,6 +182,24 @@ WTCODE_CMDS_TO_TRY=(
167
182
  )}
168
183
 
169
184
  local worktree_path="$GIT_WORKTREE_ROOT"/"$branch_name"
185
+
186
+ # if the default worktree directory exists but holds a different branch
187
+ # (e.g., something like claude swapped branches with `git checkout`), pick
188
+ # a fresh numbered suffix instead of stealing it. branch-is-checked-out
189
+ # case is already handled above, so we only need to check the default path.
190
+ if [[ -e "$worktree_path"/.git ]]; then
191
+ local existing_branch
192
+ existing_branch=$(git -C "$worktree_path" branch --show-current 2>/dev/null)
193
+ if [[ -n $existing_branch && $existing_branch != "$branch_name" ]]; then
194
+ --msg "$worktree_path holds branch '$existing_branch'; picking a new path for '$branch_name'"
195
+ local n=2
196
+ while [[ -e "$GIT_WORKTREE_ROOT/$branch_name-$n" ]]; do
197
+ n=$((n+1))
198
+ done
199
+ worktree_path="$GIT_WORKTREE_ROOT/$branch_name-$n"
200
+ fi
201
+ fi
202
+
170
203
  if [[ -e "$worktree_path"/.git ]]; then
171
204
  --msg "using existing worktree: $worktree_path"
172
205
  elif [[ -n ${remote_branch-} ]] && ! git rev-parse --verify "refs/heads/$branch_name" &>/dev/null; then
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wtcode
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Launch your favorite code tool in a git worktree
5
5
  Author-email: Jaeho Shin <netj@sparcs.org>
6
6
  License-Expression: MIT
@@ -59,7 +59,7 @@ wtcode [BRANCH] [CMD [CMD-ARGS...]]
59
59
  wtcode --exec CMD [CMD-ARGS...]
60
60
  ```
61
61
 
62
- - **`BRANCH`** -- Git branch or worktree name. If omitted and [fzf](https://github.com/junegunn/fzf) is available, interactively select one. Prefix with `:` to create a new branch (use `:::name` to avoid fzf matching the colons).
62
+ - **`BRANCH`** -- Git branch or worktree name. If omitted and [fzf](https://github.com/junegunn/fzf) is available, interactively select one. Surround with `:` to create a new branch (use `:::name` or `name:::` to avoid fzf matching the colons).
63
63
  - **`CMD`** -- Command to launch in the worktree. Defaults to `$WTCODE_CMD`, or the first available of: `claude`, `aider`, `codex`, `$SHELL`.
64
64
  - **`--exec`** -- Skip the branch argument; select interactively via fzf, then launch `CMD`.
65
65
  - **`--help`** / **`--version`** -- Show help or version info.
File without changes
File without changes
File without changes