{"thread":{"id":"58631","subject":"[PATCH] completion: support amend and reword in git commit fixup option","startedAt":"2022-10-15T19:55:04Z","lastAt":"2022-10-15T19:55:04Z","messageCount":1,"participants":["Bob van der Linden via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"465034","messageId":"pull.1365.git.git.1665863696303.gitgitgadget@gmail.com","threadId":"58631","inReplyTo":null,"subject":"[PATCH] completion: support amend and reword in git commit fixup option","fromName":"Bob van der Linden via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-10-15T19:54:55Z","receivedAt":"2022-10-15T19:55:04Z","isPatch":true,"sender":{"key":"bobvanderlinden@gmail.com","avatar":"https://gravatar.com/avatar/21e15d98784c39be83c652f2cbcfca07f7617b9744f6aa66cc84ef95914334d9?d=mp&s=160"},"body":"From: Bob van der Linden <bobvanderlinden@gmail.com>\n\nThe option `git commit --fixup=` has the ability to create amend and\nreword commits, by specifying `--fixup=amend:REF` and\n`--fixup=reword:REF`.\n\nThis patch allows completion of amend: and reword: prefixes when a user\nhas already typed the --fixup= option.\n\nIn addition, this patch fixes completion of refs that can be\nfilled in after the amend: and reword: prefixes. Previously `amend:` and\n`reword:` were considered part of the ref to complete, which always\nresulted in 0 potential completions.\n\nSigned-off-by: Bob van der Linden <bobvanderlinden@gmail.com>\n---\n    completion: support amend and reword in git commit fixup option\n    \n    I'd like to use git commit --fixup= more in my day-to-day work. However,\n    it dawned on me that the options --fixup=amend: and --fixup=reword: were\n    not supported by bash completion.\n    \n    I attempted to solve this by first adding amend: and reword: to the\n    completions of --fixup=. In addition, I made sure that --fixup=amend:ref\n    does not consider amend: to be part of the reference, thus allowing\n    completion of references when --fixup=amend: and --fixup=reword: are\n    used.\n    \n    The patch also includes completion tests for --fixup=, --fixup=amend:\n    and --fixup=reword:.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1365%2Fbobvanderlinden%2Fpr-fixup-amend-reword-completion-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1365/bobvanderlinden/pr-fixup-amend-reword-completion-v1\nPull-Request: https://github.com/git/git/pull/1365\n\n contrib/completion/git-completion.bash | 11 +++++++-\n t/t9902-completion.sh                  | 35 ++++++++++++++++++++++++++\n 2 files changed, 45 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex ba5c395d2d8..8d1a713dc4d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1672,8 +1672,17 @@ _git_commit ()\n \t\t\t\" \"\" \"${cur##--cleanup=}\"\n \t\treturn\n \t\t;;\n+\t--fixup=amend:*|--fixup=reword:*)\n+\t\t__git_complete_refs --cur=\"${cur#*:}\"\n+\t\treturn\n+\t\t;;\n+\t--fixup=*)\n+\t\t__git_complete_refs --cur=\"${cur#*=}\"\n+\t\t__gitcomp_direct_append \"$(compgen -W \"amend: reword:\" \"${cur#*=}\")\"\n+\t\treturn\n+\t\t;;\n \t--reuse-message=*|--reedit-message=*|\\\n-\t--fixup=*|--squash=*)\n+\t--squash=*)\n \t\t__git_complete_refs --cur=\"${cur#*=}\"\n \t\treturn\n \t\t;;\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 43de868b800..bb3dcab5d9d 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1444,6 +1444,41 @@ test_expect_success 'git checkout - with --detach, complete only references' '\n \tEOF\n '\n \n+test_expect_success 'git commit - with --fixup=, completes references along with amend: and reword:' '\n+\ttest_completion \"git commit --fixup=\" <<-\\EOF\n+\tHEAD Z\n+\tmain Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/main-in-other Z\n+\tamend:Z\n+\treword:Z\n+\tEOF\n+'\n+\n+test_expect_success 'git commit - with --fixup=amend:, completes references' '\n+\ttest_completion \"git commit --fixup=amend:\" <<-\\EOF\n+\tHEAD Z\n+\tmain Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/main-in-other Z\n+\tEOF\n+'\n+\n+test_expect_success 'git commit - with --fixup=reword:, completes references' '\n+\ttest_completion \"git commit --fixup=reword:\" <<-\\EOF\n+\tHEAD Z\n+\tmain Z\n+\tmatching-branch Z\n+\tmatching-tag Z\n+\tother/branch-in-other Z\n+\tother/main-in-other Z\n+\tEOF\n+'\n+\n test_expect_success 'setup sparse-checkout tests' '\n \t# set up sparse-checkout repo\n \tgit init sparse-checkout &&\n\nbase-commit: 3dcec76d9df911ed8321007b1d197c1a206dc164\n-- \ngitgitgadget\n"}]}