def get_name(self):
return self.__name
+ def rename(self, newname):
+ olddir = self.__dir
+ self.__name = newname
+ self.__dir = os.path.join(self.__patch_dir, self.__name)
+
+ os.rename(olddir, self.__dir)
+
def __get_field(self, name, multiline = False):
id_file = os.path.join(self.__dir, name)
if os.path.isfile(id_file):
"""
if len(self.get_applied()) == 0:
head = git.get_head()
- if os.path.exists(self.__base_file):
- raise StackException, 'stack empty but the base file exists'
write_string(self.__base_file, head)
def __end_stack_check(self):
- """Remove .git/refs/heads/base if the stack is empty
+ """Remove .git/refs/heads/base if the stack is empty.
+ This warning should never happen
"""
- if len(self.get_applied()) == 0:
- if not os.path.exists(self.__base_file):
- print 'Warning: stack empty but the base file is missing'
- else:
- os.remove(self.__base_file)
+ if len(self.get_applied()) == 0 \
+ and read_string(self.__base_file) != git.get_head():
+ print 'Warning: stack empty but the HEAD and base are different'
def head_top_equal(self):
"""Return true if the head and the top are the same
create_empty_file(self.__applied_file)
create_empty_file(self.__unapplied_file)
+ self.__begin_stack_check()
- def refresh_patch(self, message = None, edit = False,
+ def refresh_patch(self, message = None, edit = False, cache_update = True,
author_name = None, author_email = None,
author_date = None,
- committer_name = None, committer_email = None):
+ committer_name = None, committer_email = None,
+ commit_only = False):
"""Generates a new commit for the given patch
"""
name = self.get_current()
committer_email = patch.get_commemail()
commit_id = git.commit(message = descr, parents = [patch.get_bottom()],
+ cache_update = cache_update,
allowempty = True,
author_name = author_name,
author_email = author_email,
committer_name = committer_name,
committer_email = committer_email)
- patch.set_top(commit_id)
- patch.set_description(descr)
- patch.set_authname(author_name)
- patch.set_authemail(author_email)
- patch.set_authdate(author_date)
- patch.set_commname(committer_name)
- patch.set_commemail(committer_email)
+ if not commit_only:
+ patch.set_top(commit_id)
+ patch.set_description(descr)
+ patch.set_authname(author_name)
+ patch.set_authemail(author_email)
+ patch.set_authdate(author_date)
+ patch.set_commname(committer_name)
+ patch.set_commemail(committer_email)
+
+ return commit_id
def new_patch(self, name, message = None, edit = False,
author_name = None, author_email = None, author_date = None,
self.__set_current(name)
- if not ex:
- # if the merge was OK and no conflicts, just refresh the patch
- self.refresh_patch()
- else:
- raise StackException, str(ex)
+ # head == bottom case doesn't need to refresh the patch
+ if head != bottom:
+ if not ex:
+ # if the merge was OK and no conflicts, just refresh the patch
+ # The GIT cache was already updated by the merge operation
+ self.refresh_patch(cache_update = False)
+ else:
+ raise StackException, str(ex)
def undo_push(self):
name = self.get_current()
assert(name)
patch = Patch(name, self.__patch_dir)
+ git.reset()
self.pop_patch(name)
patch.restore_old_boundaries()
if bottom == top:
return True
- elif git.Commit(top).get_tree() == git.Commit(bottom).get_tree():
+ elif git.get_commit(top).get_tree() \
+ == git.get_commit(bottom).get_tree():
return True
return False
+
+ def rename_patch(self, oldname, newname):
+ applied = self.get_applied()
+ unapplied = self.get_unapplied()
+
+ if newname in applied or newname in unapplied:
+ raise StackException, 'Patch "%s" already exists' % newname
+
+ if oldname in unapplied:
+ Patch(oldname, self.__patch_dir).rename(newname)
+ unapplied[unapplied.index(oldname)] = newname
+
+ f = file(self.__unapplied_file, 'w+')
+ f.writelines([line + '\n' for line in unapplied])
+ f.close()
+ elif oldname in applied:
+ Patch(oldname, self.__patch_dir).rename(newname)
+ if oldname == self.get_current():
+ self.__set_current(newname)
+
+ applied[applied.index(oldname)] = newname
+
+ f = file(self.__applied_file, 'w+')
+ f.writelines([line + '\n' for line in applied])
+ f.close()
+ else:
+ raise StackException, 'Unknown patch "%s"' % oldname