summaryrefslogtreecommitdiff
path: root/t/t9902-completion.sh
AgeCommit message (Collapse)Author
2015-05-12completion: simplify query for config variablesSZEDER Gábor
To get the name of all config variables in a given section we perform a 'git config --get-regex' query for all config variables containing the name of that section, and then filter its output through a case statement to throw away those that though contain but don't start with the given section. Modify the regex to match only at the beginning, so the case statement becomes unnecessary and we can get rid of it. Add a test to check that a match in the middle doesn't fool us. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-12completion: add a helper function to get config variablesSZEDER Gábor
Currently there are a few completion functions that perform similar 'git config' queries and filtering to get config variable names: the completion of pretty aliases, aliases, and remote groups for 'git remote update'. Unify those 'git config' queries in a helper function to eliminate code duplication. Though the helper functions to get pretty aliases and alieses are reduced to mere one-liner wrappers around the newly added function, keep these helpers still, because users' completion functions out there might depend on them. And they keep their callers a tad easier to read, too. Add tests for the pretty alias and alias helper to show that they work as before; not for the remote groups query, though, because that's not extracted into a helper function and it's not worth the effort to do so for a sole callsite. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-03-20t: fix severe &&-chain breakageJeff King
These are tests which are missing a link in their &&-chain, in a location which causes a significant portion of the test to be missed (e.g., the test effectively does nothing, or consists of a long string of actions and output comparisons, and we throw away the exit code of at least one part of the string). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-03-06completion: add a test for __git_remotes() helper functionSZEDER Gábor
The test checks that both remotes under '$GIT_DIR/remotes' and remotes in the config file are listed. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-21t9902: mingw-specific fix for gitfile link filesPat Thoyts
The path in a .git platform independent link file needs to be absolute and under mingw we need it to be a windows type path, not a unix style path so it should start with a drive letter and not a /. Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net> Signed-off-by: Stepan Kasal <kasal@ucw.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-13completion: handle '!f() { ... }; f' and "!sh -c '...' -" aliasesSteffen Prohaska
'!f() { ... }; f' and "!sh -c '....' -" are recommended patterns for declaring more complex aliases (see git wiki [1]). This commit teaches the completion to handle them. When determining which completion to use for an alias, an opening brace or single quote is now skipped, and the search for a git command is continued. For example, the aliases '!f() { git commit ... }' or "!sh -c 'git commit ...'" now trigger commit completion. Previously, the search stopped on the opening brace or quote, and the completion tried it to determine how to complete, which obviously was useless. The null command ':' is now skipped, so that it can be used as a workaround to declare the desired completion style. For example, the aliases !f() { : git commit ; if ... } f !sh -c ': git commit; if ...' - now trigger commit completion. Shell function declarations now work with or without space before the parens, i.e. '!f() ...' and '!f () ...' both work. [1] https://git.wiki.kernel.org/index.php/Aliases Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-21t9902-completion.sh: old Bash still does not support array+=('') notationBrandon Casey
Old Bash (3.0) which is distributed with RHEL 4.X and other ancient platforms that are still in wide use, does not understand the array+=() notation. Let's use an explicit assignment to the new array element which works everywhere, like: array[${#array[@]}+1]='' The right-hand side '' is not strictly necessary, but in this case I think it is more clear. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-12Merge branch 'tr/test-lint-no-export-assignment-in-shell'Junio C Hamano
* tr/test-lint-no-export-assignment-in-shell: test-lint: detect 'export FOO=bar' t9902: fix 'test A == B' to use = operator
2013-07-11Merge branch 'jk/bash-completion'Junio C Hamano
* jk/bash-completion: completion: learn about --man-path completion: handle unstuck form of base git options
2013-07-08t9902: fix 'test A == B' to use = operatorThomas Rast
The == operator as an alias to = is not POSIX. This doesn't actually matter for the execution of the script, because it only runs when the shell is bash. However, it trips up test-lint, so it's nicer to use the standard form. Signed-off-by: Thomas Rast <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-30completion: learn about --man-pathJohn Keeping
Signed-off-by: John Keeping <john@keeping.me.uk> Acked-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-24completion, bash prompt: move __gitdir() tests to completion test suiteSZEDER Gábor
Currently __gitdir() is duplicated in the git completion and prompt scripts, while its tests are in the prompt test suite. This patch series is about to change __git_ps1() in a way that it won't need __gitdir() anymore and __gitdir() will be removed from the prompt script. So move all __gitdir() tests from the prompt test suite over to the completion test suite. Update the setup tests so that they perform only those steps that are necessary for each test suite. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-04-27completion: document tilde expansion failure in testsFelipe Contreras
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-27completion: add file completion testsFelipe Contreras
The commit fea16b4 (git-completion.bash: add support for path completion) introduced quite a few changes, without the usual tests. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-15completion: get rid of compgenFelipe Contreras
The functionality we use from compgen is not much, we can do the same manually, with drastic improvements in speed, especially when dealing with only a few words. This patch also has the sideffect that brekage reported by Jeroen Meijer and SZEDER Gábor gets fixed because we no longer expand the resulting words. Here are some numbers filtering N amount of words: == 1 == original: 0.002s new: 0.000s == 10 == original: 0.002s new: 0.000s == 100 == original: 0.003s new: 0.002s == 1000 == original: 0.012s new: 0.011s == 10000 == original: 0.056s new: 0.066s == 100000 == original: 2.669s new: 0.622s If the results are not narrowed: == 1 == original: 0.002s new: 0.000s == 10 == original: 0.002s new: 0.001s == 100 == original: 0.004s new: 0.004s == 1000 == original: 0.020s new: 0.015s == 10000 == original: 0.101s new: 0.355s == 100000 == original: 2.850s new: 31.941s So, unless 'git checkout <tab>' usually gives you more than 10000 results, you'll get an improvement :) Other possible solutions perform better after 1000 words, but worst if less than that: COMPREPLY=($(awk -v cur="$3" -v pre="$2" -v suf="$4" '$0 ~ cur { print pre$0suf }' <<< "$1" )) COMPREPLY=($(printf -- "$2%s$4\n" $1 | grep "^$2$3")) Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-15completion: add __gitcomp_nl testsFelipe Contreras
Original patch by SZEDER Gábor. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-12completion: trivial test improvementFelipe Contreras
Instead of passing a dummy "", let's check if the last character is a space, and then move the _cword accordingly. Apparently we were passing "" all the way to compgen, which fortunately expanded it to nothing. Lets do the right thing though. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-24t9902: protect test from stray build artifactsJunio C Hamano
When you have random build artifacts in your build directory, left behind by running "make" while on another branch, the "git help -a" command run by __git_list_all_commands in the completion script that is being tested does not have a way to know that they are not part of the subcommands this build will ship. Such extra subcommands may come from the user's $PATH. They will interfere with the tests that expect a certain prefix to uniquely expand to a known completion. Instrument the completion script and give it a way for us to tell what (subset of) subcommands we are going to ship. Also add a test to "git --help <prefix><TAB>" expansion. It needs to show not just commands but some selected documentation pages. Based on an idea by Jeff King. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-29Merge branch 'fc/completion-test-simplification'Junio C Hamano
Clean up completion tests. Use of conslidated helper may make instrumenting one particular test during debugging of the test itself, but I think that issue should be addressed in some other way (e.g. making sure individual tests in 9902 can be skipped). * fc/completion-test-simplification: completion: simplify __gitcomp() test helper completion: refactor __gitcomp related tests completion: consolidate test_completion*() tests completion: simplify tests using test_completion_long() completion: standardize final space marker in tests completion: add comment for test_completion()
2012-11-16completion: simplify __gitcomp() test helperFelipe Contreras
By using print_comp as suggested by SZEDER Gábor. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-16completion: refactor __gitcomp related testsFelipe Contreras
Remove lots of duplicated code; no functional changes intended. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-16completion: consolidate test_completion*() testsFelipe Contreras
No need to have two versions; if a second argument is specified, use that, otherwise use stdin. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-16completion: simplify tests using test_completion_long()Felipe Contreras
No need to duplicate that functionality. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-16completion: standardize final space marker in testsFelipe Contreras
The rest of the code uses ' Z$'. Lets use that for test_completion_long() as well. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-16completion: add comment for test_completion()Felipe Contreras
So that it's easier to understand what it does. Also, make sure we pass only the first argument for completion. Shouldn't cause any functional changes because run_completion only checks $1. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-10-16completion: add format-patch options to send-emailFelipe Contreras
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-28t9902: add completion tests for "odd" filenamesJeff King
We correctly handle completion items with spaces just fine, since we pass the lists around with newline delimiters. However, we do not handle filenames with shell metacharacters, as "compgen -W" performs expansion on the list we give it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-28t9902: add a few basic completion testsJeff King
We were not testing ref or tree completion at all. Let's give them even basic sanity checks to avoid regressions. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-06-28Merge branch 'fc/git-prompt-script'Junio C Hamano
Split a rather heavy-ish "git completion" script out to create a separate "git prompting" script, to help lazy-autoloading of the completion part while making prompting part always available.
2012-06-13completion: put main git and gitk completion functions back into git namespaceSZEDER Gábor
Commit 7f02f3d7 (completion: rename internal helpers _git and _gitk, 2012-05-19) renamed said functions to _main_git() and _main_gitk(), respectively. By convention the name of our git-completion-specific functions start with '_git' or '__git' prefix, so rename those functions once again to put them back into our "namespace". Use the two underscore prefix, because _git_main() could be mistaken for the completion function of the (not yet existing) 'git main' command. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-22Merge branch 'fc/git-complete-helper' into fc/git-prompt-scriptJunio C Hamano
By Michael Haggerty (17) and others via Junio C Hamano (36) and Jeff King (1) * fc/git-complete-helper: (54 commits) completion: add new __git_complete helper Update draft release notes to 1.7.11 (11th batch) Git 1.7.10.2 document submdule.$name.update=none option for gitmodules The tenth batch of topics Update draft release notes to 1.7.10.2 checkout: do not corrupt HEAD on empty repo apply: remove lego in i18n string in gitdiff_verify_name dir: convert to strbuf status: refactor colopts handling status: respect "-b" for porcelain format status: fix null termination with "-b" status: refactor null_termination option commit: refactor option parsing Documentation/git-config: describe and clarify "--local <file>" option reflog-walk: tell explicit --date=default from not having --date at all clone: fix progress-regression grep.c: remove redundant line of code checkout (detached): truncate list of orphaned commits at the new HEAD t2020-checkout-detach: check for the number of orphaned commits ...
2012-05-20completion: rename internal helpers _git and _gitkFelipe Contreras
Would be useful to provide backwards compatibility for _git. Also, zsh completion uses _git, and it cannot be changed. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-14completion: add new __git_complete helperFelipe Contreras
This simplifies the completions, and would make it easier to define aliases in the future. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-09tests: move code to run tests under bash into a helper librarySZEDER Gábor
The following patch will add tests for the bash prompt functions as a new test script, which also has to be run under bash. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-22completion: fix completion after 'git --option <TAB>'SZEDER Gábor
The bash completion doesn't work when certain options to git itself are specified, e.g. 'git --no-pager <TAB>' errors out with error: invalid key: alias.--no-pager The main _git() completion function finds out the git command name by looping through all the words on the command line and searching for the first word that is not a known option for the git command. Unfortunately the list of known git options was not updated in a long time, and newer options are not skipped but mistaken for a git command. Such a misrecognized "command" is then passed to __git_aliased_command(), which in turn passes it to a 'git config' query, hence the error. Currently the following options are misrecognized for a git command: -c --no-pager --exec-path --html-path --man-path --info-path --no-replace-objects --work-tree= --namespace= To fix this we could just update the list of options to be skipped, but the same issue will likely arise, if the git command learns a new option in the future. Therefore, to make it more future proof against new options, this patch changes that loop to skip all option-looking words, i.e. words starting with a dash. We also have to handle the '-c' option specially, because it takes a configutation parameter in a separate word, which must be skipped, too. [fc: added tests] Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-22completion: avoid trailing space for --exec-pathJonathan Nieder
"--exec-path" looks to the completion script like an unambiguous successful completion, but it is wrong to emit a SP after it as if declaring that we are done with completion; the user could be trying to do git --exec-path; # print name of helper directory or git --exec-path=/path/to/alternative/helper/dir <subcommand> so the most helpful thing to do is to leave out the trailing space and leave it to the operator to type an equal sign or carriage return according to the situation. [fc: added tests] Cc: Andreas Schwab <schwab@linux-m68k.org> Reported-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-22completion: add missing general optionsFelipe Contreras
And add relevant tests. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-22tests: add tests for the __gitcomp() completion helper functionSZEDER Gábor
These tests check that trailing space, prefix, and suffix are added correctly. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-15tests: add initial bash completion testsFelipe Contreras
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>