make_option('-l', '--list',
help = 'list branches contained in this repository',
action = 'store_true'),
+ make_option('-p', '--protect',
+ help = 'prevent "stg pull" from modifying this branch',
+ action = 'store_true'),
make_option('-r', '--rename',
help = 'rename an existing development branch',
+ action = 'store_true'),
+ make_option('-u', '--unprotect',
+ help = 'allow "stg pull" to modify this branch',
action = 'store_true')]
def print_branch(branch_name):
initialized = ' '
current = ' '
+ protected = ' '
+
+ branch = stack.Series(branch_name)
+
if os.path.isdir(os.path.join(git.base_dir, 'patches', branch_name)):
initialized = 's'
if is_current_branch(branch_name):
current = '>'
- print '%s %s\t%s' % (current, initialized, branch_name)
+ if branch.get_protected():
+ protected = 'p'
+ print '%s %s%s\t%s\t%s' % (current, initialized, protected, branch_name, \
+ branch.get_description())
def delete_branch(doomed_name, force = False):
+ doomed = stack.Series(doomed_name)
+
+ if doomed.get_protected():
+ raise CmdException, 'This branch is protected. Delete is not permitted'
+
if is_current_branch(doomed_name) and doomed_name != 'master':
git.switch_branch('master')
- stack.Series(doomed_name).delete(force)
+ doomed.delete(force)
if doomed_name != 'master':
git.delete_branch(doomed_name)
print_branch(i)
return
+ elif options.protect:
+
+ if len(args) == 0:
+ branch = git.get_head_file()
+ elif len(args) == 1:
+ branch = args[0]
+ else:
+ parser.error('incorrect number of arguments')
+
+ base = os.path.join(git.base_dir, 'refs', 'bases', branch)
+ if not os.path.isfile(base):
+ raise CmdException, 'Branch "%s" is not controlled by StGit' % branch
+
+ print 'Protecting branch "%s"...' % branch,
+ sys.stdout.flush()
+ stack.Series(branch).protect()
+ print 'done'
+
+ return
+
elif options.rename:
if len(args) != 2:
rename_branch(args[0], args[1])
return
+ elif options.unprotect:
+
+ if len(args) == 0:
+ branch = git.get_head_file()
+ elif len(args) == 1:
+ branch = args[0]
+ else:
+ parser.error('incorrect number of arguments')
+
+ base = os.path.join(git.base_dir, 'refs', 'bases', branch)
+ if not os.path.isfile(base):
+ raise CmdException, 'Branch "%s" is not controlled by StGit' % branch
+
+ print 'Unprotecting branch "%s"...' % branch,
+ sys.stdout.flush()
+ stack.Series(branch).unprotect()
+ print 'done'
+
+ return
+
elif len(args) == 1:
+ if args[0] == git.get_head_file():
+ raise CmdException, 'Branch "%s" is already the current branch' % args[0]
+
print 'Switching to branch "%s"...' % args[0],
sys.stdout.flush()