+ def get_hidden(self):
+ if not os.path.isfile(self.__hidden_file):
+ return []
+ f = file(self.__hidden_file)
+ names = [line.strip() for line in f.readlines()]
+ f.close()
+ return names
+
+ 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_head(self):
+ """Return the head of the branch
+ """
+ crt = self.get_current_patch()
+ if crt:
+ return crt.get_top()
+ else:
+ return self.get_base()
+
+ def get_protected(self):
+ return os.path.isfile(os.path.join(self._dir(), 'protected'))
+
+ def protect(self):
+ protect_file = os.path.join(self._dir(), 'protected')
+ if not os.path.isfile(protect_file):
+ create_empty_file(protect_file)
+
+ def unprotect(self):
+ protect_file = os.path.join(self._dir(), 'protected')
+ if os.path.isfile(protect_file):
+ os.remove(protect_file)
+
+ def get_description(self):
+ return self._get_field('description') or ''
+
+ def set_description(self, line):
+ self._set_field('description', line)
+
+ def get_parent_remote(self):
+ value = config.get('branch.%s.remote' % self.__name)
+ if value:
+ return value
+ elif 'origin' in git.remotes_list():
+ print 'Notice: no parent remote declared for stack "%s", ' \
+ 'defaulting to "origin". Consider setting "branch.%s.remote" ' \
+ 'and "branch.%s.merge" with "git repo-config".' \
+ % (self.__name, self.__name, self.__name)
+ return 'origin'
+ else:
+ raise StackException, 'Cannot find a parent remote for "%s"' % self.__name
+
+ def __set_parent_remote(self, remote):
+ value = config.set('branch.%s.remote' % self.__name, remote)
+
+ def get_parent_branch(self):
+ value = config.get('branch.%s.stgit.parentbranch' % self.__name)
+ if value:
+ return value
+ elif git.rev_parse('heads/origin'):
+ print 'Notice: no parent branch declared for stack "%s", ' \
+ 'defaulting to "heads/origin". Consider setting ' \
+ '"branch.%s.stgit.parentbranch" with "git repo-config".' \
+ % (self.__name, self.__name)
+ return 'heads/origin'
+ else:
+ raise StackException, 'Cannot find a parent branch for "%s"' % self.__name
+
+ def __set_parent_branch(self, name):
+ if config.get('branch.%s.remote' % self.__name):
+ # Never set merge if remote is not set to avoid
+ # possibly-erroneous lookups into 'origin'
+ config.set('branch.%s.merge' % self.__name, name)
+ config.set('branch.%s.stgit.parentbranch' % self.__name, name)
+
+ def set_parent(self, remote, localbranch):
+ # policy: record local branches as remote='.'
+ recordremote = remote or '.'
+ if localbranch:
+ self.__set_parent_remote(recordremote)
+ self.__set_parent_branch(localbranch)
+ # We'll enforce this later
+# else:
+# raise StackException, 'Parent branch (%s) should be specified for %s' % localbranch, self.__name