{"thread":{"id":"28740","subject":"[PATCH] git-svn: add hook to allow modifying the subversion commit message","startedAt":"2011-10-21T20:25:08Z","lastAt":"2011-11-01T20:45:43Z","messageCount":3,"participants":["Michael Lutz","Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"178146","messageId":"1319228708-9052-1-git-send-email-michi@icosahedron.de","threadId":"28740","inReplyTo":null,"subject":"[PATCH] git-svn: add hook to allow modifying the subversion commit message","fromName":"Michael Lutz","fromEmail":"michi@icosahedron.de","sentAt":"2011-10-21T20:25:08Z","receivedAt":"2011-10-21T20:25:08Z","isPatch":true,"sender":{"key":"michi@icosahedron.de","avatar":"https://avatars.githubusercontent.com/u/1447653?v=4"},"body":"Sometimes modifying the commit message git-svn creates for a subversion\ncommit can be useful, for example if the original message contains meta\ninformation not needed in the git clone or information from svn properties\nshould be stored visibly in the commit message.\n\nThis change adds a hook 'git-svn-msg' analogue to the 'commit-msg' hook.\nAdditionally to the commit message, the hook is passed the git-svn meta\ndata by an environment variable.\n\nSigned-off-by: Michael Lutz <michi@icosahedron.de>\n---\n Documentation/githooks.txt          |   19 +++++++++++++++++++\n git-svn.perl                        |   25 +++++++++++++++++++++++++\n templates/hooks--git-svn-msg.sample |   18 ++++++++++++++++++\n 3 files changed, 62 insertions(+), 0 deletions(-)\n create mode 100755 templates/hooks--git-svn-msg.sample\n\ndiff --git a/Documentation/githooks.txt b/Documentation/githooks.txt\nindex 28edefa..dd90c1a 100644\n--- a/Documentation/githooks.txt\n+++ b/Documentation/githooks.txt\n@@ -45,6 +45,25 @@ the commit after inspecting the message file.\n The default 'applypatch-msg' hook, when enabled, runs the\n 'commit-msg' hook, if the latter is enabled.\n \n+git-svn-msg\n+~~~~~~~~~~~\n+\n+This hook is invoked by 'git svn' when creating a git commit\n+from a subversion commit.  It takes a single parameter, the name\n+of the file that holds the original subversion commit message.\n+Exiting with non-zero status causes 'git svn' to abbort before\n+creating the git commit. Additional, the environment variable\n+`GIT_SVN_METADATA=:` is set to the string that would appear\n+after the 'git-svn-id:' line.\n+\n+The hook is allowed to edit the message file in place, and can\n+be used to normalize the message into some project standard\n+format (if the project has one). It can also be used to refuse\n+the commit after inspecting the message file.\n+\n+The default 'git-svn-msg' hook, when enabled, runs the\n+'commit-msg' hook, if the latter is enabled.\n+\n pre-applypatch\n ~~~~~~~~~~~~~~\n \ndiff --git a/git-svn.perl b/git-svn.perl\nindex b67fef0..030516c 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -3007,6 +3007,31 @@ sub do_git_commit {\n \t\trequire Encode;\n \t\tEncode::from_to($log_entry->{log}, 'UTF-8', $enc);\n \t}\n+\n+\t# execute commit message hook if present\n+\tif (-x \"$ENV{GIT_DIR}/hooks/git-svn-msg\") {\n+\t\tprint \"Calling commit mesasage hook\\n\";\n+\n+\t\t# write commit message to file\n+\t\tmy $msg_file = \"$ENV{GIT_DIR}/SVN_COMMIT_EDITMSG\";\n+\t\tmkfile($msg_file);\n+\t\topen my $fh, '>', $msg_file or croak $!;\n+\t\tbinmode $fh;\n+\t\tprint $fh $log_entry->{log} or croak $!;\n+\t\tclose $fh or croak $!;\n+\n+\t\t$ENV{GIT_SVN_METADATA} = $log_entry->{metadata};\n+\t\tsystem(\"$ENV{GIT_DIR}/hooks/git-svn-msg\", $msg_file);\n+\t\tdie \"git-svn-msg hook failed: $!\\n\" if $?;\n+\n+\t\t# read commit message back\n+\t\topen $fh, '<', $msg_file or croak $!;\n+\t\tbinmode $fh;\n+\t\t$log_entry->{log} = do { local $/; <$fh> };\n+\t\tclose $fh or croak $!;\n+\t\tunlink $msg_file;\n+\t}\n+\n \tprint $msg_fh $log_entry->{log} or croak $!;\n \trestore_commit_header_env($old_env);\n \tunless ($self->no_metadata) {\ndiff --git a/templates/hooks--git-svn-msg.sample b/templates/hooks--git-svn-msg.sample\nnew file mode 100755\nindex 0000000..6584fd8\n--- /dev/null\n+++ b/templates/hooks--git-svn-msg.sample\n@@ -0,0 +1,18 @@\n+#!/bin/sh\n+#\n+# An example hook script to check the commit log message taken by\n+# git svn from a subversion commit.\n+#\n+# The hook should exit with non-zero status after issuing an\n+# appropriate message if it wants to stop the commit.  The hook is\n+# allowed to edit the commit message file.\n+#\n+# GIT_SVN_METADATA will contain the same info as printed after\n+# the git-svn-id line.\n+#\n+# To enable this hook, rename this file to \"git-svn-msg\".\n+\n+. git-sh-setup\n+test -x \"$GIT_DIR/hooks/commit-msg\" &&\n+\texec \"$GIT_DIR/hooks/commit-msg\" ${1+\"$@\"}\n+:\n-- \n1.7.5.1\n"},{"id":"178643","messageId":"20111101202806.GB29769@dcvr.yhbt.net","threadId":"28740","inReplyTo":"1319228708-9052-1-git-send-email-michi@icosahedron.de","subject":"Re: [PATCH] git-svn: add hook to allow modifying the subversion commit message","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2011-11-01T20:28:06Z","receivedAt":"2011-11-01T20:28:06Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Michael Lutz <michi@icosahedron.de> wrote:\n> Sometimes modifying the commit message git-svn creates for a subversion\n> commit can be useful, for example if the original message contains meta\n> information not needed in the git clone or information from svn properties\n> should be stored visibly in the commit message.\n> \n> This change adds a hook 'git-svn-msg' analogue to the 'commit-msg' hook.\n> Additionally to the commit message, the hook is passed the git-svn meta\n> data by an environment variable.\n\nI'm not convinced this is a good feature to support.  We already have\n--no-metadata to remove git-svn-id: lines and I hate that feature\nbecause it introduced extra variables for testing/debugging/recovery.\n\nMetadata in the commit message is important, if you want to remove\nit after-the-fact, there's git-filter-branch.\n\nWhen dealing with repositories that have been through several systems\n(e.g. (CVS|Perforce) -> SVN -> git), it's useful to be able to refer to\nold mailing list archives that only refer to the original system (since\nneither SVN nor git existed at the time the email was sent).\n"},{"id":"178646","messageId":"4EB05A77.4050901@icosahedron.de","threadId":"28740","inReplyTo":"20111101202806.GB29769@dcvr.yhbt.net","subject":"Re: [PATCH] git-svn: add hook to allow modifying the subversion commit message","fromName":"Michael Lutz","fromEmail":"michi@icosahedron.de","sentAt":"2011-11-01T20:45:43Z","receivedAt":"2011-11-01T20:45:43Z","isPatch":true,"sender":{"key":"michi@icosahedron.de","avatar":"https://avatars.githubusercontent.com/u/1447653?v=4"},"body":"Am 01.11.2011 21:28 schrieb Eric Wong:\n> I'm not convinced this is a good feature to support.  We already have\n> --no-metadata to remove git-svn-id: lines and I hate that feature\n> because it introduced extra variables for testing/debugging/recovery.\n> \n> Metadata in the commit message is important, if you want to remove\n> it after-the-fact, there's git-filter-branch.\n\nThe actual use case here is to replace a custom hack that adds some info\nto the git commit message. In this case filter-branch isn't an option\nbecause git-svn continuously pulls from the subversion master repository.\nAdditionally, especially for *adding* information, the information might\nnot be available later any more.\n\nThe only current metadata (the git-svn-id line) isn't affected by this\nchange as git-svn outputs it separately after the svn commit message that\nthe proposed hook can modify.\n\nI fully realize that this is a rather specialized feature but I wanted to\npublish it in case somebody else finds a use for this as well.\n\n\nMichael Lutz\n"}]}