The commit-msg hook is important for gerrit users, where it
generates a Change-Id.
The following I tested on Windows, where running the script is a bit tricky
because it usually is a shell script. Thus I needed to prepend "bash". I
think the best approach might be to parse the script for the hash bang and
then attempt to find and execute the appropriate binary with the script as
argument. Please take a look!
Patch below:
diff --git a/stgit/commands/new.py b/stgit/commands/new.py
index d5c5382..3328042 100644
--- a/stgit/commands/new.py
+++ b/stgit/commands/new.py
@@ -20,6 +20,7 @@ from stgit import argparse, utils
from stgit.commands import common
from stgit.lib import git as gitlib, transaction
from stgit.config import config
+from stgit.lib import edit
help = 'Create a new, empty patch'
kind = 'patch'
@@ -69,6 +70,9 @@ def func(parser, options, args):
author = gitlib.Person.author(), committer =
gitlib.Person.committer())
cd = common.update_commit_data(cd, options)
+ # run the commit-msg hook
+ cd = cd.set_message(edit.run_commit_msg_hook(stack.repository,
cd.message))
+
if options.save_template:
options.save_template(cd.message)
return utils.STGIT_SUCCESS
diff --git a/stgit/lib/edit.py b/stgit/lib/edit.py
index c8d29f6..5993754 100644
--- a/stgit/lib/edit.py
+++ b/stgit/lib/edit.py
@@ -3,6 +3,31 @@
from stgit import utils
from stgit.commands import common
from stgit.lib import git
+from stgit import run
+from tempfile import NamedTemporaryFile
+import os
+
+def run_commit_msg_hook(repo, message):
+ """Run the commit-msg git hook manually when editing a patch.
+
+ Return the edited commit message, or the original message if there
+ is no commit-msg hook."""
+
+ hook_path = os.path.join(repo.directory, 'hooks', 'commit-msg')
+
+ if not os.access(hook_path, os.X_OK):
+ return message
+
+ # message hook exists, make a temporary file and run on the temp file
+ tf = NamedTemporaryFile("w", delete=False)
+ tf.write(message)
+ tf.close()
+
+ run.Run('bash', hook_path, tf.name).run()
+ new_msg = open(tf.name, 'r').read()
+ os.remove(tf.name)
+
+ return new_msg
def update_patch_description(repo, cd, text, contains_diff):
"""Update the given L{CommitData<stgit.lib.git.CommitData>} with the
@@ -19,7 +44,7 @@ def update_patch_description(repo, cd, text,
contains_diff):
(git.Date.maybe(authdate), 'set_date')]:
if val != None:
a = getattr(a, setter)(val)
- cd = cd.set_message(message).set_author(a)
+ cd = cd.set_message(run_commit_msg_hook(repo, message)).set_author(a)
failed_diff = None
if diff:
tree = repo.apply(cd.parent.data.tree, diff, quiet = False)
_______________________________________________
stgit-users mailing list
[email protected]
https://mail.gna.org/listinfo/stgit-users