libvcs.cmd.git#

For git(1).

Compare to: fabtools.git, salt.modules.git, ansible.builtin.git

Subcommands

Run hg commands directly against a local git repo.

class libvcs.cmd.git.Git(*, path, progress_callback=None)[source]#

Bases: object

Run commands directly on a git repository.

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

Parameters:

Examples

>>> git = Git(path=git_local_clone.path)
>>> git
<Git path=...>

Subcommands:

>>> git.remote.show()
'origin'
>>> git.remote.add(
...     name='my_remote', url=f'file:///dev/null'
... )
''
>>> git.remote.show()
'my_remote\norigin'
>>> git.stash.save(message="Message")
'No local changes to save'
>>> git.submodule.init()
''
__init__(*, path, progress_callback=None)[source]#

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

Parameters:
Return type:

None

Examples

>>> git = Git(path=git_local_clone.path)
>>> git
<Git path=...>

Subcommands:

>>> git.remote.show()
'origin'
>>> git.remote.add(
...     name='my_remote', url=f'file:///dev/null'
... )
''
>>> git.remote.show()
'my_remote\norigin'
>>> git.stash.save(message="Message")
'No local changes to save'
>>> git.submodule.init()
''
path: Path#

Directory to check out

progress_callback: Optional[ProgressCallbackProtocol] = None#
submodule: GitSubmoduleCmd#
remote: GitRemoteCmd#
stash: GitStashCmd#
run(args, *, version=None, _help=None, html_path=None, man_path=None, info_path=None, C=None, cwd=None, git_dir=None, work_tree=None, namespace=None, super_prefix=None, exec_path=None, bare=None, no_replace_objects=None, literal_pathspecs=None, global_pathspecs=None, noglob_pathspecs=None, icase_pathspecs=None, no_optional_locks=None, config=None, config_env=None, log_in_real_time=False, **kwargs)[source]#

Run a command for this git repository.

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

git help and git help [cmd]

Wraps git’s Options.

Parameters:
Return type:

str

Examples

>>> git = Git(path=tmp_path)
>>> git.run(['help'])
"usage: git [...--version] [...--help] [-C <path>]..."
clone(*, url, separate_git_dir=None, template=None, depth=None, branch=None, origin=None, upload_pack=None, shallow_since=None, shallow_exclude=None, reference=None, reference_if_able=None, server_option=None, jobs=None, force=None, local=None, _all=None, no_hardlinks=None, hardlinks=None, shared=None, progress=None, no_checkout=None, no_reject_shallow=None, reject_shallow=None, sparse=None, shallow_submodules=None, no_shallow_submodules=None, remote_submodules=None, no_remote_submodules=None, verbose=None, quiet=None, config=None, log_in_real_time=False, check_returncode=None, make_parents=True, **kwargs)[source]#

Clone a working copy from an git repo.

Wraps git clone.

Parameters:
  • url (str) –

  • directory (str) –

  • separate_git_dir (StrOrBytesPath) – Separate repository (.git/ ) from working tree

  • force (bool, optional) – force operation to run

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

  • template (str | None) –

  • depth (int | None) –

  • branch (str | None) –

  • origin (str | None) –

  • upload_pack (str | None) –

  • shallow_since (str | None) –

  • shallow_exclude (str | None) –

  • reference (str | None) –

  • reference_if_able (str | None) –

  • server_option (str | None) –

  • jobs (str | None) –

  • local (bool | None) –

  • _all (bool | None) –

  • no_hardlinks (bool | None) –

  • hardlinks (bool | None) –

  • shared (bool | None) –

  • progress (bool | None) –

  • no_checkout (bool | None) –

  • no_reject_shallow (bool | None) –

  • reject_shallow (bool | None) –

  • sparse (bool | None) –

  • shallow_submodules (bool | None) –

  • no_shallow_submodules (bool | None) –

  • remote_submodules (bool | None) –

  • no_remote_submodules (bool | None) –

  • verbose (bool | None) –

  • quiet (bool | None) –

  • config (dict[str, Any] | None) –

  • log_in_real_time (bool) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Return type:

str

Examples

