Skip to content

Commit

Permalink
Merge branch 'rj/complete-worktree-paths-fix'
Browse files Browse the repository at this point in the history
The logic to complete the command line arguments to "git worktree"
subcommand (in contrib/) has been updated to correctly honor things
like "git -C dir" etc.

* rj/complete-worktree-paths-fix:
  completion: fix __git_complete_worktree_paths
  • Loading branch information
gitster committed Mar 14, 2024
2 parents 4310074 + 3574816 commit c5a7ee1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3629,7 +3629,7 @@ __git_complete_worktree_paths ()
# Generate completion reply from worktree list skipping the first
# entry: it's the path of the main worktree, which can't be moved,
# removed, locked, etc.
__gitcomp_nl "$(git worktree list --porcelain |
__gitcomp_nl "$(__git worktree list --porcelain |
sed -n -e '2,$ s/^worktree //p')"
}

Expand Down
23 changes: 23 additions & 0 deletions t/t9902-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,29 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
test_cmp expected out
'

test_expect_success '__git_complete_worktree_paths' '
test_when_finished "git worktree remove other_wt" &&
git worktree add --orphan other_wt &&
run_completion "git worktree remove " &&
grep other_wt out
'

test_expect_success '__git_complete_worktree_paths - not a git repository' '
(
cd non-repo &&
GIT_CEILING_DIRECTORIES="$ROOT" &&
export GIT_CEILING_DIRECTORIES &&
test_completion "git worktree remove " ""
)
'

test_expect_success '__git_complete_worktree_paths with -C' '
test_when_finished "git -C otherrepo worktree remove otherrepo_wt" &&
git -C otherrepo worktree add --orphan otherrepo_wt &&
run_completion "git -C otherrepo worktree remove " &&
grep otherrepo_wt out
'

test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '
test_completion "git switch " <<-\EOF
branch-in-other Z
Expand Down

0 comments on commit c5a7ee1

Please sign in to comment.