All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Bob van der Linden via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Bob van der Linden <bobvanderlinden@gmail.com>,
	Bob van der Linden <bobvanderlinden@gmail.com>
Subject: [PATCH] completion: support amend and reword in git commit fixup option
Date: Sat, 15 Oct 2022 19:54:55 +0000	[thread overview]
Message-ID: <pull.1365.git.git.1665863696303.gitgitgadget@gmail.com> (raw)

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

             reply	other threads:[~2022-10-15 19:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-15 19:54 Bob van der Linden via GitGitGadget [this message]
2022-10-16 20:50 [PATCH] completion: support amend and reword in git commit fixup option Bob van der Linden
2022-10-18 21:49 Bob van der Linden

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1365.git.git.1665863696303.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=bobvanderlinden@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.