>>> git = Git(path=tmp_path)
>>> git_remote_repo = create_git_remote_repo()
>>> git.clone(url=f'file://{git_remote_repo}')
''
>>> git.path.exists()
True
fetch(*, reftag=None, deepen=None, depth=None, branch=None, origin=None, upload_pack=None, shallow_since=None, shallow_exclude=None, negotiation_tip=None, jobs=None, server_option=None, recurse_submodules=None, recurse_submodules_default=None, submodule_prefix=None, _all=None, force=None, keep=None, multiple=None, dry_run=None, append=None, atomic=None, ipv4=None, ipv6=None, progress=None, quiet=None, verbose=None, unshallow=None, update_shallow=None, negotiate_tip=None, no_write_fetch_head=None, write_fetch_head=None, no_auto_maintenance=None, auto_maintenance=None, no_write_commit_graph=None, write_commit_graph=None, prefetch=None, prune=None, prune_tags=None, no_tags=None, tags=None, no_recurse_submodules=None, set_upstream=None, update_head_ok=None, show_forced_updates=None, no_show_forced_updates=None, negotiate_only=None, check_returncode=None, **kwargs)[source]#

Download from repo. Wraps git fetch.

Return type:

str

Parameters:
  • reftag (Any | None) –

  • deepen (str | None) –

  • depth (str | None) –

  • branch (str | None) –

  • origin (str | None) –

  • upload_pack (str | None) –

  • shallow_since (str | None) –

  • shallow_exclude (str | None) –

  • negotiation_tip (str | None) –

  • jobs (str | None) –

  • server_option (str | None) –

  • recurse_submodules (bool | Literal['yes', 'on-demand', 'no'] | None) –

  • recurse_submodules_default (bool | Literal['yes', 'on-demand'] | None) –

  • submodule_prefix (str | bytes | PathLike[str] | PathLike[bytes] | None) –

  • _all (bool | None) –

  • force (bool | None) –

  • keep (bool | None) –

  • multiple (bool | None) –

  • dry_run (bool | None) –

  • append (bool | None) –

  • atomic (bool | None) –

  • ipv4 (bool | None) –

  • ipv6 (bool | None) –

  • progress (bool | None) –

  • quiet (bool | None) –

  • verbose (bool | None) –

  • unshallow (bool | None) –

  • update_shallow (bool | None) –

  • negotiate_tip (bool | None) –

  • no_write_fetch_head (bool | None) –

  • write_fetch_head (bool | None) –

  • no_auto_maintenance (bool | None) –

  • auto_maintenance (bool | None) –

  • no_write_commit_graph (bool | None) –

  • write_commit_graph (bool | None) –

  • prefetch (bool | None) –

  • prune (bool | None) –

  • prune_tags (bool | None) –

  • no_tags (bool | None) –

  • tags (bool | None) –

  • no_recurse_submodules (bool | None) –

  • set_upstream (bool | None) –

  • update_head_ok (bool | None) –

  • show_forced_updates (bool | None) –

  • no_show_forced_updates (bool | None) –

  • negotiate_only (bool | None) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Examples

>>> git = Git(path=git_local_clone.path)
>>> git_remote_repo = create_git_remote_repo()
>>> git.fetch()
''
>>> git = Git(path=git_local_clone.path)
>>> git_remote_repo = create_git_remote_repo()
>>> git.fetch(reftag=f'file://{git_remote_repo}')
''
>>> git.path.exists()
True
rebase(*, upstream=None, onto=None, branch=None, apply=None, merge=None, quiet=None, verbose=None, stat=None, no_stat=None, verify=None, no_verify=None, fork_point=None, no_fork_point=None, whitespace=None, no_whitespace=None, commit_date_is_author_date=None, ignore_date=None, root=None, autostash=None, no_autostash=None, autosquash=None, no_autosquash=None, reschedule_failed_exec=None, no_reschedule_failed_exec=None, context=None, rerere_autoupdate=None, no_rerere_autoupdate=None, keep_empty=None, no_keep_empty=None, reapply_cherry_picks=None, no_reapply_cherry_picks=None, allow_empty_message=None, signoff=None, keep_base=None, strategy=None, strategy_option=None, _exec=None, gpg_sign=None, no_gpg_sign=None, empty=None, rebase_merges=None, interactive=None, edit_todo=None, skip=None, show_current_patch=None, abort=None, _quit=None, check_returncode=None, **kwargs)[source]#

