Skip to content

Commit d15f92e

Browse files
committed
Merge branch 'jc/alias-completion'
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
2 parents e076f3a + 8d73a2c commit d15f92e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

contrib/completion/git-completion.bash

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
# completion style. For example '!f() { : git commit ; ... }; f' will
2929
# tell the completion to use commit completion. This also works with aliases
3030
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
31-
# Be sure to add a space between the command name and the ';'.
31+
# Note that "git" is optional --- '!f() { : commit; ...}; f' would complete
32+
# just like the 'git commit' command.
3233
#
3334
# If you have a command that is not part of git, but you would still
3435
# like completion, you can use __git_complete:
@@ -1183,7 +1184,7 @@ __git_aliased_command ()
11831184
:) : skip null command ;;
11841185
\'*) : skip opening quote after sh -c ;;
11851186
*)
1186-
cur="$word"
1187+
cur="${word%;}"
11871188
break
11881189
esac
11891190
done

t/t9902-completion.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,24 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c
24642464
EOF
24652465
'
24662466

2467+
test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
2468+
test_config alias.co "!f() { : checkout ; if ... } f" &&
2469+
test_completion "git co m" <<-\EOF
2470+
main Z
2471+
mybranch Z
2472+
mytag Z
2473+
EOF
2474+
'
2475+
2476+
test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd>; ... }' '
2477+
test_config alias.co "!f() { : checkout; if ... } f" &&
2478+
test_completion "git co m" <<-\EOF
2479+
main Z
2480+
mybranch Z
2481+
mytag Z
2482+
EOF
2483+
'
2484+
24672485
test_expect_success 'completion without explicit _git_xxx function' '
24682486
test_completion "git version --" <<-\EOF
24692487
--build-options Z

0 commit comments

Comments
 (0)