Skip to content

Commit 1a4b73a

Browse files
committed
refactor: remove unused functions and improve command clarity
- Removed the unused helper function `__fish_git_gtr_config_is_write` from `completions/git-gtr.fish` and `scripts/generate-completions.sh` to streamline the code. - Deleted the `copy_file` function from `lib/copy.sh` as it was redundant and not utilized in the current codebase. - Eliminated the `list_worktrees` function from `lib/core.sh` to enhance clarity and maintainability of the code.
1 parent 2fcf302 commit 1a4b73a

14 files changed

Lines changed: 32 additions & 63 deletions

File tree

completions/git-gtr.fish

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,6 @@ function __fish_git_gtr_config_is_read
117117
return 1
118118
end
119119

120-
# Helper to check if config action is a write operation (set, add, unset)
121-
function __fish_git_gtr_config_is_write
122-
set -l cmd (commandline -opc)
123-
for i in $cmd
124-
if test "$i" = "set" -o "$i" = "add" -o "$i" = "unset"
125-
return 0
126-
end
127-
end
128-
return 1
129-
end
130-
131120
# Scope flags for config command
132121
# --local and --global available for all operations
133122
complete -f -c git -n '__fish_git_gtr_using_command config' -l local -d 'Use local git config'

lib/commands/ai.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2154
32

43
# AI command
4+
# shellcheck disable=SC2154 # _arg_* _pa_* set by parse_args, _ctx_* set by resolve_*
55
cmd_ai() {
66
parse_args "--ai: value" "$@"
77

lib/commands/clean.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2154
32

43
# Clean command (remove prunable worktrees)
54
# Remove worktrees whose PRs/MRs are merged (handles squash merges)
@@ -83,17 +82,28 @@ _clean_merged() {
8382
removed=$((removed + 1))
8483
elif [ "$yes_mode" -eq 1 ] || prompt_yes_no "Remove worktree and delete branch '$branch'?"; then
8584
log_step "Removing worktree: $branch"
86-
local remove_output
87-
if remove_output=$(git worktree remove "$dir" 2>&1); then
88-
# Also delete the local branch
85+
86+
# Run pre-remove hooks (skip worktree on failure)
87+
if ! run_hooks_in preRemove "$dir" \
88+
REPO_ROOT="$repo_root" \
89+
WORKTREE_PATH="$dir" \
90+
BRANCH="$branch"; then
91+
log_warn "Pre-remove hook failed for $branch, skipping"
92+
skipped=$((skipped + 1))
93+
continue
94+
fi
95+
96+
if remove_worktree "$dir" 0; then
97+
# Delete the local branch (safe: already merged)
8998
git branch -d "$branch" 2>/dev/null || git branch -D "$branch" 2>/dev/null || true
90-
log_info "Removed: $branch"
9199
removed=$((removed + 1))
92-
else
93-
if [ -n "$remove_output" ]; then
94-
log_error "Failed to remove worktree: $remove_output"
95-
else
96-
log_error "Failed to remove worktree: $branch"
100+
101+
# Run post-remove hooks (worktree already removed, don't abort)
102+
if ! run_hooks postRemove \
103+
REPO_ROOT="$repo_root" \
104+
WORKTREE_PATH="$dir" \
105+
BRANCH="$branch"; then
106+
log_warn "Post-remove hook failed for $branch"
97107
fi
98108
fi
99109
else
@@ -112,6 +122,7 @@ _clean_merged() {
112122
fi
113123
}
114124

125+
# shellcheck disable=SC2154 # _arg_* set by parse_args, _ctx_* set by resolve_*
115126
cmd_clean() {
116127
local _spec
117128
_spec="--merged

lib/commands/copy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2154
32

43
# Copy command (copy files between worktrees)
4+
# shellcheck disable=SC2154 # _arg_* _pa_* set by parse_args, _ctx_* set by resolve_*/merge_copy_patterns
55
cmd_copy() {
66
local _spec
77
_spec="--from: value

lib/commands/create.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2154
32

43
# Create command
54
# Copy files and directories to newly created worktree
65
# Usage: _post_create_copy repo_root worktree_path
6+
# shellcheck disable=SC2154 # _ctx_copy_* set by merge_copy_patterns
77
_post_create_copy() {
88
local repo_root="$1"
99
local worktree_path="$2"
@@ -30,6 +30,7 @@ _post_create_copy() {
3030

3131
# Show next steps after worktree creation (resolves collision for --folder overrides)
3232
# Usage: _post_create_next_steps branch_name folder_name folder_override repo_root base_dir prefix
33+
# shellcheck disable=SC2154 # _ctx_is_main set by resolve_target/unpack_target
3334
_post_create_next_steps() {
3435
local branch_name="$1" folder_name="$2" folder_override="$3"
3536
local repo_root="$4" base_dir="$5" prefix="$6"
@@ -83,6 +84,7 @@ _create_resolve_from_ref() {
8384

8485
printf "%s" "$from_ref"
8586
}
87+
# shellcheck disable=SC2154 # _arg_* _pa_* set by parse_args, _ctx_* set by resolve_*
8688
cmd_create() {
8789
local _spec
8890
_spec="--from: value

lib/commands/editor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2154
32

43
# Editor command
4+
# shellcheck disable=SC2154 # _arg_* _pa_* set by parse_args, _ctx_* set by resolve_*
55
cmd_editor() {
66
parse_args "--editor: value" "$@"
77

lib/commands/go.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2154
32

43
# Go command (navigate to worktree - prints path for shell integration)
4+
# shellcheck disable=SC2154 # _pa_* set by parse_args, _ctx_* set by resolve_*
55
cmd_go() {
66
parse_args "" "$@"
77

lib/commands/list.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2154
32

43
# List command
4+
# shellcheck disable=SC2154 # _arg_* set by parse_args, _ctx_* set by resolve_*
55
cmd_list() {
66
parse_args "--porcelain" "$@"
77

lib/commands/remove.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2154
32

43
# Remove command
4+
# shellcheck disable=SC2154 # _arg_* _pa_* set by parse_args, _ctx_* set by resolve_*
55
cmd_remove() {
66
local _spec
77
_spec="--delete-branch

lib/commands/rename.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
# shellcheck disable=SC2154
32

43
# Rename command (rename worktree and branch)
4+
# shellcheck disable=SC2154 # _arg_* _pa_* set by parse_args, _ctx_* set by resolve_*
55
cmd_rename() {
66
local _spec
77
_spec="--force

0 commit comments

Comments
 (0)