Reapply commit on top of another tip.

Wraps git rebase.

Parameters:
  • continue (bool) – Accepted via kwargs

  • upstream (str | None) –

  • onto (str | None) –

  • branch (str | None) –

  • apply (bool | None) –

  • merge (bool | None) –

  • quiet (bool | None) –

  • verbose (bool | None) –

  • stat (bool | None) –

  • no_stat (bool | None) –

  • verify (bool | None) –

  • no_verify (bool | None) –

  • fork_point (bool | None) –

  • no_fork_point (bool | None) –

  • whitespace (str | None) –

  • no_whitespace (bool | None) –

  • commit_date_is_author_date (bool | None) –

  • ignore_date (bool | None) –

  • root (bool | None) –

  • autostash (bool | None) –

  • no_autostash (bool | None) –

  • autosquash (bool | None) –

  • no_autosquash (bool | None) –

  • reschedule_failed_exec (bool | None) –

  • no_reschedule_failed_exec (bool | None) –

  • context (int | None) –

  • rerere_autoupdate (bool | None) –

  • no_rerere_autoupdate (bool | None) –

  • keep_empty (bool | None) –

  • no_keep_empty (bool | None) –

  • reapply_cherry_picks (bool | None) –

  • no_reapply_cherry_picks (bool | None) –

  • allow_empty_message (bool | None) –

  • signoff (bool | None) –

  • keep_base (bool | None) –

  • strategy (str | bool | None) –

  • strategy_option (str | None) –

  • _exec (str | None) –

  • gpg_sign (str | bool | None) –

  • no_gpg_sign (bool | None) –

  • empty (str | Literal['drop', 'keep', 'ask'] | None) –

  • rebase_merges (str | Literal['rebase-cousins', 'no-rebase-cousins'] | None) –

  • interactive (bool | None) –

  • edit_todo (bool | None) –

  • skip (bool | None) –

  • show_current_patch (bool | None) –

  • abort (bool | None) –

  • _quit (bool | None) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Return type:

str

Examples

>>> git = Git(path=git_local_clone.path)
>>> git_remote_repo = create_git_remote_repo()
>>> git.rebase()
'Current branch master is up to date.'

Declare upstream:

>>> git = Git(path=git_local_clone.path)
>>> git_remote_repo = create_git_remote_repo()
>>> git.rebase(upstream='origin')
'Current branch master is up to date.'
>>> git.path.exists()
True
pull(*, reftag=None, repository=None, deepen=None, depth=None, branch=None, origin=None, upload_pack=None, shallow_since=None, shallow_exclude=None, negotiation_tip=None, jobs=None, server_option=None, recurse_submodules=None, recurse_submodules_default=None, submodule_prefix=None, cleanup=None, rebase=None, no_rebase=None, strategy=None, strategy_option=None, gpg_sign=None, no_gpg_sign=None, commit=None, no_commit=None, edit=None, no_edit=None, fast_forward_only=None, fast_forward=None, no_fast_forward=None, sign_off=None, no_sign_off=None, stat=None, no_stat=None, squash=None, no_squash=None, verify=None, no_verify=None, verify_signatures=None, no_verify_signatures=None, summary=None, no_summary=None, autostash=None, no_autostash=None, allow_unrelated_histories=None, fetch=None, no_fetch=None, _all=None, force=None, keep=None, multiple=None, dry_run=None, append=None, atomic=None, ipv4=None, ipv6=None, progress=None, quiet=None, verbose=None, unshallow=None, update_shallow=None, negotiate_tip=None, no_write_fetch_head=None, write_fetch_head=None, no_auto_maintenance=None, auto_maintenance=None, no_write_commit_graph=None, write_commit_graph=None, prefetch=None, prune=None, prune_tags=None, no_tags=None, tags=None, no_recurse_submodules=None, set_upstream=None, update_head_ok=None, show_forced_updates=None, no_show_forced_updates=None, negotiate_only=None, log_in_real_time=False, check_returncode=None, **kwargs)[source]#

Download from repo. Wraps git pull.

Return type:

str

