7 7 const WT_MAIN_BRANCH =
"wt.main-branch" 8 8 const WT_SOURCE_PATH =
"wt.source-path" 11 -def gitx [args: list<any>, cwd?: path] {
12 - let res =
if (
$cwd == null) {
10 +const DOT_GIT =
".git" 11 +const WT_ROOT_SUFFIX =
".wt" 12 +const DEFAULT_MAIN_BRANCH =
"main" 14 +const REF_HEADS =
"refs/heads/" 15 +const DIRTY_REFUSE =
"refuse" 16 +const DIRTY_COPY =
"copy" 17 +const DIRTY_MODES = [
"refuse" "copy"]
18 +const STATUS_PORCELAIN = [
"status" "--porcelain=v1"]
19 +const STAGED_PATCH =
"staged.patch" 20 +const UNSTAGED_PATCH =
"unstaged.patch" 22 +const LINE_WORKTREE =
"worktree " 23 +const LINE_HEAD =
"HEAD " 24 +const LINE_BRANCH =
"branch " 25 +const LINE_DETACHED =
"detached" 26 +const LINE_BARE =
"bare" 27 +const LINE_LOCKED =
"locked" 28 +const LINE_PRUNABLE =
"prunable" 31 +def git-complete [args: list<string>, cwd?: path] {
13 33 ^git ...
$args | complete
15 35 ^git -C
$cwd ...
$args | complete
40 +def git-failure [args: list<string>, stderr: string] {
41 + let msg = (
$stderr | str trim)
42 + if (
$msg | is-empty) {
43 + $
"git failed: git ($args | str join ' ')" 50 +def git-output [args: list<string>, cwd?: path] {
51 + let res =
if $cwd == null { git-complete
$args }
else { git-complete
$args $cwd }
18 53 if $res.exit_code !=
0 {
19 - let msg = (
$res.stderr | str trim)
20 - error make {msg: (
if (
$msg | is-empty) { $
"git failed: git ($args | str join ' ')" }
else {
$msg })}
54 + error make {msg: (git-failure
$args $res.stderr)}
23 57 $res.stdout | str trim
27 -def gitc [args: list<any>, cwd?: path] {
29 - ^git ...
$args | complete
31 - ^git -C
$cwd ...
$args | complete
61 +def gitx [args: list<string>, cwd?: path] {
62 + if $cwd == null { git-output
$args }
else { git-output
$args $cwd }
65 +def gitc [args: list<string>, cwd?: path] {
66 + if $cwd == null { git-complete
$args }
else { git-complete
$args $cwd }
69 +def git-dir-args [git_dir: path, args: list<string>] {
70 + [
"--git-dir" $git_dir] | append
$args 73 +def git-dir-output [git_dir: path, args: list<string>] {
74 + git-output (git-dir-args
$git_dir $args)
77 +def git-dir-complete [git_dir: path, args: list<string>] {
78 + git-complete (git-dir-args
$git_dir $args)
81 +def git-config [git_dir: path, key: string] {
82 + let res = (git-dir-complete
$git_dir [
"config" "--get" $key])
83 + if $res.exit_code ==
0 {
$res.stdout | str trim }
else { null }
86 +def git-config-bool [git_dir: path, key: string] {
87 + let res = (git-dir-complete
$git_dir [
"config" "--bool" "--get" $key])
88 + if $res.exit_code ==
0 {
$res.stdout | str trim }
else { null }
91 +def git-config-set [git_dir: path, key: string, value: string] {
92 + git-dir-output
$git_dir [
"config" $key $value] | ignore
43 103 def repo-name-from [
source: string] {
44 - let base = (
$source | path basename)
45 - $base | str replace --regex
'\.git$' '' 104 + $source | path basename | str replace --regex
'\.git$' '' 50 - let common = (gitx [
"rev-parse" "--path-format=absolute" "--git-common-dir"])
51 - let bare = (gitc [
"--git-dir" $common "config" "--bool" "--get" "core.bare"])
109 + let git_dir = (git-output [
"rev-parse" "--path-format=absolute" "--git-common-dir"])
53 - if ((
$bare.stdout | str trim) !=
"true") {
111 + if (git-config-bool
$git_dir "core.bare") !=
"true" {
54 112 error make {msg:
"not inside co/wt layout: git common dir is not bare"}
57 - let root = (
$common | path dirname)
58 - let repo_res = (gitc [
"--git-dir" $common "config" "--get" $WT_REPO_NAME])
59 - let repo =
if $repo_res.exit_code ==
0 {
60 - $repo_res.stdout | str trim
62 - $root | path basename | str replace --regex
'\.wt$' '' 115 + let root = (
$git_dir | path dirname)
116 + let repo = (git-config
$git_dir $WT_REPO_NAME | default (
$root | path basename | str replace --regex $
"($WT_ROOT_SUFFIX)$" ""))
117 + let main = (git-config
$git_dir $WT_MAIN_BRANCH | default
$DEFAULT_MAIN_BRANCH)
65 - let main_res = (gitc [
"--git-dir" $common "config" "--get" $WT_MAIN_BRANCH])
66 - let main =
if $main_res.exit_code ==
0 {
$main_res.stdout | str trim }
else {
"main" }
68 - {root:
$root, git_dir:
$common, repo:
$repo, main:
$main}
119 + {root:
$root, git_dir:
$git_dir, repo:
$repo, main:
$main}
72 123 def wt-path [branch: string] {
74 125 [
$l.root $
"($l.repo).(branch-slug $branch)"] | path join
128 +def empty-worktree-record [] {
129 + {path: null, head: null, branch: null, detached: false, bare: false, locked: false, lock_reason: null, prunable: false}
132 +def strip-prefix [line: string, prefix: string] {
133 + $line | str replace
$prefix "" 136 +def parse-lock-line [line: string] {
137 + let reason = (strip-prefix
$line $LINE_LOCKED | str trim)
138 + if (
$reason | is-empty) { null }
else {
$reason }
141 +def parse-worktree-line [rec: record, line: string] {
142 + if (
$line | str starts-with
$LINE_WORKTREE) {
143 + return (
$rec | upsert path (strip-prefix
$line $LINE_WORKTREE))
145 + if (
$line | str starts-with
$LINE_HEAD) {
146 + return (
$rec | upsert head (strip-prefix
$line $LINE_HEAD))
148 + if (
$line | str starts-with
$LINE_BRANCH) {
149 + let branch = (strip-prefix
$line $LINE_BRANCH | str replace
$REF_HEADS "")
150 + return (
$rec | upsert branch
$branch)
152 + if $line ==
$LINE_DETACHED {
153 + return (
$rec | upsert detached true)
155 + if $line ==
$LINE_BARE {
156 + return (
$rec | upsert bare true)
158 + if (
$line | str starts-with
$LINE_LOCKED) {
159 + return (
$rec | upsert locked true | upsert lock_reason (parse-lock-line
$line))
161 + if (
$line | str starts-with
$LINE_PRUNABLE) {
162 + return (
$rec | upsert prunable true)
168 +def parse-worktree-block [block: string] {
169 + $block | lines | reduce --fold (empty-worktree-record) {|line, rec| parse-worktree-line
$rec $line }
78 173 def parse-worktree-list [text: string] {
80 175 | split row
"\n\n" 81 176 |
where {|block| not ((
$block | str trim) | is-empty) }
83 - mut rec = {path: null, head: null, branch: null, detached: false, bare: false, locked: false, lock_reason: null, prunable: false}
85 - for line
in (
$block | lines) {
86 - if (
$line | str starts-with
"worktree ") {
87 - $rec = (
$rec | upsert path (
$line | str replace
"worktree " ""))
88 - }
else if (
$line | str starts-with
"HEAD ") {
89 - $rec = (
$rec | upsert head (
$line | str replace
"HEAD " ""))
90 - }
else if (
$line | str starts-with
"branch ") {
91 - let b = (
$line | str replace
"branch " "" | str replace
"refs/heads/" "")
92 - $rec = (
$rec | upsert branch
$b)
93 - }
else if $line ==
"detached" {
94 - $rec = (
$rec | upsert detached true)
95 - }
else if $line ==
"bare" {
96 - $rec = (
$rec | upsert bare true)
97 - }
else if (
$line | str starts-with
"locked") {
98 - let reason = (
$line | str replace
"locked" "" | str trim)
99 - $rec = (
$rec | upsert locked true | upsert lock_reason (
if (
$reason | is-empty) { null }
else {
$reason }))
100 - }
else if (
$line | str starts-with
"prunable") {
101 - $rec = (
$rec | upsert prunable true)
177 + |
each {|block| parse-worktree-block
$block }
110 181 def worktrees-basic [] {
112 - parse-worktree-list (gitx [
"--git-dir" $l.git_dir "worktree" "list" "--porcelain"])
183 + parse-worktree-list (git-dir-output
$l.git_dir [
"worktree" "list" "--porcelain"])
118 189 if (
$found == null) { wt-path
$branch }
else {
$found.path }
192 +def branch-exists [git_dir: path, branch: string] {
193 + (git-dir-complete
$git_dir [
"show-ref" "--verify" "--quiet" $
"($REF_HEADS)($branch)"]).exit_code ==
0 196 +def add-worktree [git_dir: path, path: path, branch: string, base: string] {
197 + let args =
if (branch-exists
$git_dir $branch) {
198 + [
"worktree" "add" $path $branch]
200 + [
"worktree" "add" "-b" $branch $path $base]
203 + git-dir-output
$git_dir $args | ignore
122 207 def create-worktree [branch: string, base: string] {
127 212 error make {msg: $
"path exists: ($path)"}
130 - let exists = ((gitc [
"--git-dir" $l.git_dir "show-ref" "--verify" "--quiet" $
"refs/heads/($branch)"]).exit_code ==
0)
133 - gitx [
"--git-dir" $l.git_dir "worktree" "add" $path $branch] | ignore
135 - gitx [
"--git-dir" $l.git_dir "worktree" "add" "-b" $branch $path $base] | ignore
215 + add-worktree
$l.git_dir $path $branch $base 142 220 def current-branch [] {
143 - let b = (gitx [
"rev-parse" "--abbrev-ref" "HEAD"])
144 - if $b ==
"HEAD" { error make {msg:
"detached HEAD is not supported"} }
221 + let branch = (git-output [
"rev-parse" "--abbrev-ref" $HEAD])
222 + if $branch ==
$HEAD { error make {msg:
"detached HEAD is not supported"} }
226 +def current-repo-top [] {
227 + try { git-output [
"rev-parse" "--show-toplevel"] | path expand } catch {
"" }
230 +def existing-main-or-root [layout: record] {
231 + let main_path = (path-
for-branch
$layout.main)
232 + if (
$main_path | path exists) {
$main_path }
else {
$layout.root }
235 +def --env cd-away-from-target [layout: record, target: path, branch: string] {
236 + if $target != (current-repo-top) { return }
238 + if $branch ==
$layout.main {
241 + cd (existing-main-or-root
$layout)
245 +def remove-worktree-args [target: path, force: bool] {
246 + if $force { [
"worktree" "remove" "--force" $target] }
else { [
"worktree" "remove" $target] }
249 +def delete-branch [git_dir: path, branch: string, force: bool] {
250 + let flag =
if $force {
"-D" }
else {
"-d" }
251 + git-dir-output
$git_dir [
"branch" $flag $branch] | ignore
149 255 def --env remove-worktree [branch: string, delete_branch: bool, force: bool] {
151 257 let target = (path-
for-branch
$branch | path expand)
152 - let cwd_top = (try { gitx [
"rev-parse" "--show-toplevel"] } catch {
"" } | path expand)
154 - if $target ==
$cwd_top {
155 - if $branch ==
$l.main {
158 - let main_path = (path-
for-branch
$l.main)
159 - if (
$main_path | path exists) { cd
$main_path }
else { cd
$l.root }
163 - let remove_args =
if $force {
164 - [
"--git-dir" $l.git_dir "worktree" "remove" "--force" $target]
166 - [
"--git-dir" $l.git_dir "worktree" "remove" $target]
168 - gitx
$remove_args | ignore
259 + cd-away-from-target
$l $target $branch 260 + git-dir-output
$l.git_dir (remove-worktree-args
$target $force) | ignore
170 262 if $delete_branch {
171 - let branch_flag =
if $force {
"-D" }
else {
"-d" }
172 - gitx [
"--git-dir" $l.git_dir "branch" $branch_flag $branch] | ignore
263 + delete-branch
$l.git_dir $branch $force 269 +def init-bare-layout [
source: string, git_dir: path, repo: string, main: string] {
270 + git-output [
"clone" "--bare" $source $git_dir] | ignore
271 + git-config-set
$git_dir $WT_REPO_NAME $repo 272 + git-config-set
$git_dir $WT_MAIN_BRANCH $main 275 +def remember-
source [git_dir: path,
source: path] {
276 + git-config-set
$git_dir $WT_SOURCE_PATH $source 279 +def choose-fresh-branch [git_dir: path, branch: any] {
280 + if ((
$branch == null) or (
$branch | is-empty)) {
281 + git-dir-output
$git_dir [
"symbolic-ref" "--short" $HEAD]
287 +def selected-branch [branch: any] {
288 + if ((
$branch == null) or (
$branch | is-empty)) { current-branch }
else {
$branch }
179 292 def --env co-fresh [
source: string, name?: string, branch?: string, dir?: path] {
180 293 let repo =
if (
$name == null) { repo-name-from
$source }
else {
$name }
181 294 let parent =
if (
$dir == null) {
"." }
else {
$dir }
182 295 let root = ([
$parent $repo] | path join | path expand)
183 - let git_dir = ([
$root ".git"] | path join)
296 + let git_dir = ([
$root $DOT_GIT] | path join)
185 298 if (
$root | path exists) {
186 299 error make {msg: $
"target exists: ($root)"}
190 - gitx [
"clone" "--bare" $source $git_dir] | ignore
303 + git-output [
"clone" "--bare" $source $git_dir] | ignore
192 - let chosen_branch =
if ((
$branch == null) or (
$branch | is-empty)) {
193 - gitx [
"--git-dir" $git_dir "symbolic-ref" "--short" "HEAD"]
198 - gitx [
"--git-dir" $git_dir "config" $WT_REPO_NAME $repo] | ignore
199 - gitx [
"--git-dir" $git_dir "config" $WT_MAIN_BRANCH $chosen_branch] | ignore
305 + let chosen_branch = (choose-fresh-branch
$git_dir $branch)
306 + git-config-set
$git_dir $WT_REPO_NAME $repo 307 + git-config-set
$git_dir $WT_MAIN_BRANCH $chosen_branch 201 309 let worktree = ([
$root $
"($repo).(branch-slug $chosen_branch)"] | path join)
202 - gitx [
"--git-dir" $git_dir "worktree" "add" $worktree $chosen_branch] | ignore
310 + git-dir-output
$git_dir [
"worktree" "add" $worktree $chosen_branch] | ignore
205 313 {root:
$root, worktree:
$worktree, branch:
$chosen_branch}
209 -def --env co-current [name?: string, branch?: string, plan: bool = false, dirty: string =
"refuse"] {
210 - let src = (gitx [
"rev-parse" "--show-toplevel"] | path expand)
211 - let src_name = (
$src | path basename)
212 - let repo =
if (
$name == null) {
$src_name }
else {
$name }
213 - let parent = (
$src | path dirname)
214 - let root = ([
$parent $
"($repo).wt"] | path join | path expand)
215 - let git_dir = ([
$root ".git"] | path join)
216 - let current = (current-branch)
217 - let chosen_branch =
if ((
$branch == null) or (
$branch | is-empty)) {
$current }
else {
$branch }
218 - let target = ([
$root $
"($repo).(branch-slug $chosen_branch)"] | path join)
219 - let status_before = (gitx [
"status" "--porcelain=v1"]
$src)
220 - let is_dirty = (not (
$status_before | is-empty))
221 - let stash_res = (gitc [
"stash" "list"]
$src)
222 - let stash_count =
if $stash_res.exit_code ==
0 { (
$stash_res.stdout | lines | length) }
else {
0 }
316 +def status-porcelain [cwd: path] {
317 + git-output
$STATUS_PORCELAIN $cwd 224 - if not (
$dirty in [
"refuse" "copy"]) {
225 - error make {msg:
"--dirty must be one of: refuse, copy"}
320 +def stash-count [cwd: path] {
321 + let res = (git-complete [
"stash" "list"]
$cwd)
322 + if $res.exit_code ==
0 {
$res.stdout | lines | length }
else {
0 }
325 +def assert-dirty-mode [dirty: string] {
326 + if not (
$dirty in $DIRTY_MODES) {
327 + error make {msg: $
"--dirty must be one of: ($DIRTY_MODES | str join ', ')"}
331 +def migration-plan [dirty_mode: string, name: any, branch: any] {
332 + assert-dirty-mode
$dirty_mode 334 + let src = (git-output [
"rev-parse" "--show-toplevel"] | path expand)
335 + let repo =
if (
$name == null) {
$src | path basename }
else {
$name }
336 + let parent = (
$src | path dirname)
337 + let root = ([
$parent $
"($repo)($WT_ROOT_SUFFIX)"] | path join | path expand)
338 + let git_dir = ([
$root $DOT_GIT] | path join)
339 + let chosen_branch = (selected-branch
$branch)
340 + let target = ([
$root $
"($repo).(branch-slug $chosen_branch)"] | path join)
341 + let status_before = (status-porcelain
$src)
342 + let is_dirty = (not (
$status_before | is-empty))
229 345 mode:
"current-checkout" 231 347 target_root:
$root 235 351 branch:
$chosen_branch 238 - stashes:
$stash_count 353 + dirty_mode:
$dirty_mode 354 + stashes: (stash-count
$src)
239 355 destructive: false
356 + status_before:
$status_before 360 +def public-migration [plan: record] {
361 + $plan | reject status_before
364 +def assert-migration-ready [plan: record] {
365 + if (
$plan.target_root | path exists) {
366 + error make {msg: $
"target exists: ($plan.target_root)"}
242 - if $plan { return
$migration }
244 - if (
$root | path exists) {
245 - error make {msg: $
"target exists: ($root)"}
248 - if $is_dirty and
$dirty ==
"refuse" {
369 + if $plan.dirty and
$plan.dirty_mode ==
$DIRTY_REFUSE {
249 370 error make {msg:
"working tree has changes; rerun with `co . --dirty copy` or commit/stash first"}
252 - if $stash_count >
0 {
253 - print -e $
"warning: ($stash_count) stash(es) remain only in original checkout: ($src)" 374 +def warn-stashes [plan: record] {
375 + if $plan.stashes >
0 {
376 + print -e $
"warning: ($plan.stashes) stash(es) remain only in original checkout: ($plan.source)" 380 +def patch-paths [tmp: path] {
381 + {staged: ([
$tmp $STAGED_PATCH] | path join), unstaged: ([
$tmp $UNSTAGED_PATCH] | path join)}
384 +def write-dirty-patches [
source: path, tmp: path] {
385 + let patches = (patch-paths
$tmp)
386 + ^git -C
$source diff --binary --cached | save --force
$patches.staged 387 + ^git -C
$source diff --binary | save --force
$patches.unstaged 391 +def patch-has-data [patch: path] {
392 + not ((open --raw
$patch) | is-empty)
395 +def apply-patch [target: path, args: list<string>, patch: path] {
396 + if (patch-has-data
$patch) {
397 + git-output ([
"apply"] | append
$args | append
$patch)
$target | ignore
401 +def apply-dirty-patches [target: path, patches: record] {
402 + apply-patch
$target [
"--index"]
$patches.staged 403 + apply-patch
$target []
$patches.unstaged 406 +def assert-external-ok [name: string, res: record] {
407 + if $res.exit_code !=
0 {
408 + let msg = (
$res.stderr | str trim)
409 + error make {msg: (
if (
$msg | is-empty) { $
"($name) failed" }
else {
$msg })}
413 +def copy-untracked [
source: path, target: path] {
414 + git-output [
"status"]
$source | ignore
416 + if (which rsync | is-not-empty) {
417 + assert-external-ok
"rsync" (^rsync -a --ignore-existing --exclude .git $
"($source)/" $
"($target)/" | complete)
419 + assert-external-ok
"cp" (^cp -a -n $
"($source)/." $target | complete)
423 +def copy-dirty-state [plan: record, patches: record] {
424 + apply-dirty-patches
$plan.target_worktree $patches 425 + copy-untracked
$plan.source $plan.target_worktree 427 + let status_after = (status-porcelain
$plan.target_worktree)
428 + if $plan.status_before !=
$status_after {
429 + error make {msg: $
"dirty-copy verification failed; original untouched at ($plan.source), target left for inspection at ($plan.target_root)"}
433 +def create-migration-layout [plan: record] {
434 + mkdir
$plan.target_root 435 + init-bare-layout
$plan.source $plan.target_git_dir $plan.repo $plan.branch 436 + remember-
source $plan.target_git_dir $plan.source 437 + git-dir-output
$plan.target_git_dir [
"worktree" "add" $plan.target_worktree $plan.branch] | ignore
441 +def --env co-current [name?: string, branch?: string, plan: bool = false, dirty: string =
$DIRTY_REFUSE] {
442 + let migration = (migration-plan
$dirty $name $branch)
443 + if $plan { return (public-migration
$migration) }
445 + assert-migration-ready
$migration 446 + warn-stashes
$migration 448 + let tmp =
if $migration.dirty { mktemp -d }
else { null }
451 + let patches =
if $migration.dirty { write-dirty-patches
$migration.source $tmp }
else { null }
452 + create-migration-layout
$migration 453 + if $migration.dirty {
454 + copy-dirty-state
$migration $patches 456 + if $tmp != null { rm -rf
$tmp }
458 + if $tmp != null { rm -rf
$tmp }
459 + error make {msg:
$err.msg}
256 - let tmp = (mktemp -d)
257 - let staged_patch = ([
$tmp "staged.patch"] | path join)
258 - let unstaged_patch = ([
$tmp "unstaged.patch"] | path join)
261 - ^git -C
$src diff --binary --cached | save --force
$staged_patch 262 - ^git -C
$src diff --binary | save --force
$unstaged_patch 266 - gitx [
"clone" "--bare" $src $git_dir] | ignore
267 - gitx [
"--git-dir" $git_dir "config" $WT_REPO_NAME $repo] | ignore
268 - gitx [
"--git-dir" $git_dir "config" $WT_MAIN_BRANCH $chosen_branch] | ignore
269 - gitx [
"--git-dir" $git_dir "config" $WT_SOURCE_PATH $src] | ignore
270 - gitx [
"--git-dir" $git_dir "worktree" "add" $target $chosen_branch] | ignore
273 - if (not ((open --raw
$staged_patch) | is-empty)) {
274 - gitx [
"apply" "--index" $staged_patch]
$target | ignore
276 - if (not ((open --raw
$unstaged_patch) | is-empty)) {
277 - gitx [
"apply" $unstaged_patch]
$target | ignore
280 - let rsync = (which rsync | length) >
0 282 - gitx [
"-C" $src "status"] | ignore
283 - ^rsync -a --ignore-existing --exclude .git $
"($src)/" $
"($target)/" | complete | ignore
285 - ^cp -a -n $
"($src)/." $target | complete | ignore
288 - let status_after = (gitx [
"status" "--porcelain=v1"]
$target)
289 - if $status_before !=
$status_after {
290 - error make {msg: $
"dirty-copy verification failed; original untouched at ($src), target left for inspection at ($root)"}
462 + cd
$migration.target_worktree 463 + public-migration
$migration 301 467 export def --env co [
302 - source: string =
"." 468 + source: string =
"." 304 470 --branch (-b): string =
"" 305 - --dir (-d): path =
"." 307 - --dirty: string =
"refuse" 471 + --dir (-d): path =
"." 473 + --dirty: string =
$DIRTY_REFUSE 309 475 if $source ==
"." {
310 476 co-current
$name $branch $plan $dirty 312 478 if $plan { error make {msg:
"--plan only applies to `co .`"} }
313 - if $dirty !=
"refuse" { error make {msg:
"--dirty only applies to `co .`"} }
479 + if $dirty !=
$DIRTY_REFUSE { error make {msg:
"--dirty only applies to `co .`"} }
314 480 co-fresh
$source $name $branch $dir 322 488 export def "wt repo" [] { (layout).repo }
323 489 export def "wt path" [branch: string] { wt-path
$branch }
491 +def worktree-dirty [row: record] {
492 + if ((
$row.path | path exists) and (not
$row.bare) and (
$row.branch != null)) {
493 + not ((status-porcelain
$row.path) | is-empty)
325 499 export def "wt ls" [] {
326 - let cwd_top = (try { gitx [
"rev-parse" "--show-toplevel"] } catch {
"" } | path expand)
500 + let cwd_top = (current-repo-top)
328 502 worktrees-basic |
where bare == false |
each {|row|
329 - let p = (
$row.path | path expand)
330 - let dirty =
if ((
$p | path exists) and (not
$row.bare) and (
$row.branch != null)) {
331 - not ((gitx [
"status" "--porcelain=v1"]
$p) | is-empty)
503 + let path = (
$row.path | path expand)
337 - | upsert current (
$p ==
$cwd_top)
338 - | upsert dirty
$dirty 505 + | upsert current (
$path ==
$cwd_top)
506 + | upsert dirty (worktree-dirty
$row)
342 510 export def --env
"wt new" [
344 - --base (-b): string =
"HEAD" 512 + --base (-b): string =
$HEAD 347 - let p = (create-worktree
$branch $base)
348 - if $switch { cd
$p }
515 + let path = (create-worktree
$branch $base)
516 + if $switch { cd
$path }
352 520 export def --env
"wt go" [
355 - --base (-b): string =
"HEAD" 523 + --base (-b): string =
$HEAD 357 - let p = (path-
for-branch
$branch)
358 - if (not (
$p | path exists)) {
360 - create-worktree
$branch $base | ignore
525 + let path = (path-
for-branch
$branch)
526 + if not (
$path | path exists) {
362 528 error make {msg: $
"no worktree for branch `($branch)`; rerun with --create"}
530 + create-worktree
$branch $base | ignore
369 536 export def --env
"wt rm" [
386 553 export def "wt prune" [] {
388 - gitx [
"--git-dir" $l.git_dir "worktree" "prune"] | ignore
554 + git-dir-output (layout).git_dir [
"worktree" "prune"] | ignore
391 557 export def "wt repair" [] {
393 - gitx [
"--git-dir" $l.git_dir "worktree" "repair"] | ignore
558 + git-dir-output (layout).git_dir [
"worktree" "repair"] | ignore
397 -export def --env
"wt add" [branch: string, --base (-b): string =
"HEAD", --switch (-s)] {
562 +export def --env
"wt add" [branch: string, --base (-b): string =
$HEAD, --switch (-s)] {
398 563 wt new
$branch --base
$base --switch=
$switch 403 568 export def "wt lock" [branch?: string, reason?: string] {
404 569 let b =
if (
$branch == null) { current-branch }
else {
$branch }
405 - let p = (path-
for-branch
$b)
570 + let path = (path-
for-branch
$b)
407 - if (
$reason == null) {
408 - gitx [
"--git-dir" $l.git_dir "worktree" "lock" $p] | ignore
410 - gitx [
"--git-dir" $l.git_dir "worktree" "lock" "--reason" $reason $p] | ignore
572 + let args =
if (
$reason == null) { [
"worktree" "lock" $path] }
else { [
"worktree" "lock" "--reason" $reason $path] }
573 + git-dir-output
$l.git_dir $args | ignore
414 576 export def "wt unlock" [branch?: string] {
415 577 let b =
if (
$branch == null) { current-branch }
else {
$branch }
416 - let p = (path-
for-branch
$b)
418 - gitx [
"--git-dir" $l.git_dir "worktree" "unlock" $p] | ignore
578 + git-dir-output (layout).git_dir [
"worktree" "unlock" (path-
for-branch
$b)] | ignore
421 581 export def "wt move" [branch: string, dest: path] {
422 - let p = (path-
for-branch
$branch)
424 - gitx [
"--git-dir" $l.git_dir "worktree" "move" $p $dest] | ignore
582 + git-dir-output (layout).git_dir [
"worktree" "move" (path-
for-branch
$branch)
$dest] | ignore