Skip to content

Commit

Permalink
Merge branch 'jc/do-not-let-random-file-interfere-with-completion-tes…
Browse files Browse the repository at this point in the history
…ts' into maint

Scripts to test bash completion was inherently flaky as it was
affected by whatever random things the user may have on $PATH.

* jc/do-not-let-random-file-interfere-with-completion-tests:
  t9902: protect test from stray build artifacts
  • Loading branch information
Junio C Hamano committed Feb 7, 2013
2 parents 7728473 + 5047822 commit 696c359
Showing 2 changed files with 34 additions and 2 deletions.
11 changes: 10 additions & 1 deletion contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
@@ -531,10 +531,19 @@ __git_complete_strategy ()
return 1
}

__git_commands () {
if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
then
printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
else
git help -a|egrep '^ [a-zA-Z0-9]'
fi
}

__git_list_all_commands ()
{
local i IFS=" "$'\n'
for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
for i in $(__git_commands)
do
case $i in
*--*) : helper pattern;;
25 changes: 24 additions & 1 deletion t/t9902-completion.sh
Original file line number Diff line number Diff line change
@@ -13,6 +13,25 @@ complete ()
return 0
}

# Be careful when updating this list:
#
# (1) The build tree may have build artifact from different branch, or
# the user's $PATH may have a random executable that may begin
# with "git-check" that are not part of the subcommands this build
# will ship, e.g. "check-ignore". The tests for completion for
# subcommand names tests how "check" is expanded; we limit the
# possible candidates to "checkout" and "check-attr" to make sure
# "check-attr", which is known by the filter function as a
# subcommand to be thrown out, while excluding other random files
# that happen to begin with "check" to avoid letting them get in
# the way.
#
# (2) A test makes sure that common subcommands are included in the
# completion for "git <TAB>", and a plumbing is excluded. "add",
# "filter-branch" and "ls-files" are listed for this.

GIT_TESTING_COMMAND_COMPLETION='add checkout check-attr filter-branch ls-files'

. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"

# We don't need this function to actually join words or do anything special.
@@ -196,7 +215,6 @@ test_expect_success 'general options plus command' '
test_completion "git --paginate check" "checkout " &&
test_completion "git --git-dir=foo check" "checkout " &&
test_completion "git --bare check" "checkout " &&
test_completion "git --help des" "describe " &&
test_completion "git --exec-path=foo check" "checkout " &&
test_completion "git --html-path check" "checkout " &&
test_completion "git --no-pager check" "checkout " &&
@@ -207,6 +225,11 @@ test_expect_success 'general options plus command' '
test_completion "git --no-replace-objects check" "checkout "
'

test_expect_success 'git --help completion' '
test_completion "git --help ad" "add " &&
test_completion "git --help core" "core-tutorial "
'

test_expect_success 'setup for ref completion' '
echo content >file1 &&
echo more >file2 &&

0 comments on commit 696c359

Please sign in to comment.