Parameters:
  • reftag (Any | None) –

  • repository (str | None) –

  • deepen (str | None) –

  • depth (str | None) –

  • branch (str | None) –

  • origin (str | None) –

  • upload_pack (str | None) –

  • shallow_since (str | None) –

  • shallow_exclude (str | None) –

  • negotiation_tip (str | None) –

  • jobs (str | None) –

  • server_option (str | None) –

  • recurse_submodules (bool | Literal['yes', 'on-demand', 'no'] | None) –

  • recurse_submodules_default (bool | Literal['yes', 'on-demand'] | None) –

  • submodule_prefix (str | bytes | PathLike[str] | PathLike[bytes] | None) –

  • cleanup (str | None) –

  • rebase (str | bool | None) –

  • no_rebase (bool | None) –

  • strategy (str | bool | None) –

  • strategy_option (str | None) –

  • gpg_sign (str | bool | None) –

  • no_gpg_sign (bool | None) –

  • commit (bool | None) –

  • no_commit (bool | None) –

  • edit (bool | None) –

  • no_edit (bool | None) –

  • fast_forward_only (bool | None) –

  • fast_forward (bool | None) –

  • no_fast_forward (bool | None) –

  • sign_off (bool | None) –

  • no_sign_off (bool | None) –

  • stat (bool | None) –

  • no_stat (bool | None) –

  • squash (bool | None) –

  • no_squash (bool | None) –

  • verify (bool | None) –

  • no_verify (bool | None) –

  • verify_signatures (bool | None) –

  • no_verify_signatures (bool | None) –

  • summary (bool | None) –

  • no_summary (bool | None) –

  • autostash (bool | None) –

  • no_autostash (bool | None) –

  • allow_unrelated_histories (bool | None) –

  • fetch (bool | None) –

  • no_fetch (bool | None) –

  • _all (bool | None) –

  • force (bool | None) –

  • keep (bool | None) –

  • multiple (bool | None) –

  • dry_run (bool | None) –

  • append (bool | None) –

  • atomic (bool | None) –

  • ipv4 (bool | None) –

  • ipv6 (bool | None) –

  • progress (bool | None) –

  • quiet (bool | None) –

  • verbose (bool | None) –

  • unshallow (bool | None) –

  • update_shallow (bool | None) –

  • negotiate_tip (bool | None) –

  • no_write_fetch_head (bool | None) –

  • write_fetch_head (bool | None) –

  • no_auto_maintenance (bool | None) –

  • auto_maintenance (bool | None) –

  • no_write_commit_graph (bool | None) –

  • write_commit_graph (bool | None) –

  • prefetch (bool | None) –

  • prune (bool | None) –

  • prune_tags (bool | None) –

  • no_tags (bool | None) –

  • tags (bool | None) –

  • no_recurse_submodules (bool | None) –

  • set_upstream (bool | None) –

  • update_head_ok (bool | None) –

  • show_forced_updates (bool | None) –

  • no_show_forced_updates (bool | None) –

  • negotiate_only (bool | None) –

  • log_in_real_time (bool) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Examples

>>> git = Git(path=git_local_clone.path)
>>> git_remote_repo = create_git_remote_repo()
>>> git.pull()
'Already up to date.'

Fetch via ref:

>>> git = Git(path=tmp_path)
>>> git.run(['init'])
'Initialized ...'
>>> git_remote_repo = create_git_remote_repo()
>>> git.pull(reftag=f'file://{git_remote_repo}')
''
>>> git.path.exists()
True
init(*, template=None, separate_git_dir=None, object_format=None, branch=None, initial_branch=None, shared=None, quiet=None, bare=None, check_returncode=None, **kwargs)[source]#

Create empty repo. Wraps git init.

Parameters:
  • quiet (bool) – --quiet

  • bare (bool) – --bare

  • object_format (Optional[Literal['sha1', 'sha256']]) – Hash algorithm used for objects. SHA-256 is still experimental as of git 2.36.0.

  • template (str | None) –

  • separate_git_dir (str | bytes | PathLike[str] | PathLike[bytes] | None) –

  • branch (str | None) –

  • initial_branch (str | None) –

  • shared (bool | None) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Return type:

str

Examples

