Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-import sys, os, time
+import sys, os, time, re
from optparse import OptionParser, make_option
from stgit.commands.common import *
If not given any options, switch to the named branch."""
-directory = DirectoryHasRepository()
+directory = DirectoryGotoToplevel()
options = [make_option('-c', '--create',
help = 'create a new development branch',
action = 'store_true'),
def __delete_branch(doomed_name, force = False):
doomed = stack.Series(doomed_name)
+ if __is_current_branch(doomed_name):
+ raise CmdException('Cannot delete the current branch')
if doomed.get_protected():
raise CmdException, 'This branch is protected. Delete is not permitted'
out.start('Deleting branch "%s"' % doomed_name)
-
- if __is_current_branch(doomed_name):
- raise CmdException('Cannot delete the current branch')
-
doomed.delete(force)
-
out.done()
def func(parser, options, args):
try:
branchpoint = git.rev_parse(args[1])
- # first, look for branchpoint in well-known branch namespaces
- for namespace in ('refs/heads/', 'remotes/'):
- # check if branchpoint exists in namespace
- try:
- maybehead = git.rev_parse(namespace + args[1])
- except git.GitException:
- maybehead = None
-
- # check if git resolved branchpoint to this namespace
- if maybehead and branchpoint == maybehead:
- # we are for sure referring to a branch
- parentbranch = namespace + args[1]
-
+ # parent branch?
+ head_re = re.compile('refs/(heads|remotes)/')
+ ref_re = re.compile(args[1] + '$')
+ for ref in git.all_refs():
+ if head_re.match(ref) and ref_re.search(ref):
+ # args[1] is a valid ref from the branchpoint
+ # setting above
+ parentbranch = args[1]
+ break;
except git.GitException:
# should use a more specific exception to catch only
# non-git refs ?