from stgit.commands.common import *
from stgit.utils import *
+from stgit.out import *
from stgit import stack, git, basedir
def __is_current_branch(branch_name):
- return crt_series.get_branch() == branch_name
+ return crt_series.get_name() == branch_name
def __print_branch(branch_name, length):
initialized = ' '
out.start('Deleting branch "%s"' % doomed_name)
if __is_current_branch(doomed_name):
- check_local_changes()
- check_conflicts()
- check_head_top_equal()
-
- if doomed_name != 'master':
- git.switch_branch('master')
+ raise CmdException('Cannot delete the current branch')
doomed.delete(force)
- if doomed_name != 'master':
- git.delete_branch(doomed_name)
-
out.done()
def func(parser, options, args):
tree_id = None
if len(args) >= 2:
+ parentbranch = None
try:
- if git.rev_parse(args[1]) == git.rev_parse('refs/heads/' + args[1]):
- # we are for sure referring to a branch
- parentbranch = 'refs/heads/' + args[1]
- out.info('Recording "%s" as parent branch' % parentbranch)
- elif git.rev_parse(args[1]) and re.search('/', args[1]):
- # FIXME: should the test be more strict ?
- parentbranch = args[1]
- else:
- # Note: this includes refs to StGIT patches
- out.info('Don\'t know how to determine parent branch'
- ' from "%s"' % args[1])
- parentbranch = None
+ 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]
+
except git.GitException:
# should use a more specific exception to catch only
# non-git refs ?
out.info('Don\'t know how to determine parent branch'
' from "%s"' % args[1])
- parentbranch = None
+ # exception in branch = rev_parse() leaves branchpoint unbound
+ branchpoint = None
+
+ tree_id = branchpoint or git_id(args[1])
- tree_id = git_id(args[1])
+ if parentbranch:
+ out.info('Recording "%s" as parent branch' % parentbranch)
+ else:
+ out.info('Don\'t know how to determine parent branch'
+ ' from "%s"' % args[1])
else:
# branch stack off current branch
parentbranch = git.get_head_file()
elif options.clone:
if len(args) == 0:
- clone = crt_series.get_branch() + \
+ clone = crt_series.get_name() + \
time.strftime('-%C%y%m%d-%H%M%S')
elif len(args) == 1:
clone = args[0]
if len(args) != 0:
parser.error('incorrect number of arguments')
- branches = []
- basepath = os.path.join(basedir.get(), 'refs', 'heads')
- for path, files, dirs in walk_tree(basepath):
- branches += [os.path.join(path, f) for f in files]
+ branches = git.get_heads()
branches.sort()
if branches:
elif options.protect:
if len(args) == 0:
- branch_name = crt_series.get_branch()
+ branch_name = crt_series.get_name()
elif len(args) == 1:
branch_name = args[0]
else:
elif options.unprotect:
if len(args) == 0:
- branch_name = crt_series.get_branch()
+ branch_name = crt_series.get_name()
elif len(args) == 1:
branch_name = args[0]
else:
elif options.description is not None:
if len(args) == 0:
- branch_name = crt_series.get_branch()
+ branch_name = crt_series.get_name()
elif len(args) == 1:
branch_name = args[0]
else:
if len(args) != 0:
parser.error('incorrect number of arguments')
- print crt_series.get_branch()
+ print crt_series.get_name()