Skip to content

Commit 194212b

Browse files
committed
refactor: enhance command context handling with shellcheck directives
- Added shellcheck disable directives in various command scripts to suppress specific warnings related to variable usage and sourcing. - Improved clarity and maintainability of command context management by ensuring proper variable handling across multiple command files. - Streamlined the sourcing of command handlers in `bin/gtr` for better organization and execution flow.
1 parent e56424d commit 194212b

11 files changed

Lines changed: 22 additions & 2 deletions

File tree

bin/gtr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ resolve_script_dir() {
3232

3333
# Source command handlers
3434
for _cmd_file in "$GTR_DIR"/lib/commands/*.sh; do
35+
# shellcheck disable=SC1090
3536
. "$_cmd_file"
3637
done
3738
unset _cmd_file

lib/adapters.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ editor_open() {
133133

134134
# Use workspace file if provided and exists
135135
if [ -n "$workspace" ] && [ -f "$workspace" ]; then
136+
# shellcheck disable=SC2034
136137
target="$workspace"
137138
fi
138139

lib/commands/ai.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ cmd_ai() {
5252
load_ai_adapter "$ai_tool" || exit 1
5353

5454
resolve_repo_context || exit 1
55+
# shellcheck disable=SC2154
5556
local repo_root="$_ctx_repo_root" base_dir="$_ctx_base_dir" prefix="$_ctx_prefix"
5657

5758
# Resolve target branch
5859
local worktree_path branch
5960
resolve_worktree "$identifier" "$repo_root" "$base_dir" "$prefix" || exit 1
61+
# shellcheck disable=SC2154
6062
worktree_path="$_ctx_worktree_path" branch="$_ctx_branch"
6163

6264
log_step "Starting $ai_tool for: $branch"

lib/commands/clean.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ cmd_clean() {
149149
fi
150150

151151
resolve_repo_context || exit 1
152+
# shellcheck disable=SC2154
152153
local repo_root="$_ctx_repo_root" base_dir="$_ctx_base_dir" prefix="$_ctx_prefix"
153154

154155
if [ ! -d "$base_dir" ]; then

lib/commands/copy.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ cmd_copy() {
5555

5656
# Get repo context
5757
resolve_repo_context || exit 1
58+
# shellcheck disable=SC2154
5859
local repo_root="$_ctx_repo_root" base_dir="$_ctx_base_dir" prefix="$_ctx_prefix"
5960

6061
# Resolve source path
6162
local src_path
6263
resolve_worktree "$source" "$repo_root" "$base_dir" "$prefix" || exit 1
64+
# shellcheck disable=SC2154
6365
src_path="$_ctx_worktree_path"
6466

6567
# Get patterns (flag > config)
@@ -101,6 +103,7 @@ cmd_copy() {
101103
for target_id in $targets; do
102104
local dst_path dst_branch
103105
resolve_worktree "$target_id" "$repo_root" "$base_dir" "$prefix" || continue
106+
# shellcheck disable=SC2154
104107
dst_path="$_ctx_worktree_path" dst_branch="$_ctx_branch"
105108

106109
# Skip if source == destination

lib/commands/create.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ _post_create_next_steps() {
5151
local resolve_result
5252
if resolve_result=$(resolve_target "$folder_name" "$repo_root" "$base_dir" "$prefix" 2>/dev/null); then
5353
unpack_target "$resolve_result"
54+
# shellcheck disable=SC2154
5455
if [ "$_ctx_is_main" = "1" ]; then
5556
# Collision: folder name matches current branch, use branch name instead
5657
next_steps_id="$branch_name"
@@ -242,6 +243,7 @@ cmd_create() {
242243

243244
# Get repo info
244245
resolve_repo_context || exit 1
246+
# shellcheck disable=SC2154
245247
local repo_root="$_ctx_repo_root" base_dir="$_ctx_base_dir" prefix="$_ctx_prefix"
246248

247249
# Get branch name if not provided

lib/commands/editor.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ cmd_editor() {
3636
fi
3737

3838
resolve_repo_context || exit 1
39+
# shellcheck disable=SC2154
3940
local repo_root="$_ctx_repo_root" base_dir="$_ctx_base_dir" prefix="$_ctx_prefix"
4041

4142
# Resolve target branch
42-
local worktree_path branch
43+
local worktree_path
4344
resolve_worktree "$identifier" "$repo_root" "$base_dir" "$prefix" || exit 1
44-
worktree_path="$_ctx_worktree_path" branch="$_ctx_branch"
45+
# shellcheck disable=SC2154
46+
worktree_path="$_ctx_worktree_path"
4547

4648
if [ "$editor" = "none" ]; then
4749
open_in_gui "$worktree_path"

lib/commands/go.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ cmd_go() {
99

1010
local identifier="$1"
1111
resolve_repo_context || exit 1
12+
# shellcheck disable=SC2154
1213
local repo_root="$_ctx_repo_root" base_dir="$_ctx_base_dir" prefix="$_ctx_prefix"
1314

1415
# Resolve target branch
1516
local is_main worktree_path branch
1617
resolve_worktree "$identifier" "$repo_root" "$base_dir" "$prefix" || exit 1
18+
# shellcheck disable=SC2154
1719
is_main="$_ctx_is_main" worktree_path="$_ctx_worktree_path" branch="$_ctx_branch"
1820

1921
# Human messages to stderr so stdout can be used in command substitution

lib/commands/remove.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ cmd_remove() {
3939
fi
4040

4141
resolve_repo_context || exit 1
42+
# shellcheck disable=SC2154
4243
local repo_root="$_ctx_repo_root" base_dir="$_ctx_base_dir" prefix="$_ctx_prefix"
4344

4445
for identifier in $identifiers; do
4546
# Resolve target branch
4647
local is_main worktree_path branch_name
4748
resolve_worktree "$identifier" "$repo_root" "$base_dir" "$prefix" || continue
49+
# shellcheck disable=SC2154
4850
is_main="$_ctx_is_main" worktree_path="$_ctx_worktree_path" branch_name="$_ctx_branch"
4951

5052
# Cannot remove main repository

lib/commands/rename.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ cmd_rename() {
4040
fi
4141

4242
resolve_repo_context || exit 1
43+
# shellcheck disable=SC2154
4344
local repo_root="$_ctx_repo_root" base_dir="$_ctx_base_dir" prefix="$_ctx_prefix"
4445

4546
# Resolve old worktree
4647
local is_main old_path old_branch
4748
resolve_worktree "$old_identifier" "$repo_root" "$base_dir" "$prefix" || exit 1
49+
# shellcheck disable=SC2154
4850
is_main="$_ctx_is_main" old_path="$_ctx_worktree_path" old_branch="$_ctx_branch"
4951

5052
# Cannot rename main repository

0 commit comments

Comments
 (0)