Skip to content

Commit 3574816

Browse files
rjustogitster
authored andcommitted
completion: fix __git_complete_worktree_paths
Use __git to invoke "worktree list" in __git_complete_worktree_paths, to respect any "-C" and "--git-dir" options present on the command line. Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c2a3fd commit 3574816

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3571,7 +3571,7 @@ __git_complete_worktree_paths ()
35713571
# Generate completion reply from worktree list skipping the first
35723572
# entry: it's the path of the main worktree, which can't be moved,
35733573
# removed, locked, etc.
3574-
__gitcomp_nl "$(git worktree list --porcelain |
3574+
__gitcomp_nl "$(__git worktree list --porcelain |
35753575
sed -n -e '2,$ s/^worktree //p')"
35763576
}
35773577

t/t9902-completion.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,29 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
12631263
test_cmp expected out
12641264
'
12651265

1266+
test_expect_success '__git_complete_worktree_paths' '
1267+
test_when_finished "git worktree remove other_wt" &&
1268+
git worktree add --orphan other_wt &&
1269+
run_completion "git worktree remove " &&
1270+
grep other_wt out
1271+
'
1272+
1273+
test_expect_success '__git_complete_worktree_paths - not a git repository' '
1274+
(
1275+
cd non-repo &&
1276+
GIT_CEILING_DIRECTORIES="$ROOT" &&
1277+
export GIT_CEILING_DIRECTORIES &&
1278+
test_completion "git worktree remove " ""
1279+
)
1280+
'
1281+
1282+
test_expect_success '__git_complete_worktree_paths with -C' '
1283+
test_when_finished "git -C otherrepo worktree remove otherrepo_wt" &&
1284+
git -C otherrepo worktree add --orphan otherrepo_wt &&
1285+
run_completion "git -C otherrepo worktree remove " &&
1286+
grep otherrepo_wt out
1287+
'
1288+
12661289
test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '
12671290
test_completion "git switch " <<-\EOF
12681291
branch-in-other Z

0 commit comments

Comments
 (0)