>>> new_repo = tmp_path / 'example'
>>> new_repo.mkdir()
>>> git = Git(path=new_repo)
>>> git.init()
'Initialized empty Git repository in ...'
>>> pathlib.Path(new_repo / 'test').write_text('foo', 'utf-8')
3
>>> git.run(['add', '.'])
''

Bare:

>>> new_repo = tmp_path / 'example1'
>>> new_repo.mkdir()
>>> git = Git(path=new_repo)
>>> git.init(bare=True)
'Initialized empty Git repository in ...'
>>> pathlib.Path(new_repo / 'HEAD').exists()
True

Existing repo:

>>> git = Git(path=new_repo)
>>> git = Git(path=git_local_clone.path)
>>> git_remote_repo = create_git_remote_repo()
>>> git.init()
'Reinitialized existing Git repository in ...'
help(*, _all=None, verbose=None, no_external_commands=None, no_aliases=None, config=None, guides=None, info=None, man=None, web=None, check_returncode=None, **kwargs)[source]#

Help info. Wraps git help.

Parameters:
  • _all (bool) – Prints everything.

  • no_external_commands (bool) – For use with all, excludes external commands.

  • no_aliases (bool) – For use with all, excludes aliases.

  • verbose (bool) – For us with all, on by default.

  • config (bool) – List all config vars.

  • guides (bool) – List concept guides.

  • info (bool) – Display man page in info format.

  • man (bool) – Man page.

  • web (bool) – Man page in HTML.

  • check_returncode (bool | None) –

  • kwargs (Any) –

Return type:

str

Examples

>>> git = Git(path=tmp_path)
>>> git.help()
"usage: git [...--version] [...--help] [-C <path>]..."
>>> git.help(_all=True)
"See 'git help <command>' to read about a specific subcommand..."
>>> git.help(info=True)
"usage: git [...--version] [...--help] [-C <path>] [-c <name>=<value>]..."
>>> git.help(man=True)
"usage: git [...--version] [...--help] [-C <path>] [-c <name>=<value>]..."
reset(*, quiet=None, refresh=None, no_refresh=None, pathspec_from_file=None, pathspec=None, soft=None, mixed=None, hard=None, merge=None, keep=None, commit=None, recurse_submodules=None, no_recurse_submodules=None, check_returncode=None, **kwargs)[source]#

Reset HEAD. Wraps git help.

Parameters:
Return type:

str

Examples

>>> git = Git(path=git_local_clone.path)
>>> git.reset()
''
>>> git.reset(soft=True, commit='HEAD~0')
''
checkout(*, quiet=None, progress=None, no_progress=None, pathspec_from_file=None, pathspec=None, force=None, ours=None, theirs=None, no_track=None, guess=None, no_guess=None, _list=None, detach=None, merge=None, ignore_skip_worktree_bits=None, patch=None, orphan=None, conflict=None, overwrite_ignore=None, no_overwrite_ignore=None, recurse_submodules=None, no_recurse_submodules=None, overlay=None, no_overlay=None, commit=None, branch=None, new_branch=None, start_point=None, treeish=None, check_returncode=None, **kwargs)[source]#

Switch branches or checks out files.

Wraps git checkout (git co).

Parameters:
Return type:

str

Examples

>>> git = Git(path=git_local_clone.path)
>>> git.checkout()
"Your branch is up to date with 'origin/master'."
>>> git.checkout(branch='origin/master', pathspec='.')
''
status(*, verbose=None, long=None, short=None, branch=None, z=None, column=None, no_column=None, ahead_behind=None, no_ahead_behind=None, renames=None, no_renames=None, find_renames=None, porcelain=None, untracked_files=None, ignored=None, ignored_submodules=None, pathspec=None, check_returncode=None, **kwargs)[source]#

Return status of working tree.

Wraps git status.

git ls-files has similar params (e.g. z)

Parameters:
Return type:

str

Examples

