+ def get_unapplied(self):
+ if not os.path.isfile(self.__unapplied_file):
+ raise StackException, 'Branch "%s" not initialised' % self.get_name()
+ return read_strings(self.__unapplied_file)
+
+ def set_unapplied(self, unapplied):
+ write_strings(self.__unapplied_file, unapplied)
+
+ def get_hidden(self):
+ if not os.path.isfile(self.__hidden_file):
+ return []
+ return read_strings(self.__hidden_file)
+
+ def get_base(self):
+ # Return the parent of the bottommost patch, if there is one.
+ if os.path.isfile(self.__applied_file):
+ bottommost = file(self.__applied_file).readline().strip()
+ if bottommost:
+ return self.get_patch(bottommost).get_bottom()
+ # No bottommost patch, so just return HEAD
+ return git.get_head()
+
+ def get_parent_remote(self):
+ value = config.get('branch.%s.remote' % self.get_name())
+ if value:
+ return value
+ elif 'origin' in git.remotes_list():
+ out.note(('No parent remote declared for stack "%s",'
+ ' defaulting to "origin".' % self.get_name()),
+ ('Consider setting "branch.%s.remote" and'
+ ' "branch.%s.merge" with "git config".'
+ % (self.get_name(), self.get_name())))
+ return 'origin'
+ else:
+ raise StackException, 'Cannot find a parent remote for "%s"' % self.get_name()
+
+ def __set_parent_remote(self, remote):
+ value = config.set('branch.%s.remote' % self.get_name(), remote)
+
+ def get_parent_branch(self):
+ value = config.get('branch.%s.stgit.parentbranch' % self.get_name())
+ if value:
+ return value
+ elif git.rev_parse('heads/origin'):
+ out.note(('No parent branch declared for stack "%s",'
+ ' defaulting to "heads/origin".' % self.get_name()),
+ ('Consider setting "branch.%s.stgit.parentbranch"'
+ ' with "git config".' % self.get_name()))
+ return 'heads/origin'
+ else:
+ raise StackException, 'Cannot find a parent branch for "%s"' % self.get_name()
+
+ def __set_parent_branch(self, name):
+ if config.get('branch.%s.remote' % self.get_name()):
+ # Never set merge if remote is not set to avoid
+ # possibly-erroneous lookups into 'origin'
+ config.set('branch.%s.merge' % self.get_name(), name)
+ config.set('branch.%s.stgit.parentbranch' % self.get_name(), name)
+
+ def set_parent(self, remote, localbranch):
+ if localbranch:
+ if remote:
+ self.__set_parent_remote(remote)
+ self.__set_parent_branch(localbranch)
+ # We'll enforce this later
+# else:
+# raise StackException, 'Parent branch (%s) should be specified for %s' % localbranch, self.get_name()