diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2017-11-19 15:57:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-19 15:57:17 +0100 |
commit | d91ae75401b851b71fcc6f4dcf7eb29ed2a63369 (patch) | |
tree | a56d103e434f06ded3fde16f8dfa3706a6beebec /git/index/base.py | |
parent | 610d4c97485d2c0d4f65b87f2620a84e0df99341 (diff) | |
parent | eae04bf7b0620a0ef950dd39af7f07f3c88fd15f (diff) | |
download | gitpython-d91ae75401b851b71fcc6f4dcf7eb29ed2a63369.tar.gz |
Merge pull request #693 from satahippy/master
commit-msg hook support
Diffstat (limited to 'git/index/base.py')
-rw-r--r-- | git/index/base.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/git/index/base.py b/git/index/base.py index 4fee2aae..a9e3a3c7 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -948,6 +948,11 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): :return: Commit object representing the new commit""" if not skip_hooks: run_commit_hook('pre-commit', self) + + self._write_commit_editmsg(message) + run_commit_hook('commit-msg', self, self._commit_editmsg_filepath()) + message = self._read_commit_editmsg() + self._remove_commit_editmsg() tree = self.write_tree() rval = Commit.create_from_tree(self.repo, tree, message, parent_commits, head, author=author, committer=committer, @@ -955,6 +960,20 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): if not skip_hooks: run_commit_hook('post-commit', self) return rval + + def _write_commit_editmsg(self, message): + with open(self._commit_editmsg_filepath(), "wb") as commit_editmsg_file: + commit_editmsg_file.write(message.encode(defenc)) + + def _remove_commit_editmsg(self): + os.remove(self._commit_editmsg_filepath()) + + def _read_commit_editmsg(self): + with open(self._commit_editmsg_filepath(), "rb") as commit_editmsg_file: + return commit_editmsg_file.read().decode(defenc) + + def _commit_editmsg_filepath(self): + return osp.join(self.repo.common_dir, "COMMIT_EDITMSG") @classmethod def _flush_stdin_and_wait(cls, proc, ignore_stdout=False): |