>>> git = Git(path=git_local_clone.path)
>>> git.status()
"On branch master..."
>>> pathlib.Path(git_local_clone.path / 'new_file.txt').touch()
>>> git.status(porcelain=True)
'?? new_file.txt'
>>> git.status(porcelain='1')
'?? new_file.txt'
>>> git.status(porcelain='2')
'? new_file.txt'
>>> git.status(C=git_local_clone.path / '.git', porcelain='2')
'? new_file.txt'
>>> git.status(porcelain=True, untracked_files="no")
''
config(*, replace_all=None, get=None, get_all=None, get_regexp=None, get_urlmatch=None, system=None, local=None, worktree=None, file=None, blob=None, remove_section=None, rename_section=None, unset=None, unset_all=None, _list=None, fixed_value=None, no_type=None, null=None, name_only=None, show_origin=None, show_scope=None, get_color=None, get_colorbool=None, default=None, _type=None, edit=None, no_includes=None, includes=None, add=None, check_returncode=None, **kwargs)[source]#

Get and set repo configuration.

git config.

Parameters:
  • replace_all (Optional[bool]) –

  • get (Optional[bool]) –

  • get_all (Optional[bool]) –

  • get_regexp (Optional[bool]) –

  • get_urlmatch (Optional[tuple[str, str]]) –

  • system (Optional[bool]) –

  • local (Optional[bool]) –

  • worktree (Optional[bool]) –

  • file (Optional[StrOrBytesPath]) –

  • blob (Optional[str]) –

  • remove_section (Optional[bool]) –

  • rename_section (Optional[bool]) –

  • unset (Optional[bool]) –

  • unset_all (Optional[bool]) –

  • _list (Optional[bool]) –

  • fixed_value (Optional[bool]) –

  • no_type (Optional[bool]) –

  • null (Optional[bool]) –

  • name_only (Optional[bool]) –

  • show_origin (Optional[bool]) –

  • show_scope (Optional[bool]) –

  • get_color (Optional[Union[str, bool]]) –

  • get_colorbool (Optional[Union[str, bool]]) –

  • default (Optional[str]) –

  • _type ("bool", "int", "bool-or-int", "path", "expiry-date", "color") –

  • edit (Optional[bool]) –

  • no_includes (Optional[bool]) –

  • includes (Optional[bool]) –

  • add (Optional[bool]) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Return type:

str

Examples

>>> git = Git(path=git_local_clone.path)
>>> git.config()
'usage: git config ...'
>>> git.config(_list=True)
'...user.email=...'
>>> git.config(get='color.diff')
'auto'
version(*, build_options=None, check_returncode=None, **kwargs)[source]#

Version. Wraps git version.

Return type:

str

Parameters:
  • build_options (bool | None) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Examples

>>> git = Git(path=git_local_clone.path)
>>> git.version()
'git version ...'
>>> git.version(build_options=True)
'git version ...'
rev_parse(*, parseopt=None, sq_quote=None, keep_dashdash=None, stop_at_non_option=None, stuck_long=None, verify=None, args=None, check_returncode=None, **kwargs)[source]#

rev-parse. Wraps git rev-parse.

Return type:

str

Parameters:
  • parseopt (bool | None) –

  • sq_quote (bool | None) –

  • keep_dashdash (bool | None) –

  • stop_at_non_option (bool | None) –

  • stuck_long (bool | None) –

  • verify (bool | None) –

  • args (str | None) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Examples

>>> git = Git(path=git_local_clone.path)
>>> git.rev_parse()
''
>>> git.rev_parse(parseopt=True)
'usage: git rev-parse --parseopt...'
>>> git.rev_parse(verify=True, args='HEAD')
'...'
rev_list(*, commit, path=None, max_count=None, skip=None, since=None, after=None, until=None, before=None, max_age=None, min_age=None, author=None, committer=None, grep=None, all_match=None, invert_grep=None, regexp_ignore_case=None, basic_regexp=None, extended_regexp=None, fixed_strings=None, perl_regexp=None, remove_empty=None, merges=None, no_merges=None, no_min_parents=None, min_parents=None, no_max_parents=None, max_parents=None, first_parent=None, exclude_first_parent_only=None, _not=None, _all=None, branches=None, tags=None, remotes=None, exclude=None, reflog=None, alternative_refs=None, single_worktree=None, ignore_missing=None, stdin=None, disk_usage=None, cherry_mark=None, cherry_pick=None, left_only=None, right_only=None, cherry=None, walk_reflogs=None, merge=None, boundary=None, use_bitmap_index=None, progress=None, header=None, check_returncode=True, log_in_real_time=False, **kwargs)[source]#

rev-list. Wraps git rev-list.

