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 *
from stgit.utils import *
+from stgit.out import *
from stgit import stack, git, basedir
If not given any options, switch to the named branch."""
+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):
- check_local_changes()
- check_conflicts()
- check_head_top_equal()
-
- if doomed_name != 'master':
- git.switch_branch('master')
-
doomed.delete(force)
-
- if doomed_name != 'master':
- git.delete_branch(doomed_name)
-
out.done()
def func(parser, options, args):
check_local_changes()
check_conflicts()
- check_head_top_equal()
+ check_head_top_equal(crt_series)
tree_id = None
if len(args) >= 2:
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 ?
# exception in branch = rev_parse() leaves branchpoint unbound
branchpoint = None
- tree_id = branchpoint or git_id(args[1])
+ tree_id = git_id(crt_series, branchpoint or args[1])
if parentbranch:
out.info('Recording "%s" as parent branch' % parentbranch)
check_local_changes()
check_conflicts()
- check_head_top_equal()
+ check_head_top_equal(crt_series)
out.start('Cloning current branch to "%s"' % clone)
crt_series.clone(clone)
check_local_changes()
check_conflicts()
- check_head_top_equal()
+ check_head_top_equal(crt_series)
out.start('Switching to branch "%s"' % args[0])
git.switch_branch(args[0])