from stgit.utils import *
from stgit.out import *
+from stgit.run import *
from stgit import git, basedir, templates
from stgit.config import config
from shutil import copyfile
author_name = None, author_email = None, author_date = None,
committer_name = None, committer_email = None,
before_existing = False):
- """Creates a new patch
+ """Creates a new patch, either pointing to an existing commit object,
+ or by creating a new commit object.
"""
+ assert commit or (top and bottom)
+ assert not before_existing or (top and bottom)
+ assert not (commit and before_existing)
+ assert (top and bottom) or (not top and not bottom)
+ assert not top or (bottom == git.get_commit(top).get_parent())
+
if name != None:
self.__patch_name_valid(name)
if self.patch_exists(name):
patch = self.get_patch(name)
patch.create()
- if not bottom:
- bottom = head
- if not top:
- top = head
-
- patch.set_bottom(bottom)
- patch.set_top(top)
patch.set_description(descr)
patch.set_authname(author_name)
patch.set_authemail(author_email)
if before_existing:
insert_string(self.__applied_file, patch.get_name())
- # no need to commit anything as the object is already
- # present (mainly used by 'uncommit')
- commit = False
elif unapplied:
patches = [patch.get_name()] + self.get_unapplied()
write_strings(self.__unapplied_file, patches)
set_head = True
if commit:
+ if top:
+ top_commit = git.get_commit(top)
+ else:
+ bottom = head
+ top_commit = git.get_commit(head)
+
# create a commit for the patch (may be empty if top == bottom);
# only commit on top of the current branch
assert(unapplied or bottom == head)
- top_commit = git.get_commit(top)
commit_id = git.commit(message = descr, parents = [bottom],
cache_update = False,
tree_id = top_commit.get_tree(),
committer_name = committer_name,
committer_email = committer_email)
# set the patch top to the new commit
+ patch.set_bottom(bottom)
patch.set_top(commit_id)
+ else:
+ assert top != bottom
+ patch.set_bottom(bottom)
+ patch.set_top(top)
self.log_patch(patch, 'new')