Return type:

str

Parameters:
  • commit (str | list[str] | None) –

  • path (list[str | PathLike[str]] | str | PathLike[str] | None) –

  • max_count (int | None) –

  • skip (int | None) –

  • since (str | None) –

  • after (str | None) –

  • until (str | None) –

  • before (str | None) –

  • max_age (str | None) –

  • min_age (str | None) –

  • author (str | None) –

  • committer (str | None) –

  • grep (str | None) –

  • all_match (bool | None) –

  • invert_grep (bool | None) –

  • regexp_ignore_case (bool | None) –

  • basic_regexp (bool | None) –

  • extended_regexp (bool | None) –

  • fixed_strings (bool | None) –

  • perl_regexp (bool | None) –

  • remove_empty (bool | None) –

  • merges (bool | None) –

  • no_merges (bool | None) –

  • no_min_parents (bool | None) –

  • min_parents (int | None) –

  • no_max_parents (bool | None) –

  • max_parents (int | None) –

  • first_parent (bool | None) –

  • exclude_first_parent_only (bool | None) –

  • _not (bool | None) –

  • _all (bool | None) –

  • branches (str | bool | None) –

  • tags (str | bool | None) –

  • remotes (str | bool | None) –

  • exclude (bool | None) –

  • reflog (bool | None) –

  • alternative_refs (bool | None) –

  • single_worktree (bool | None) –

  • ignore_missing (bool | None) –

  • stdin (bool | None) –

  • disk_usage (str | bool | None) –

  • cherry_mark (bool | None) –

  • cherry_pick (bool | None) –

  • left_only (bool | None) –

  • right_only (bool | None) –

  • cherry (bool | None) –

  • walk_reflogs (bool | None) –

  • merge (bool | None) –

  • boundary (bool | None) –

  • use_bitmap_index (bool | None) –

  • progress (str | bool | None) –

  • header (bool | None) –

  • check_returncode (bool | None) –

  • log_in_real_time (bool) –

  • kwargs (Any) –

Examples

>>> git = Git(path=git_local_clone.path)
>>> git.rev_list(commit="HEAD")
'...'
>>> git.run(['commit', '--allow-empty', '--message=Moo'])
'[master ...] Moo'
>>> git.rev_list(commit="HEAD", max_count=1)
'...'
>>> git.rev_list(commit="HEAD", path=".", max_count=1, header=True)
'...'
>>> git.rev_list(commit="origin..HEAD", max_count=1, _all=True, header=True)
'...'
>>> git.rev_list(commit="origin..HEAD", max_count=1, header=True)
'...'
symbolic_ref(*, name, ref=None, message=None, short=None, delete=None, quiet=None, check_returncode=None, **kwargs)[source]#

Return symbolic-ref.

Wraps git symbolic-ref.

Return type:

str

Parameters:
  • name (str) –

  • ref (str | None) –

  • message (str | None) –

  • short (bool | None) –

  • delete (bool | None) –

  • quiet (bool | None) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Examples

>>> git = Git(path=git_local_clone.path)
>>> git.symbolic_ref(name="test")
'fatal: ref test is not a symbolic ref'
>>> git.symbolic_ref(name="test")
'fatal: ref test is not a symbolic ref'
show_ref(*, pattern=None, quiet=None, verify=None, head=None, dereference=None, tags=None, _hash=None, abbrev=None, check_returncode=None, **kwargs)[source]#

show-ref. Wraps git show-ref.

Return type:

str

Parameters:
  • pattern (str | list[str] | None) –

  • quiet (bool | None) –

  • verify (bool | None) –

  • head (bool | None) –

  • dereference (bool | None) –

  • tags (bool | None) –

  • _hash (str | bool | None) –

  • abbrev (str | bool | None) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Examples

>>> git = Git(path=git_local_clone.path)
>>> git.show_ref()
'...'
>>> git.show_ref(pattern='master')
'...'
>>> git.show_ref(pattern='master', head=True)
'...'
>>> git.show_ref(pattern='HEAD', verify=True)
'... HEAD'
>>> git.show_ref(pattern='master', dereference=True)
'... refs/heads/master\n... refs/remotes/origin/master'
>>> git.show_ref(pattern='HEAD', tags=True)
''