From 601daf60f74529ae242a11308e167c288aa46a14 Mon Sep 17 00:00:00 2001 From: James Douglass Date: Sun, 26 Jan 2020 17:25:07 -0800 Subject: [PATCH] Adding a new plugin to overwrite null messages. --- plugins/overwrite_null_messages/README.md | 23 +++++++++++++++++++++ plugins/overwrite_null_messages/__init__.py | 16 ++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 plugins/overwrite_null_messages/README.md create mode 100644 plugins/overwrite_null_messages/__init__.py diff --git a/plugins/overwrite_null_messages/README.md b/plugins/overwrite_null_messages/README.md new file mode 100644 index 0000000..9fc1b8a --- /dev/null +++ b/plugins/overwrite_null_messages/README.md @@ -0,0 +1,23 @@ +## Overwrite Null Commit Messages + +There are cases (such as when creating a new, empty snippet on bitbucket +before they deprecated mercurial repositories) where you could create a +new repo with a single commit in it, but the message would be null. Then, +when attempting to convert this repository to a git repo and pushing to +a new host, the git push would fail with an error like this: + + error: a NUL byte in commit log message not allowed + +To get around this, you may provide a string that will be used in place of +a null byte in commit messages. + +To use the plugin, add + + --plugin overwrite_null_messages="" + +This will use the default commit message `""`. + +Or to specify a different commit message, you may pass this in at the +command line like so: + + --plugin overwrite_null_messages="use this message instead" diff --git a/plugins/overwrite_null_messages/__init__.py b/plugins/overwrite_null_messages/__init__.py new file mode 100644 index 0000000..3be7e53 --- /dev/null +++ b/plugins/overwrite_null_messages/__init__.py @@ -0,0 +1,16 @@ +def build_filter(args): + return Filter(args) + +class Filter: + def __init__(self, args): + if args == '': + message = '' + else: + message = args + self.message = message + + def commit_message_filter(self,commit_data): + # Only write the commit message if the recorded commit + # message is null. + if commit_data['desc'] == '\x00': + commit_data['desc'] = self.message