X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/8866fedad702f33cbeaf83d18ab120f3a76922f5..c0167829ce790a0812f16ae03d1c7c7bd7b14560:/stgit/stack.py diff --git a/stgit/stack.py b/stgit/stack.py index dbdda01..6f0f67a 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -import sys, os +import sys, os, re from stgit.utils import * from stgit import git, basedir, templates @@ -328,6 +328,12 @@ class Series(StgitObject): if self.is_initialised() and not os.path.isdir(self.__trash_dir): os.makedirs(self.__trash_dir) + def __patch_name_valid(self, name): + """Raise an exception if the patch name is not valid. + """ + if not name or re.search('[^\w.-]', name): + raise StackException, 'Invalid patch name: "%s"' % name + def get_branch(self): """Return the branch name for the Series object """ @@ -408,7 +414,16 @@ class Series(StgitObject): self._set_field('description', line) def get_parent_remote(self): - return config.get('branch.%s.remote' % self.__name) or 'origin' + 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" with "git repo-config".' \ + % (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) @@ -418,6 +433,9 @@ class Series(StgitObject): 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.merge" with "git repo-config".' \ + % (self.__name, self.__name) return 'heads/origin' else: raise StackException, 'Cannot find a parent branch for "%s"' % self.__name @@ -753,6 +771,8 @@ class Series(StgitObject): before_existing = False, refresh = True): """Creates a new patch """ + self.__patch_name_valid(name) + if self.patch_applied(name) or self.patch_unapplied(name): raise StackException, 'Patch "%s" already exists' % name @@ -809,6 +829,7 @@ class Series(StgitObject): def delete_patch(self, name): """Deletes a patch """ + self.__patch_name_valid(name) patch = Patch(name, self.__patch_dir, self.__refs_dir) if self.__patch_is_current(patch): @@ -1084,6 +1105,7 @@ class Series(StgitObject): def empty_patch(self, name): """Returns True if the patch is empty """ + self.__patch_name_valid(name) patch = Patch(name, self.__patch_dir, self.__refs_dir) bottom = patch.get_bottom() top = patch.get_top() @@ -1097,6 +1119,8 @@ class Series(StgitObject): return False def rename_patch(self, oldname, newname): + self.__patch_name_valid(newname) + applied = self.get_applied() unapplied = self.get_unapplied()