completion: loosen and document the requirement around completing alias
Recently we started to tell users to spell ": git foo ;" with space(s) around 'foo' for an alias to be completed similarly to the 'git foo' command. It however is easy to also allow users to spell it in a more natural way with the semicolon attached to 'foo', i.e. ": git foo;". Also, add a comment to note that 'git' is optional and writing ": foo;" would complete the alias just fine. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Sep 20, 2023 at 11:28 UTC
8d73a2cc036199a25cc97586937267ec14cb6eae
2 files changed
+21
-2
contrib/completion/git-completion.bash
+3
-2
@@ -28,7 +28,8 @@
28
# completion style. For example '!f() { : git commit ; ... }; f' will
29
# tell the completion to use commit completion. This also works with aliases
30
# 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.
33
#
34
# If you have a command that is not part of git, but you would still
35
# like completion, you can use __git_complete:
@@ -1183,7 +1184,7 @@ __git_aliased_command ()
1184
:) : skip null command ;;
1185
\'*) : skip opening quote after sh -c ;;
1186
*)
1186
- cur="$word"
1187
+ cur="${word%;}"
1188
break
1189
esac
1190
done
t/t9902-completion.sh
+18
@@ -2464,6 +2464,24 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c
2464
EOF
2465
'
2466
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
+
2485
test_expect_success 'completion without explicit _git_xxx function' '
2486
test_completion "git version --" <<-\EOF
2487
--build-options Z