Skip to content

Commit 4adeaed

Browse files
committed
fix: using command in worktree context
1 parent 1cb9857 commit 4adeaed

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/commands/using.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,35 @@
3232
}
3333

3434
$using = slic_target();
35-
$target_path = slic_plugins_dir( $using );
35+
$is_worktree = slic_stacks_is_worktree( $stack_id );
36+
$worktree_info = null;
37+
38+
if ( $is_worktree ) {
39+
$stack_state = slic_stacks_get( $stack_id );
40+
if ( $stack_state ) {
41+
$worktree_info = [
42+
'target' => $stack_state['worktree_target'] ?? null,
43+
'branch' => $stack_state['worktree_branch'] ?? null,
44+
'full_path' => $stack_state['worktree_full_path'] ?? null,
45+
];
46+
}
47+
}
48+
49+
$target_path = $is_worktree && ! empty( $worktree_info['full_path'] )
50+
? $worktree_info['full_path']
51+
: slic_plugins_dir( $using );
52+
3653
if ( empty( $using ) ) {
3754
echo magenta( "Currently not using any target, commands requiring a target will fail." . PHP_EOL );
3855
echo light_cyan( "Stack: {$stack_id}" . PHP_EOL );
3956
return;
4057
}
4158

42-
echo light_cyan( "Using {$using}" . PHP_EOL );
59+
if ( $is_worktree && ! empty( $worktree_info['target'] ) && ! empty( $worktree_info['branch'] ) ) {
60+
echo light_cyan( "Using {$using} ({$worktree_info['target']} worktree for {$worktree_info['branch']})" . PHP_EOL );
61+
} else {
62+
echo light_cyan( "Using {$using}" . PHP_EOL );
63+
}
4364
echo light_cyan( "Stack: {$stack_id}" . PHP_EOL );
4465

4566
// Show stack ports - ensure they're up-to-date from Docker
@@ -60,7 +81,13 @@
6081
}
6182

6283
if ( $target_path === getcwd() ) {
63-
echo light_cyan( PHP_EOL . "The directory you are in is the current use target." );
84+
$message = $is_worktree
85+
? "The directory you are in is the current use target of the worktree."
86+
: "The directory you are in is the current use target.";
87+
echo light_cyan( PHP_EOL . $message );
6488
} else {
65-
echo yellow( PHP_EOL . "The directory you are in is not the current use target." );
89+
$message = $is_worktree
90+
? "The directory you are in is not the current use target of the worktree."
91+
: "The directory you are in is not the current use target.";
92+
echo yellow( PHP_EOL . $message );
6693
}

0 commit comments

Comments
 (0)