diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-11-24 16:15:40 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-11-24 16:15:40 +0100 |
commit | 279d162f54b5156c442c878dee2450f8137d0fe3 (patch) | |
tree | 0b89fb29494137ca04c582fa80b89e6a5b4f787c /lib/git/index.py | |
parent | 1194dc4322e15a816bfa7731a9487f67ba1a02aa (diff) | |
download | gitpython-279d162f54b5156c442c878dee2450f8137d0fe3.tar.gz |
commit: added create_from_tree method to untie commit creation from actually using the current index. This makes it more flexible. For convenience, the index.commit method is still available, it delgates all the work
Diffstat (limited to 'lib/git/index.py')
-rw-r--r-- | lib/git/index.py | 53 |
1 files changed, 4 insertions, 49 deletions
diff --git a/lib/git/index.py b/lib/git/index.py index 930f2c75..b3dd12fd 100644 --- a/lib/git/index.py +++ b/lib/git/index.py @@ -995,58 +995,13 @@ class IndexFile(LazyMixin, diff.Diffable): """ Commit the current index, creating a commit object. - ``message`` - Commit message. It may be an empty string if no message is provided. - It will be converted to a string in any case. - - ``parent_commits`` - Optional Commit objects to use as parents for the new commit. - If empty list, the commit will have no parents at all and become - a root commit. - If None , the current head commit will be the parent of the - new commit object - - ``head`` - If True, the HEAD will be advanced to the new commit automatically. - Else the HEAD will remain pointing on the previous commit. This could - lead to undesired results when diffing files. - + For more information on the arguments, see tree.commit. + Returns Commit object representing the new commit - - Note: - Additional information about hte committer and Author are taken from the - environment or from the git configuration, see git-commit-tree for - more information """ - parents = parent_commits - if parent_commits is None: - parent_commits = [ self.repo.head.commit ] - - parent_args = [ ("-p", str(commit)) for commit in parent_commits ] - - # create message stream - tmp_file_path = tempfile.mktemp() - fp = open(tmp_file_path,"wb") - fp.write(str(message)) - fp.close() - fp = open(tmp_file_path,"rb") - fp.seek(0) - - try: - # write the current index as tree - tree_sha = self.repo.git.write_tree() - commit_sha = self.repo.git.commit_tree(tree_sha, parent_args, istream=fp) - new_commit = Commit(self.repo, commit_sha) - - if head: - self.repo.head.commit = new_commit - # END advance head handling - - return new_commit - finally: - fp.close() - os.remove(tmp_file_path) + tree_sha = self.repo.git.write_tree() + return Commit.create_from_tree(self.repo, tree_sha, message, parent_commits, head) @classmethod def _flush_stdin_and_wait(cls, proc): |