When __git_func_wrap was fixed to set correctly __git_cmd_idx in cea232194d (completion: bash: fix late declaration of __git_cmd_idx, 2021-06-18) no test was added, therefore we could hit the same bug in the future. To ensure that doesn't happen add a test which adds an alias for 'git add' with __git_complete, and then pretend the user typed this alias. To make sure __git_cmd_idx is correct we add the --update option to ensure the result of __git_find_on_cmdline (which uses __git_cmd_idx) is correct. When __git_cmd_idx isn't correct __git_find_on_cmdline fails, and therefore the --update option isn't interpreted correctly. Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx> --- t/t9902-completion.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 43de868b80..8cc30448c7 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2659,4 +2659,13 @@ test_expect_success '__git_complete' ' test_must_fail __git_complete ga missing ' +test_expect_success '__git_complete has correct __git_cmd_idx' ' + __git_complete ga _git_add && + echo modified > file1 && + touch file3 && + _words=(ga --update f) _cword=2 && + __git_wrap_git_add && + test "${COMPREPLY[*]}" = "file1" +' + test_done -- 2.37.2.351.g9bf691b78c.dirty