Rev 5455: Make the test properly fail and provide a fake implementation for ``bzr config --remove opt_name``. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Oct 4 10:47:39 BST 2010
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5455
revision-id: v.ladeuil+lp at free.fr-20101004094739-cn2ps0c3t3hj3e5u
parent: v.ladeuil+lp at free.fr-20101004084217-z6ul10wq2f8h6nfv
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-modify
timestamp: Mon 2010-10-04 11:47:39 +0200
message:
Make the test properly fail and provide a fake implementation for ``bzr config --remove opt_name``.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2010-10-04 08:06:27 +0000
+++ b/bzrlib/config.py 2010-10-04 09:47:39 +0000
@@ -1723,25 +1723,30 @@
# their own config files (or not) -- vila 20101002
commands.Option('force', help='Force the configuration file',
short_name='f', type=unicode),
+ commands.Option('remove', help='Remove the option from'
+ ' the configuration file'),
]
@commands.display_command
- def run(self, matching=None, directory=None, force=None):
+ def run(self, matching=None, directory=None, force=None, remove=False):
if directory is None:
directory = '.'
directory = urlutils.normalize_url(directory)
if matching is None:
matching = '*'
- self._show_config('*', directory, force)
+ self._show_config('*', directory)
else:
- pos = matching.find('=')
- if pos == -1:
- self._show_config(matching, directory, force)
+ if remove:
+ self._remove_config_option(matching, directory, force)
else:
- self._set_config_option(matching[:pos], matching[pos+1:],
- directory, force)
+ pos = matching.find('=')
+ if pos == -1:
+ self._show_config(matching, directory)
+ else:
+ self._set_config_option(matching[:pos], matching[pos+1:],
+ directory, force)
- def _show_config(self, matching, directory, force_meaningless):
+ def _show_config(self, matching, directory):
try:
(_, br, _) = bzrdir.BzrDir.open_containing_tree_or_branch(
directory)
@@ -1777,10 +1782,39 @@
confs = [br.get_config()]
except errors.NotBranchError:
confs = [LocationConfig(directory), GlobalConfig()]
- trace.mutter('confs: %r' % (confs,))
if not confs:
raise errors.BzrError('%s is not a known configuration'
% (force,))
# We use the first config to set the option
confs[0].set_user_option(name, value)
+ def _remove_config_option(self, name, directory, force):
+ confs = []
+ if force is not None:
+ if force == 'bazaar':
+ confs = [GlobalConfig()]
+ elif force == 'locations':
+ confs = [LocationConfig(directory)]
+ elif force == 'branch':
+ (_, br, _) = bzrdir.BzrDir.open_containing_tree_or_branch(
+ directory)
+ confs = [br.get_config()]
+ else:
+ try:
+ (_, br, _) = bzrdir.BzrDir.open_containing_tree_or_branch(
+ directory)
+ confs = [br.get_config()]
+ except errors.NotBranchError:
+ confs = [LocationConfig(directory), GlobalConfig()]
+ if not confs:
+ raise errors.BzrError('%s is not a known configuration'
+ % (force,))
+ # We use the first config to set the option
+ sections = confs[0].get_sections()
+ if sections:
+ section = sections.next()[1]
+ if not sections or name not in section:
+ raise errors.BzrError('%s is not a known option' % (name,))
+ raise NotImplementeErro(self._remove_config_option)
+ del section[name]
+ confs[0]._write_config_file()
=== modified file 'bzrlib/tests/blackbox/test_config.py'
--- a/bzrlib/tests/blackbox/test_config.py 2010-10-04 08:42:17 +0000
+++ b/bzrlib/tests/blackbox/test_config.py 2010-10-04 09:47:39 +0000
@@ -135,5 +135,5 @@
_t_config.create_configs_with_file_option(self)
def test_unknown_option(self):
- self.run_bzr_error(['file option is unknown',],
+ self.run_bzr_error(['file is not a known option',],
['config', '--remove', 'file'])
More information about the bazaar-commits
mailing list