[MERGE] Adds a new builtin command 'alias' to list, set and remove bzr aliases.
Ian Clatworthy
ian.clatworthy at internode.on.net
Wed May 21 06:27:43 BST 2008
Tim Penhey wrote:
> Here's another patch, from our sit down fix-it session.
Some tweaks needed, particularly for better Windows compatibility.
bb:tweak
Firstly, this needs a NEWS item added under IMPROVEMENTS.
> + Show the alias specified for 'll'::
> +
> + bzr alias ll
> +
> + Set an alias for 'll'::
> +
> + bzr alias ll='log --line -r-10..-1'
> +
> + To remove an alias for 'll'::
See bug #59302. Daniel mentioned this in an earlier review btw.
> + @display_command
> + def print_aliases(self):
> + """Print out the defined aliases in a similar format to bash."""
> + aliases = config.GlobalConfig().get_aliases()
> + for key, value in sorted(aliases.iteritems()):
> + self.outf.write("bzr alias %s='%s'\n" % (key, value))
> +
> + @display_command
> + def print_alias(self, alias_name):
> + from bzrlib.commands import get_alias
> + alias = get_alias(alias_name)
> + if alias is None:
> + self.outf.write("bzr alias: %s: not found\n" % alias_name)
> + else:
> + self.outf.write(
> + "bzr alias %s='%s'" % (alias_name, ' '.join(alias)))
I think the output should reflect the preferred input - use " again
here instead of '.
> + def set_alias(self, alias_name, alias_commands):
> + """Save the alias in the global config."""
> + c = config.GlobalConfig()
> + c.set_alias(alias_name, alias_commands)
The last parameter is actually a string, not a list, so I'd like it
renamed to alias_command to make this clearer.
> + self._writeConfigFile()
> +
> + def _set_option(self, option, value, section):
> # FIXME: RBC 20051029 This should refresh the parser and also take a
> # file lock on bazaar.conf.
> conf_dir = os.path.dirname(self._get_filename())
> ensure_config_dir_exists(conf_dir)
> - if 'DEFAULT' not in self._get_parser():
> - self._get_parser()['DEFAULT'] = {}
> - self._get_parser()['DEFAULT'][option] = value
> + self._get_parser().setdefault(section, {})[option] = value
> + self._writeConfigFile()
> +
> + def _writeConfigFile(self):
Our method naming convention is xx_yy_zz, not xxYyZz. Fix _writeConfigFile
accordingly please.
> + def test_add_alias_visible(self):
> + """Adding an alias makes it ..."""
> + self.run_bzr('alias commit="commit --strict"')
> + out = self.run_bzr('alias commit')[0].rstrip('\n')
> + self.assertEquals("bzr alias commit='commit --strict'", out)
Be sure to update the tests after s/"/'/ in the print methods.
If you make the above changes and send the new bundle to the list,
I'll merge it. It doesn't require another round of reviews.
Ian C.
More information about the bazaar
mailing list