Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo Specific Prepare Commit #564

Zren opened this issue Feb 15, 2019 · 0 comments


None yet
1 participant
Copy link

commented Feb 15, 2019

I recently found out about the power of .git/hooks/prepare-commit-msg but found out this plugin doesn't support it. So I modified this plugin to look for .git/hooks/SublimeTextGit-prepare-commit-msg use the contents of that file for the commit message. Unlike the other hooks, it's not a bash script which makes it easier to setup.

diff --git a/git/ b/git/
index 90eb726..0cfcefd 100644
--- a/git/
+++ b/git/
@@ -8,6 +8,7 @@ import os
 import sublime
 import sublime_plugin
 from . import GitTextCommand, GitWindowCommand, plugin_file, view_contents, _make_text_safeish
+from . import git_root
 from .add import GitAddSelectedHunkCommand
 history = []
@@ -106,6 +107,19 @@ class GitCommitCommand(GitWindowCommand):
         if not len(self.lines):
             self.lines = ["", ""]
+        if self.get_working_dir():
+            git_root_dir = git_root(self.get_working_dir())
+        else:
+            git_root_dir = self.active_view().settings().get("git_root_dir")
+        if git_root_dir:
+            prepareCommitFilepath = os.path.join(git_root_dir, '.git', 'hooks', 'SublimeTextGit-prepare-commit-msg')
+            if os.path.exists(prepareCommitFilepath):
+                with open(prepareCommitFilepath, "r") as fin:
+                    self.lines ='\n')
+                    self.lines.extend([""])
         self.lines.extend(map(format, history[:historySize]))
             "# --------------",

My example .git/hooks/SublimeTextGit-prepare-commit-msg

# BUG: 1234


# Differential Revision:

I'm not sure if this is a feature you'd consider merging (and I've no idea what the proper filepath should be). I didn't see anyone ask for this feature however so it might be easier to not add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.