Skip to content

Commit

Permalink
Merge branch 'jc/alias-completion'
Browse files Browse the repository at this point in the history
The command line completion script (in contrib/) can be told to
complete aliases by including ": git <cmd> ;" in the alias to tell
it that the alias should be completed similar to how "git <cmd>" is
completed.  The parsing code for the alias as been loosened to
allow ';' without an extra space before it.

* jc/alias-completion:
  completion: loosen and document the requirement around completing alias
  • Loading branch information
gitster committed Sep 29, 2023
2 parents e076f3a + 8d73a2c commit d15f92e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
# completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
# Be sure to add a space between the command name and the ';'.
# Note that "git" is optional --- '!f() { : commit; ...}; f' would complete
# just like the 'git commit' command.
#
# If you have a command that is not part of git, but you would still
# like completion, you can use __git_complete:
Expand Down Expand Up @@ -1183,7 +1184,7 @@ __git_aliased_command ()
:) : skip null command ;;
\'*) : skip opening quote after sh -c ;;
*)
cur="$word"
cur="${word%;}"
break
esac
done
Expand Down
18 changes: 18 additions & 0 deletions t/t9902-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,24 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c
EOF
'

test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
test_config alias.co "!f() { : checkout ; if ... } f" &&
test_completion "git co m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'

test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd>; ... }' '
test_config alias.co "!f() { : checkout; if ... } f" &&
test_completion "git co m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'

test_expect_success 'completion without explicit _git_xxx function' '
test_completion "git version --" <<-\EOF
--build-options Z
Expand Down

0 comments on commit d15f92e

Please sign in to comment.