summaryrefslogtreecommitdiff
path: root/contrib/completion
AgeCommit message (Collapse)AuthorFilesLines
2013-04-14completion: small optimizationLibravatar Felipe Contreras1-4/+4
No need to calculate a new $c with a space if we are not going to do anything it with it. There should be no functional changes, except that a word "foo " with no suffixes can't be matched. But $cur cannot have a space at the end anyway. So it's safe. Based on the code from SZEDER Gábor. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-14completion: inline __gitcomp_1 to its sole callsiteLibravatar Felipe Contreras1-15/+11
There is no point in calling a separate function that is only used in one place. Especially considering that there's no need to call compgen, and we traverse the words ourselves both in __gitcompadd, and __gitcomp_1. Let's squash the functions together, and traverse only once. This improves performance. For N number of words: == 1 == original: 0.002s new: 0.000s == 10 == original: 0.005s new: 0.001s == 100 == original: 0.009s new: 0.006s == 1000 == original: 0.027s new: 0.019s == 10000 == original: 0.163s new: 0.151s == 100000 == original: 1.555s new: 1.497s No functional changes. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-14completion: get rid of compgenLibravatar Felipe Contreras1-5/+10
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-14completion: add new __gitcompadd helperLibravatar Felipe Contreras1-5/+8
The idea is to never touch the COMPREPLY variable directly. This allows other completion systems (i.e. zsh) to override __gitcompadd, and do something different instead. Also, this allows further optimizations down the line. There should be no functional changes. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-12completion: get rid of empty COMPREPLY assignmentsLibravatar Felipe Contreras1-21/+0
There's no functional reason for those, the only purpose they are supposed to serve is to say "we don't provide any words here", but even for that it's not used consistently. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-12completion: add more cherry-pick optionsLibravatar Felipe Contreras1-1/+6
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-03Merge branch 'rr/prompt-revert-head'Libravatar Junio C Hamano1-0/+2
The prompt string generator did not notice when we are in a middle of a "git revert" session. * rr/prompt-revert-head: bash: teach __git_ps1 about REVERT_HEAD
2013-03-31bash: teach __git_ps1 about REVERT_HEADLibravatar Robin Rosenberg1-0/+2
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-03-25Merge branch 'jl/submodule-deinit'Libravatar Junio C Hamano1-1/+1
There was no Porcelain way to say "I no longer am interested in this submodule", once you express your interest in a submodule with "submodule init". "submodule deinit" is the way to do so. * jl/submodule-deinit: submodule: add 'deinit' command
2013-03-11Merge branch 'mp/complete-paths'Libravatar Junio C Hamano1-5/+11
* mp/complete-paths: git-completion.bash: zsh does not implement function redirection correctly
2013-03-11git-completion.bash: zsh does not implement function redirection correctlyLibravatar Matthieu Moy1-5/+11
A recent change added functions whose entire standard error stream is redirected to /dev/null using a construct that is valid POSIX.1 but is not widely used: funcname () { cd "$1" && run some command "$2" } 2>/dev/null Even though this file is "git-completion.bash", zsh completion support dot-sources it (instead of asking bash to grok it like tcsh completion does), and zsh does not implement this redirection correctly. With zsh, trying to complete an inexistant directory gave this: git add no-such-dir/__git_ls_files_helper:cd:2: no such file or directory: no-such-dir/ Also these functions use "cd" to first go somewhere else before running a command, but the location the caller wants them to go that is given as an argument to them should not be affected by CDPATH variable the users may have set for their interactive session. To fix both of these, wrap the body of the function in a subshell, unset CDPATH at the beginning of the subshell, and redirect the standard error stream of the subshell to /dev/null. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-03-07Merge branch 'mp/complete-paths'Libravatar Junio C Hamano1-0/+9
* mp/complete-paths: git-completion.zsh: define __gitcomp_file compatibility function
2013-03-05git-completion.zsh: define __gitcomp_file compatibility functionLibravatar Matthieu Moy1-0/+9
Commit fea16b47b60 (Fri Jan 11 19:48:43 2013, Manlio Perillo, git-completion.bash: add support for path completion), introduced a new __gitcomp_file function that uses the bash builtin "compgen". The function was redefined for ZSH in the deprecated section of git-completion.bash, but not in the new git-completion.zsh script. As a result, users of git-completion.zsh trying to complete "git add fo<tab>" get an error: git add fo__gitcomp_file:8: command not found: compgen This patch adds the redefinition and removes the error. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-03-04submodule: add 'deinit' commandLibravatar Jens Lehmann1-1/+1
With "git submodule init" the user is able to tell git he cares about one or more submodules and wants to have it populated on the next call to "git submodule update". But currently there is no easy way he could tell git he does not care about a submodule anymore and wants to get rid of his local work tree (except he knows a lot about submodule internals and removes the "submodule.$name.url" setting from .git/config together with the work tree himself). Help those users by providing a 'deinit' command. This removes the whole submodule.<name> section from .git/config (either for the given submodule(s) or for all those which have been initialized if '.' is used) together with their work tree. Fail if the current work tree contains modifications (unless forced), but don't complain when either the work tree is already removed or no settings are found in .git/config. Add tests and link the man pages of "git submodule deinit" and "git rm" to assist the user in deciding whether removing or unregistering the submodule is the right thing to do for him. Also add the deinit subcommand to the completion list. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-18shell-prompt: clean up nested if-thenLibravatar Martin Erik Werner1-14/+13
Minor clean up of if-then nesting in checks for environment variables and config options. No functional changes. Signed-off-by: Martin Erik Werner <martinerikwerner@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-17Merge branch 'mp/diff-algo-config'Libravatar Junio C Hamano1-1/+13
Add diff.algorithm configuration so that the user does not type "diff --histogram". * mp/diff-algo-config: diff: Introduce --diff-algorithm command line option config: Introduce diff.algorithm variable git-completion.bash: Autocomplete --minimal and --histogram for git-diff
2013-02-17Merge branch 'mw/bash-prompt-show-untracked-config'Libravatar Junio C Hamano1-3/+8
Allows skipping the untracked check GIT_PS1_SHOWUNTRACKEDFILES asks for the git-prompt (in contrib/) per repository. * mw/bash-prompt-show-untracked-config: t9903: add extra tests for bash.showDirtyState t9903: add tests for bash.showUntrackedFiles shell prompt: add bash.showUntrackedFiles option
2013-02-13shell prompt: add bash.showUntrackedFiles optionLibravatar Martin Erik Werner1-3/+8
Add a config option 'bash.showUntrackedFiles' which allows enabling the prompt showing untracked files on a per-repository basis. This is useful for some repositories where the 'git ls-files ...' command may take a long time. Signed-off-by: Martin Erik Werner <martinerikwerner@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-12completion: support 'git config --local'Libravatar Matthieu Moy1-2/+2
This needs to be done in two places: __git_config_get_set_variables to allow clever completion of "git config --local --get foo<tab>", and _git_config to allow "git config --loc<tab>" to complete to --local. While we're there, change the order of options in the code to match git-config.txt. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-08Merge branch 'mk/tcsh-complete-only-known-paths'Libravatar Junio C Hamano1-0/+12
The "complete with known paths only" update to completion scripts returns directory names without trailing slash to compensate the addition of '/' done by bash that reads from our completion result. tcsh completion code that reads from our internal completion result does not add '/', so let it ask our complletion code to keep the '/' at the end. * mk/tcsh-complete-only-known-paths: completion: handle path completion and colon for tcsh script
2013-02-08Merge branch 'mp/complete-paths'Libravatar Junio C Hamano1-15/+240
The completion script used to let the default completer to suggest pathnames, which gave too many irrelevant choices (e.g. "git add" would not want to add an unmodified path). Teach it to use a more git-aware logic to enumerate only relevant ones. * mp/complete-paths: git-completion.bash: add support for path completion
2013-02-03completion: handle path completion and colon for tcsh scriptLibravatar Marc Khouzam1-0/+12
Recent enhancements to git-completion.bash provide intelligent path completion for git commands. Such completions do not provide the '/' at the end of directories for recent versions of bash; instead, bash itself will add the trailing slash to directories to the result provided by git-completion.bash. However, the completion for tcsh uses the result of the bash completion script directly, so it either needs to add the necessary slash itself, or needs to ask the bash script to keep the trailing slash. Adding the slash itself is difficult because we have to check the each path in the output of the bash script to see if it is meant to be a directory or something else. For example, assuming there is a directory named 'commit' in the current directory, then, when completing git add commit<tab> we would need to add a slash, but for git help commit<tab> we should not. Figuring out such differences would require adding much intelligence to the tcsh completion script. Instead, it is simpler to ask the bash script to keep the trailing slash. This patch does this. Also, tcsh does not handle the colon as a completion separator so we remove it from the list of separators. Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com>
2013-02-01Merge branch 'jc/do-not-let-random-file-interfere-with-completion-tests'Libravatar Junio C Hamano1-1/+10
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
2013-01-28Merge branch 'bc/fix-array-syntax-for-3.0-in-completion-bash'Libravatar Junio C Hamano1-1/+1
Fix use of an array notation that older versions of bash do not understand. * bc/fix-array-syntax-for-3.0-in-completion-bash: git-completion.bash: replace zsh notation that breaks bash 3.X
2013-01-24t9902: protect test from stray build artifactsLibravatar Junio C Hamano1-1/+10
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>
2013-01-23Merge branch 'as/check-ignore'Libravatar Junio C Hamano1-0/+1
Add a new command "git check-ignore" for debugging .gitignore files. The variable names may want to get cleaned up but that can be done in-tree. * as/check-ignore: clean.c, ls-files.c: respect encapsulation of exclude_list_groups t0008: avoid brace expansion add git-check-ignore sub-command setup.c: document get_pathspec() add.c: extract new die_if_path_beyond_symlink() for reuse add.c: extract check_path_for_gitlink() from treat_gitlinks() for reuse pathspec.c: rename newly public functions for clarity add.c: move pathspec matchers into new pathspec.c for reuse add.c: remove unused argument from validate_pathspec() dir.c: improve docs for match_pathspec() and match_pathspec_depth() dir.c: provide clear_directory() for reclaiming dir_struct memory dir.c: keep track of where patterns came from dir.c: use a single struct exclude_list per source of excludes Conflicts: builtin/ls-files.c dir.c
2013-01-18git-completion.bash: replace zsh notation that breaks bash 3.XLibravatar Brandon Casey1-1/+1
When commit d8b45314 began separating the zsh completion from the bash completion, it introduced a zsh completion "bridge" section into the bash completion script for zsh users to use until they migrated to the zsh script. The zsh '+=()' append-to-array notation prevents bash 3.00.15 on CentOS 4.x from loading the completion script and breaks test 9902. We can easily work around this by using standard Bash array notation. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-18Merge branch 'ds/completion-silence-in-tree-path-probe'Libravatar Junio C Hamano1-1/+1
An internal ls-tree call made by completion code only to probe if a path exists in the tree recorded in a commit object leaked error messages when the path is not there. It is not an error at all and should not be shown to the end user. * ds/completion-silence-in-tree-path-probe: git-completion.bash: silence "not a valid object" errors
2013-01-18Merge branch 'mk/complete-tcsh'Libravatar Junio C Hamano1-12/+21
Update tcsh command line completion so that an unwanted space is not added to a single directory name. * mk/complete-tcsh: Prevent space after directories in tcsh completion
2013-01-16diff: Introduce --diff-algorithm command line optionLibravatar Michal Privoznik1-0/+11
Since command line options have higher priority than config file variables and taking previous commit into account, we need a way how to specify myers algorithm on command line. However, inventing `--myers` is not the right answer. We need far more general option, and that is `--diff-algorithm`. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-16config: Introduce diff.algorithm variableLibravatar Michal Privoznik1-0/+1
Some users or projects prefer different algorithms over others, e.g. patience over myers or similar. However, specifying appropriate argument every time diff is to be used is impractical. Moreover, creating an alias doesn't play nicely with other tools based on diff (git-show for instance). Hence, a configuration variable which is able to set specific algorithm is needed. For now, these four values are accepted: 'myers' (which has the same effect as not setting the config variable at all), 'minimal', 'patience' and 'histogram'. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-14git-completion.bash: Autocomplete --minimal and --histogram for git-diffLibravatar Michal Privoznik1-1/+1
Even though --patience was already there, we missed --minimal and --histogram for some reason. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-14Merge branch 'jk/complete-commit-c' into maintLibravatar Junio C Hamano1-0/+7
* jk/complete-commit-c: completion: complete refs for "git commit -c"
2013-01-11git-completion.bash: add support for path completionLibravatar Manlio Perillo1-15/+240
The git-completion.bash script did not implemented full, git aware, support to complete paths, for git commands that operate on files within the current working directory or the index. As an example: git add <TAB> will suggest all files in the current working directory, including ignored files and files that have not been modified. Support path completion, for git commands where the non-option arguments always refer to paths within the current working directory or the index, as follows: * the path completion for the "git rm" and "git ls-files" commands will suggest all cached files. * the path completion for the "git add" command will suggest all untracked and modified files. Ignored files are excluded. * the path completion for the "git clean" command will suggest all untracked files. Ignored files are excluded. * the path completion for the "git mv" command will suggest all cached files when expanding the first argument, and all untracked and cached files for subsequent arguments. In the latter case, empty directories are included and ignored files are excluded. * the path completion for the "git commit" command will suggest all files that have been modified from the HEAD, if HEAD exists, otherwise it will suggest all cached files. For all affected commands, completion will always stop at directory boundary. Only standard ignored files are excluded, using the --exclude-standard option of the ls-files command. When using a recent Bash version, Git path completion will be the same as builtin file completion, e.g. git add contrib/ will suggest relative file names. Signed-off-by: Manlio Perillo <manlio.perillo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-11git-completion.bash: silence "not a valid object" errorsLibravatar Dylan Smith1-1/+1
Trying to complete the command git show master:./file would cause a "Not a valid object name" error to be output on standard error. Silence the error so it won't appear on the command line. Signed-off-by: Dylan Smith <dylan.ah.smith@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-07Prevent space after directories in tcsh completionLibravatar Marc Khouzam1-12/+21
If git-completion.bash returns a single directory as a completion, tcsh will automatically add a space after it, which is not what the user wants. This commit prevents tcsh from doing this. Also, a check is added to make sure the tcsh version used is recent enough to allow completion to work as expected. Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-06add git-check-ignore sub-commandLibravatar Adam Spiers1-0/+1
This works in a similar manner to git-check-attr. Thanks to Jeff King and Junio C Hamano for the idea: http://thread.gmane.org/gmane.comp.version-control.git/108671/focus=108815 Signed-off-by: Adam Spiers <git@adamspiers.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-05Merge branch 'jk/complete-commit-c'Libravatar Junio C Hamano1-0/+7
Complete "git commmit -c foo<TAB>" into a refname that begins with "foo". * jk/complete-commit-c: completion: complete refs for "git commit -c"
2012-12-27Merge branch 'so/prompt-command'Libravatar Junio C Hamano1-12/+20
Finishing touches... * so/prompt-command: make __git_ps1 accept a third parameter in pcmode
2012-12-26make __git_ps1 accept a third parameter in pcmodeLibravatar Simon Oosthoek1-12/+20
The optional third parameter when __git_ps1 is used in PROMPT_COMMAND mode as format string for printf to further customize the way the git status string is embedded in the user's PS1 prompt. Signed-off-by: Simon Oosthoek <s.oosthoek@xs4all.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-15completion: complete refs for "git commit -c"Libravatar Jeff King1-0/+7
The "-c" and "-C" options take an existing commit, so let's complete refs, just as we would for --squash or --fixup. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-12Merge branch 'so/prompt-command'Libravatar Junio C Hamano1-5/+11
* so/prompt-command: git-prompt.sh: update PROMPT_COMMAND documentation
2012-12-12git-prompt.sh: update PROMPT_COMMAND documentationLibravatar Junio C Hamano1-5/+11
The description of __git_ps1 function operating in two-arg mode was not very clear. It said "set PROMPT_COMMAND=__git_ps1" which is not the right usage for this mode, followed by "To customize the prompt, do this", giving a false impression that those who do not want to customize it can get away with no-arg form, which was incorrect. Make it clear that this mode always takes two arguments, pre and post, with an example. The straight-forward one should be listed as the primary usage, and the confusing one should be an alternate for advanced users. Swap the order of these two. Acked-by: Simon Oosthoek <s.oosthoek@xs4all.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-11Add file completion to tcsh git completion.Libravatar Marc Khouzam1-15/+54
For bash completion, the option '-o bashdefault' is used to indicate that when no other choices are available, file completion should be performed. Since this option is not available in tcsh, no file completion is ever performed. Therefore, commands like 'git add ', 'git send-email ', etc, require the user to manually type out the file name. This can be quite annoying. To improve the user experience we try to simulate file completion directly in this script (although not perfectly). The known issues with the file completion simulation are: - Possible completions are shown with their directory prefix. - Completions containing shell variables are not handled. - Completions with ~ as the first character are not handled. Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-11Merge branch 'maint'Libravatar Junio C Hamano1-1/+10
* maint: git-prompt: Document GIT_PS1_DESCRIBE_STYLE
2012-12-11git-prompt: Document GIT_PS1_DESCRIBE_STYLELibravatar Anders Kaseorg1-0/+9
GIT_PS1_DESCRIBE_STYLE was introduced in v1.6.3.2~35. Document it in the header comments. Signed-off-by: Anders Kaseorg <andersk@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-29Merge branch 'mk/complete-tcsh'Libravatar Junio C Hamano1-7/+12
Finishing touches for tcsh completion. * mk/complete-tcsh: Support for git aliasing for tcsh completion
2012-11-29completion: fix warning for zshLibravatar Felipe Contreras1-0/+2
Otherwise the user might get something like: git-completion.sh:2466: command not found: compdef If this script is loaded before compinit. The script would work either way, but let's not be more annoying to the user. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-28Merge branch 'maint'Libravatar Junio C Hamano1-0/+2
2012-11-28Merge branch 'fc/zsh-completion'Libravatar Junio C Hamano2-43/+139
* fc/zsh-completion: completion: start moving to the new zsh completion completion: add new zsh completion