Sometimes we want to develop against a branch that doesn't evolve (eg.
2.6.12). To prevent an accidental "stg pull", provide two new options to
stg: "--protect" and "--unprotect". This also prevents deleting any
patches in the series.
Signed-off-by: Chuck Lever <cel@netapp.com>
make_option('-l', '--list',
help = 'list branches contained in this repository',
action = 'store_true'),
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',
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',
def print_branch(branch_name):
initialized = ' '
current = ' '
def print_branch(branch_name):
initialized = ' '
current = ' '
if os.path.isdir(os.path.join(git.base_dir, 'patches', branch_name)):
initialized = 's'
if is_current_branch(branch_name):
current = '>'
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 stack.Series(branch_name).get_protected():
+ protected = 'p'
+ print '%s %s%s\t%s' % (current, initialized, protected, branch_name)
def delete_branch(doomed_name, force = False):
def delete_branch(doomed_name, force = False):
+ if stack.Series(doomed_name).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')
if is_current_branch(doomed_name) and doomed_name != 'master':
git.switch_branch('master')
+ 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
+ stack.Series(branch).protect()
+ return
+
elif options.rename:
if len(args) != 2:
elif options.rename:
if len(args) != 2:
rename_branch(args[0], args[1])
return
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
+ stack.Series(branch).unprotect()
+ return
+
elif len(args) == 1:
print 'Switching to branch "%s"...' % args[0],
elif len(args) == 1:
print 'Switching to branch "%s"...' % args[0],
if not applied:
raise CmdException, 'No patches applied'
if not applied:
raise CmdException, 'No patches applied'
+ if crt_series.get_protected():
+ raise CmdException, 'This branch is protected. Commit is not permitted'
+
crt_head = git.get_head()
print 'Committing %d patches...' % len(applied),
crt_head = git.get_head()
print 'Committing %d patches...' % len(applied),
if len(args) == 2:
refspec = args[1]
if len(args) == 2:
refspec = args[1]
+ if crt_series.get_protected():
+ raise CmdException, 'This branch is protected. Pulls are not permitted'
+
check_local_changes()
check_conflicts()
check_head_top_equal()
check_local_changes()
check_conflicts()
check_head_top_equal()
def get_base_file(self):
return self.__base_file
def get_base_file(self):
return self.__base_file
+ def get_protected(self):
+ return os.path.isfile(os.path.join(self.__patch_dir, 'protected'))
+
+ def protect(self):
+ protect_file = os.path.join(self.__patch_dir, 'protected')
+ if not os.path.isfile(protect_file):
+ create_empty_file(protect_file)
+
+ def unprotect(self):
+ protect_file = os.path.join(self.__patch_dir, 'protected')
+ if os.path.isfile(protect_file):
+ os.remove(protect_file)
+
def __patch_is_current(self, patch):
return patch.get_name() == read_string(self.__current_file)
def __patch_is_current(self, patch):
return patch.get_name() == read_string(self.__current_file)