self.__applied_file = os.path.join(self._dir(), 'applied')
self.__unapplied_file = os.path.join(self._dir(), 'unapplied')
self.__hidden_file = os.path.join(self._dir(), 'hidden')
- self.__descr_file = os.path.join(self._dir(), 'description')
# where this series keeps its patches
self.__patch_dir = os.path.join(self._dir(), 'patches')
if os.path.isfile(protect_file):
os.remove(protect_file)
+ def __branch_descr(self):
+ return 'branch.%s.description' % self.get_branch()
+
def get_description(self):
- return self._get_field('description') or ''
+ # Fall back to the .git/patches/<branch>/description file if
+ # the config variable is unset.
+ return (config.get(self.__branch_descr())
+ or self._get_field('description') or '')
def set_description(self, line):
- self._set_field('description', line)
+ if line:
+ config.set(self.__branch_descr(), line)
+ else:
+ config.unset(self.__branch_descr())
+ # Delete the old .git/patches/<branch>/description file if it
+ # exists.
+ self._set_field('description', None)
def get_parent_remote(self):
value = config.get('branch.%s.remote' % self.__name)
config.set('branch.%s.stgit.parentbranch' % self.__name, name)
def set_parent(self, remote, localbranch):
- # policy: record local branches as remote='.'
- recordremote = remote or '.'
if localbranch:
- self.__set_parent_remote(recordremote)
+ self.__set_parent_remote(remote)
self.__set_parent_branch(localbranch)
# We'll enforce this later
# else:
self.create_empty_field('applied')
self.create_empty_field('unapplied')
- self.create_empty_field('description')
os.makedirs(os.path.join(self._dir(), 'patches'))
os.makedirs(self.__refs_dir)
self._set_field('orig-base', git.get_head())
os.remove(self.__unapplied_file)
if os.path.exists(self.__hidden_file):
os.remove(self.__hidden_file)
- if os.path.exists(self.__descr_file):
- os.remove(self.__descr_file)
if os.path.exists(self._dir()+'/orig-base'):
os.remove(self._dir()+'/orig-base')
+ # Remove obsolete files that StGIT no longer uses, but
+ # that might still be around if this is an old repository.
+ for obsolete in ([os.path.join(self._dir(), fn)
+ for fn in ['current', 'description']]
+ + [os.path.join(self.__base_dir,
+ 'refs', 'bases', self.__name)]):
+ if os.path.exists(obsolete):
+ os.remove(obsolete)
+
if not os.listdir(self.__patch_dir):
os.rmdir(self.__patch_dir)
else:
before_existing = False, refresh = True):
"""Creates a new patch
"""
- self.__patch_name_valid(name)
- if self.patch_applied(name) or self.patch_unapplied(name):
- raise StackException, 'Patch "%s" already exists' % name
+ if name != None:
+ self.__patch_name_valid(name)
+ if self.patch_applied(name) or self.patch_unapplied(name):
+ raise StackException, 'Patch "%s" already exists' % name
if not message and can_edit:
- descr = edit_file(self, None, \
- 'Please enter the description for patch "%s" ' \
- 'above.' % name, show_patch)
+ descr = edit_file(
+ self, None,
+ 'Please enter the description for the patch above.',
+ show_patch)
else:
descr = message
head = git.get_head()
+ if name == None:
+ name = make_patch_name(descr, self.patch_exists)
+
patch = Patch(name, self.__patch_dir, self.__refs_dir)
patch.create()