git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] completion: Add hook in Bash completion for commit message; tests

From
Mikko Johannes Koivunalho <mikko.koivunalho@iki.fi>
Date
Jun 30, 2024, 21:33 UTC
Message-ID
<20240630213336.2212166-4-mikko.koivunalho@iki.fi>
In-Reply-To
<20240630213336.2212166-1-mikko.koivunalho@iki.fi>
Signed-off-by: Mikko Johannes Koivunalho <mikko.koivunalho@iki.fi>
---
 t/t9902-completion.sh | 68 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 932d5ad759..4ea80fddd2 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -146,6 +146,74 @@ else
 	ROOT="$(pwd)"
 fi
 
+test_expect_success 'setup for commit message completion' "
+    commit-msg-callback-function () { echo HelloFromCallbackFunction; } &&
+    printf '#!/usr/bin/env sh\necho HelloFromCallbackExe\n' >.git/hooks/commit-callback &&
+    chmod +x .git/hooks/commit-callback
+"
+
+test_expect_success 'git commit --message= (empty)' "
+    test_completion 'git commit --message=' ' '
+"
+
+test_expect_success 'setup for commit message completion (run a shell function)' '
+    git config --local completion.commitMessageCallback commit-msg-callback-function
+'
+
+test_expect_success 'git commit --message=HelloFromCallbackFunction' '
+    test_completion "git commit --message=" "HelloFromCallbackFunction"
+'
+
+test_expect_success 'setup for commit message completion (run an executable file)' "
+    git config --local completion.commitMessageCallback \"${PWD}/.git/hooks/commit-callback\"
+"
+
+test_expect_success 'git commit --message=HelloFromCallbackExe' '
+    test_completion "git commit --message=" "HelloFromCallbackExe"
+'
+
+test_expect_success 'setup for commit message completion (do completion in a subdir)' '
+    mkdir -p commit_message_completion_subdir &&
+    cd commit_message_completion_subdir
+'
+
+test_expect_success 'git commit --message=HelloFromCallbackExe' '
+    test_completion "git commit --message=" "HelloFromCallbackExe"
+'
+
+test_expect_success 'teardown from commit message completion (do completion in a subdir)' '
+    cd .. &&
+    rm -r commit_message_completion_subdir
+'
+
+test_expect_success 'setup for commit message completion (run an executable file with ENV var set)' "
+    GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK=commit-msg-callback-function &&
+    export GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK
+"
+
+test_expect_success 'git commit --message=HelloFromCallbackFunction (ENV var overrides config)' '
+    test_completion "git commit --message=" "HelloFromCallbackFunction"
+'
+
+test_expect_success 'setup for commit message completion (completion begins with quote char)' '
+    commit-msg-callback-function-with-quote () { echo \"HelloFromCallbackFunctionWithQuote; } &&
+    GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK=commit-msg-callback-function-with-quote &&
+    export GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK
+'
+
+test_expect_success 'git commit --message=HelloFromCallbackFunction (completion begins with quote char)' '
+    test_completion "git commit --message=" "\"HelloFromCallbackFunctionWithQuote"
+'
+
+test_expect_success 'teardown after commit message completion' '
+    unset -v GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK &&
+    git config --local --unset completion.commitMessageCallback &&
+    unset -f commit-msg-callback-function &&
+    unset -f commit-msg-callback-function-with-quote &&
+    rm .git/hooks/commit-callback
+
+'
+
 test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
 	mkdir -p subdir/subsubdir &&
 	mkdir -p non-repo &&
-- 
2.30.2
Previous: Mikko Johannes KoivunalhoNext: Mikko Johannes Koivunalho
Message 3 of 6 in “Add a Hook To git commit --message Bash Completion”
  1. 0/3 Add a Hook To git commit --message Bash CompletionMikko Johannes Koivunalho, Jun 30, 2024
  2. 2/3 completion: Add hook in Bash completion for commit message; docsMikko Johannes Koivunalho, Jun 30, 2024
  3. 3/3 completion: Add hook in Bash completion for commit message; testsMikko Johannes Koivunalho, Jun 30, 2024
  4. 1/3 completion: Add hook in Bash completion for commit messageMikko Johannes Koivunalho, Jun 30, 2024
  5. brian m. carlsonJun 30, 2024
  6. Mikko Johannes KoivunalhoJun 30, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.