* [PATCH] completion: support amend and reword in git commit fixup option
@ 2022-10-15 19:54 Bob van der Linden via GitGitGadget
0 siblings, 0 replies; 3+ messages in thread
From: Bob van der Linden via GitGitGadget @ 2022-10-15 19:54 UTC (permalink / raw)
To: git; +Cc: Bob van der Linden, Bob van der Linden
From: Bob van der Linden <bobvanderlinden@gmail.com>
The option `git commit --fixup=` has the ability to create amend and
reword commits, by specifying `--fixup=amend:REF` and
`--fixup=reword:REF`.
This patch allows completion of amend: and reword: prefixes when a user
has already typed the --fixup= option.
In addition, this patch fixes completion of refs that can be
filled in after the amend: and reword: prefixes. Previously `amend:` and
`reword:` were considered part of the ref to complete, which always
resulted in 0 potential completions.
Signed-off-by: Bob van der Linden <bobvanderlinden@gmail.com>
---
completion: support amend and reword in git commit fixup option
I'd like to use git commit --fixup= more in my day-to-day work. However,
it dawned on me that the options --fixup=amend: and --fixup=reword: were
not supported by bash completion.
I attempted to solve this by first adding amend: and reword: to the
completions of --fixup=. In addition, I made sure that --fixup=amend:ref
does not consider amend: to be part of the reference, thus allowing
completion of references when --fixup=amend: and --fixup=reword: are
used.
The patch also includes completion tests for --fixup=, --fixup=amend:
and --fixup=reword:.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1365%2Fbobvanderlinden%2Fpr-fixup-amend-reword-completion-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1365/bobvanderlinden/pr-fixup-amend-reword-completion-v1
Pull-Request: https://github.com/git/git/pull/1365
contrib/completion/git-completion.bash | 11 +++++++-
t/t9902-completion.sh | 35 ++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ba5c395d2d8..8d1a713dc4d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1672,8 +1672,17 @@ _git_commit ()
" "" "${cur##--cleanup=}"
return
;;
+ --fixup=amend:*|--fixup=reword:*)
+ __git_complete_refs --cur="${cur#*:}"
+ return
+ ;;
+ --fixup=*)
+ __git_complete_refs --cur="${cur#*=}"
+ __gitcomp_direct_append "$(compgen -W "amend: reword:" "${cur#*=}")"
+ return
+ ;;
--reuse-message=*|--reedit-message=*|\
- --fixup=*|--squash=*)
+ --squash=*)
__git_complete_refs --cur="${cur#*=}"
return
;;
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 43de868b800..bb3dcab5d9d 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1444,6 +1444,41 @@ test_expect_success 'git checkout - with --detach, complete only references' '
EOF
'
+test_expect_success 'git commit - with --fixup=, completes references along with amend: and reword:' '
+ test_completion "git commit --fixup=" <<-\EOF
+ HEAD Z
+ main Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/main-in-other Z
+ amend:Z
+ reword:Z
+ EOF
+'
+
+test_expect_success 'git commit - with --fixup=amend:, completes references' '
+ test_completion "git commit --fixup=amend:" <<-\EOF
+ HEAD Z
+ main Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/main-in-other Z
+ EOF
+'
+
+test_expect_success 'git commit - with --fixup=reword:, completes references' '
+ test_completion "git commit --fixup=reword:" <<-\EOF
+ HEAD Z
+ main Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/main-in-other Z
+ EOF
+'
+
test_expect_success 'setup sparse-checkout tests' '
# set up sparse-checkout repo
git init sparse-checkout &&
base-commit: 3dcec76d9df911ed8321007b1d197c1a206dc164
--
gitgitgadget
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] completion: support amend and reword in git commit fixup option
@ 2022-10-16 20:50 Bob van der Linden
0 siblings, 0 replies; 3+ messages in thread
From: Bob van der Linden @ 2022-10-16 20:50 UTC (permalink / raw)
To: gitgitgadget; +Cc: Bob van der Linden, git
Hmm, I cannot figure out why `CI / win+VS test` is failing on GitHub CI.
The logs do indicate `Result: FAIL`, but I cannot see which test is failing.
It's surprising, as my changes seem totally unrelated to Windows.
Could anyone help out?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] completion: support amend and reword in git commit fixup option
@ 2022-10-18 21:49 Bob van der Linden
0 siblings, 0 replies; 3+ messages in thread
From: Bob van der Linden @ 2022-10-18 21:49 UTC (permalink / raw)
To: Bob van der Linden; +Cc: git, gitgitgadget
It seemed to have been a flaky test that was failing. All looks good now.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-18 21:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-16 20:50 [PATCH] completion: support amend and reword in git commit fixup option Bob van der Linden
-- strict thread matches above, loose matches on Subject: below --
2022-10-18 21:49 Bob van der Linden
2022-10-15 19:54 Bob van der Linden via GitGitGadget
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).