libvcs.cmd.hg#

For mercurial, aka hg(1).

Run hg (Mercurial) commands directly against a local mercurial repo.

Note

At a Mercurial shop? Can you help us jimmy this module into the next Sunbeam toaster of Mercurialian perfection? We need to patch and shimmy this thing into shape and seek a skilled tradesperson to give it - in Robert M. Pirsig’s sense - care. Connect with us on the tracker. It’s not too late to change the API.

class libvcs.cmd.hg.HgColorType(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

CLI Color enum for Mercurial.

boolean = 'boolean'#
always = 'always'#
auto = 'auto'#
never = 'never'#
debug = 'debug'#
class libvcs.cmd.hg.HgPagerType(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

CLI Pagination enum for Mercurial.

boolean = 'boolean'#
always = 'always'#
auto = 'auto'#
never = 'never'#
class libvcs.cmd.hg.Hg(*, dir, progress_callback=None)[source]#

Bases: object

Run commands directly on a Mercurial repository.

Lite, typed, pythonic wrapper for hg(1).

Parameters:

Examples

>>> Hg(dir=tmp_path)
<Hg dir=...>
__init__(*, dir, progress_callback=None)[source]#

Lite, typed, pythonic wrapper for hg(1).

Parameters:
Return type:

None

Examples

>>> Hg(dir=tmp_path)
<Hg dir=...>
dir: Path#

Directory to check out

progress_callback: Optional[ProgressCallbackProtocol] = None#
run(args, *, config=None, repository=None, quiet=None, help=None, encoding=None, encoding_mode=None, verbose=None, traceback=None, debug=None, debugger=None, profile=None, version=None, hidden=None, time=None, pager=None, color=None, check_returncode=None, **kwargs)[source]#

Run a command for this Mercurial repository.

Passing None to a subcommand option, the flag won’t be passed unless otherwise stated.

hg help and hg help [cmd]

Wraps hg’s Options.

Parameters:
Return type:

str

Examples

>>> hg = Hg(dir=tmp_path)
>>> hg.run(['help'])
"Mercurial Distributed SCM..."
clone(*, url, no_update=None, update_rev=None, rev=None, branch=None, ssh=None, remote_cmd=None, pull=None, stream=None, insecure=None, quiet=None, make_parents=True, check_returncode=None)[source]#

Clone a working copy from a mercurial repo.

Wraps hg clone.

Parameters:
  • make_parents (bool, default: True) – Creates checkout directory (:attr:`self.dir) if it doesn’t already exist.

  • check_returncode (bool, default: None) – Passthrough to Hg.run()

  • url (str) –

  • no_update (bool | None) –

  • update_rev (str | None) –

  • rev (str | None) –

  • branch (str | None) –

  • ssh (str | None) –

  • remote_cmd (str | None) –

  • pull (bool | None) –

  • stream (bool | None) –

  • insecure (bool | None) –

  • quiet (bool | None) –

Return type:

str

Examples

>>> hg = Hg(dir=tmp_path)
>>> hg_remote_repo = create_hg_remote_repo()
>>> hg.clone(url=f'file://{hg_remote_repo}')
'updating to branch default...1 files updated, 0 files merged, ...'
>>> hg.dir.exists()
True
update(quiet=None, verbose=None, check_returncode=True, *args, **kwargs)[source]#

Update working directory.

Wraps hg update.

Return type:

str

Parameters:
  • quiet (bool | None) –

  • verbose (bool | None) –

  • check_returncode (bool | None) –

  • args (object) –

  • kwargs (object) –

Examples

>>> hg = Hg(dir=tmp_path)
>>> hg_remote_repo = create_hg_remote_repo()
>>> hg.clone(url=f'file://{hg_remote_repo}')
'updating to branch default...1 files updated, 0 files merged, ...'
>>> hg.update()
'0 files updated, 0 files merged, 0 files removed, 0 files unresolved'
pull(quiet=None, verbose=None, update=None, check_returncode=True, *args, **kwargs)[source]#

Update working directory.

Wraps hg update.

Return type:

str

Parameters:
  • quiet (bool | None) –

  • verbose (bool | None) –

  • update (bool | None) –

  • check_returncode (bool | None) –

  • args (object) –

  • kwargs (object) –

Examples

>>> hg = Hg(dir=tmp_path)
>>> hg_remote_repo = create_hg_remote_repo()
>>> hg.clone(url=f'file://{hg_remote_repo}')
'updating to branch default...1 files updated, 0 files merged, ...'
>>> hg.pull()
'pulling from ...searching for changes...no changes found'
>>> hg.pull(update=True)
'pulling from ...searching for changes...no changes found'