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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Mikko Johannes Koivunalho <mikko.koivunalho@xxxxxx>
---
 contrib/completion/git-completion.bash | 40 ++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 60a22d619a..5350531c8f 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -81,6 +81,34 @@
 #     case insensitively, even on systems with case sensitive file systems
 #     (e.g., completing tag name "FOO" on "git checkout f<TAB>").
 
+#   GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK
+#
+#     Name of an executable or a script which returns a commit message.
+#     Use this, for example, to always start a commit message with a predefined
+#     prefix. Example:
+#     # Extract Jira ticket number from branch name:
+#     extract_ticket () {
+#       if [[ "$(git rev-parse --symbolic-full-name HEAD)" =~ ([[:alpha:]]{3,}-[[:digit:]]{1,}) ]]
+#       then
+#         echo "\"${BASH_REMATCH[1]^^} "
+#       fi
+#     }
+#     GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK=extract_ticket
+#     # Doing commit:
+#     git commit --message=<TAB>
+#     # you would get (without the closing double quote):
+#     git commit --message="ABC-1234
+#
+# You can set the following Git configuration variables to influence the behavior of
+# the completion routines:
+#
+#   completion.commitMessageCallback
+#
+#     Name of an executable, script or shell functions which returns a commit message.
+#     See above environment variable GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK.
+#     The config variable gets overriden by the environment variable if latter is present.
+#
+
 case "$COMP_WORDBREAKS" in
 *:*) : great ;;
 *)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
@@ -1824,6 +1852,18 @@ _git_commit ()
 			" "" "${cur##--cleanup=}"
 		return
 		;;
+	--message=*)
+		if test -n "${GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK-}"
+		then
+			__gitcomp_direct_append "$(${GIT_COMPLETION_COMMIT_MESSAGE_CALLBACK})"
+		elif test -n "$(__git config completion.commitMessageCallback)"
+		then
+			__gitcomp_direct_append "$("$(__git config completion.commitMessageCallback)")"
+		else
+			__gitcomp_direct_append " "
+		fi
+		return
+		;;
 	--reuse-message=*|--reedit-message=*|\
 	--fixup=*|--squash=*)
 		__git_complete_refs --cur="${cur#*=}"
-- 
2.30.2





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux