dulwich.client module

Client side support for the Git protocol.

The Dulwich client supports the following capabilities:

  • thin-pack

  • multi_ack_detailed

  • multi_ack

  • side-band-64k

  • ofs-delta

  • quiet

  • report-status

  • delete-refs

  • shallow

Known capabilities that are not supported:

  • no-progress

  • include-tag

class dulwich.client.AbstractHttpGitClient(base_url, dumb=False, **kwargs)

Bases: GitClient

Abstract base class for HTTP Git Clients.

This is agonistic of the actual HTTP implementation.

Subclasses should provide an implementation of the _http_request method.

Create a new GitClient instance.

Parameters
  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

  • include_tags – send annotated tags when sending the objects they point to

fetch_pack(path, determine_wants, graph_walker, pack_data, progress=None, depth=None)

Retrieve a pack from a git smart server.

Parameters
  • path – Path to fetch from

  • determine_wants – Callback that returns list of commits to fetch

  • graph_walker – Object with next() and ack().

  • pack_data – Callback called for each bit of data in the pack

  • progress – Callback for progress reports (strings)

  • depth – Depth for request

Returns

FetchPackResult object

classmethod from_parsedurl(parsedurl, **kwargs)

Create an instance of this client from a urlparse.parsed object.

Parameters

parsedurl – Result of urlparse()

Returns

A GitClient object

get_refs(path)

Retrieve the current refs from a git smart server.

get_url(path)

Retrieves full url to given path.

Parameters

path – Repository path (as string)

Returns

Url to path (as string)

send_pack(path, update_refs, generate_pack_data, progress=None)

Upload a pack to a remote repository.

Parameters
  • path – Repository path (as bytestring)

  • update_refs – Function to determine changes to remote refs. Receives dict with existing remote refs, returns dict with changed refs (name -> sha, where sha=ZERO_SHA for deletions)

  • generate_pack_data – Function that can return a tuple with number of elements and pack data to upload.

  • progress – Optional progress function

Returns

SendPackResult

Raises

SendPackError – if server rejects the pack data

class dulwich.client.FetchPackResult(refs, symrefs, agent, new_shallow=None, new_unshallow=None)

Bases: object

Result of a fetch-pack operation.

refs

Dictionary with all remote refs

symrefs

Dictionary with remote symrefs

agent

User agent string

class dulwich.client.GitClient(thin_packs=True, report_activity=None, quiet=False, include_tags=False)

Bases: object

Git smart server client.

Create a new GitClient instance.

Parameters
  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

  • include_tags – send annotated tags when sending the objects they point to

archive(path, committish, write_data, progress=None, write_error=None, format=None, subdirs=None, prefix=None)

Retrieve an archive of the specified tree.

clone(path, target_path, mkdir: bool = True, bare=False, origin='origin', checkout=None, branch=None, progress=None, depth=None)

Clone a repository.

fetch(path: str, target: Repo, determine_wants: Optional[Callable[[Dict[bytes, bytes], Optional[int]], List[bytes]]] = None, progress: Optional[Callable[[bytes], None]] = None, depth: Optional[int] = None) FetchPackResult

Fetch into a target repository.

Parameters
  • path – Path to fetch from (as bytestring)

  • target – Target repository to fetch into

  • determine_wants – Optional function to determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch. Defaults to all shas.

  • progress – Optional progress function

  • depth – Depth to fetch at

Returns

Dictionary with all remote refs (not just those fetched)

fetch_pack(path, determine_wants, graph_walker, pack_data, progress=None, depth=None)

Retrieve a pack from a git smart server.

Parameters
  • path – Remote path to fetch from

  • determine_wants – Function determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch.

  • graph_walker – Object with next() and ack().

  • pack_data – Callback called for each bit of data in the pack

  • progress – Callback for progress reports (strings)

  • depth – Shallow fetch depth

Returns

FetchPackResult object

classmethod from_parsedurl(parsedurl, **kwargs)

Create an instance of this client from a urlparse.parsed object.

Parameters

parsedurl – Result of urlparse()

Returns

A GitClient object

get_refs(path)

Retrieve the current refs from a git smart server.

Parameters

path – Path to the repo to fetch from. (as bytestring)

Returns:

get_url(path)

Retrieves full url to given path.

Parameters

path – Repository path (as string)

Returns

Url to path (as string)

send_pack(path, update_refs, generate_pack_data, progress=None)

Upload a pack to a remote repository.

Parameters
  • path – Repository path (as bytestring)

  • update_refs – Function to determine changes to remote refs. Receive dict with existing remote refs, returns dict with changed refs (name -> sha, where sha=ZERO_SHA for deletions)

  • generate_pack_data – Function that can return a tuple with number of objects and list of pack data to include

  • progress – Optional progress function

Returns

SendPackResult object

Raises

SendPackError – if server rejects the pack data

exception dulwich.client.HTTPProxyUnauthorized(proxy_authenticate, url)

Bases: Exception

Raised when proxy authentication fails.

exception dulwich.client.HTTPUnauthorized(www_authenticate, url)

Bases: Exception

Raised when authentication fails.

dulwich.client.HttpGitClient

alias of Urllib3HttpGitClient

exception dulwich.client.InvalidWants(wants)

Bases: Exception

Invalid wants.

class dulwich.client.LocalGitClient(thin_packs=True, report_activity=None, config: Optional[Config] = None)

Bases: GitClient

Git Client that just uses a local Repo.

Create a new LocalGitClient instance.

Parameters
  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

fetch(path, target, determine_wants=None, progress=None, depth=None)

Fetch into a target repository.

Parameters
  • path – Path to fetch from (as bytestring)

  • target – Target repository to fetch into

  • determine_wants – Optional function determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch. Defaults to all shas.

  • progress – Optional progress function

  • depth – Shallow fetch depth

Returns

FetchPackResult object

fetch_pack(path, determine_wants, graph_walker, pack_data, progress=None, depth=None)

Retrieve a pack from a git smart server.

Parameters
  • path – Remote path to fetch from

  • determine_wants – Function determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch.

  • graph_walker – Object with next() and ack().

  • pack_data – Callback called for each bit of data in the pack

  • progress – Callback for progress reports (strings)

  • depth – Shallow fetch depth

Returns

FetchPackResult object

classmethod from_parsedurl(parsedurl, **kwargs)

Create an instance of this client from a urlparse.parsed object.

Parameters

parsedurl – Result of urlparse()

Returns

A GitClient object

get_refs(path)

Retrieve the current refs from a git smart server.

get_url(path)

Retrieves full url to given path.

Parameters

path – Repository path (as string)

Returns

Url to path (as string)

send_pack(path, update_refs, generate_pack_data, progress=None)

Upload a pack to a remote repository.

Parameters
  • path – Repository path (as bytestring)

  • update_refs – Function to determine changes to remote refs. Receive dict with existing remote refs, returns dict with changed refs (name -> sha, where sha=ZERO_SHA for deletions) with number of items and pack data to upload.

  • progress – Optional progress function

Returns

SendPackResult

Raises

SendPackError – if server rejects the pack data

class dulwich.client.PLinkSSHVendor

Bases: SSHVendor

SSH vendor that shells out to the local ‘plink’ command.

run_command(host, command, username=None, port=None, password=None, key_filename=None, ssh_command=None)

Connect to an SSH server.

Run a command remotely and return a file-like object for interaction with the remote command.

Parameters
  • host – Host name

  • command – Command to run (as argv array)

  • username – Optional ame of user to log in as

  • port – Optional SSH port to use

  • password – Optional ssh password for login or private key

  • key_filename – Optional path to private keyfile

  • ssh_command – Optional SSH command

Returns:

dulwich.client.ParamikoSSHVendor(**kwargs)
class dulwich.client.ReportStatusParser

Bases: object

Handle status as reported by servers with ‘report-status’ capability.

check()

Check if there were any errors and, if so, raise exceptions.

Raises

SendPackError – Raised when the server could not unpack

Returns

iterator over refs

handle_packet(pkt)

Handle a packet.

Raises
  • GitProtocolError – Raised when packets are received after a flush

  • packet.

class dulwich.client.SSHGitClient(host, port=None, username=None, vendor=None, config=None, password=None, key_filename=None, ssh_command=None, **kwargs)

Bases: TraditionalGitClient

Create a new GitClient instance.

Parameters
  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

  • include_tags – send annotated tags when sending the objects they point to

classmethod from_parsedurl(parsedurl, **kwargs)

Create an instance of this client from a urlparse.parsed object.

Parameters

parsedurl – Result of urlparse()

Returns

A GitClient object

get_url(path)

Retrieves full url to given path.

Parameters

path – Repository path (as string)

Returns

Url to path (as string)

class dulwich.client.SSHVendor

Bases: object

A client side SSH implementation.

run_command(host, command, username=None, port=None, password=None, key_filename=None, ssh_command=None)

Connect to an SSH server.

Run a command remotely and return a file-like object for interaction with the remote command.

Parameters
  • host – Host name

  • command – Command to run (as argv array)

  • username – Optional ame of user to log in as

  • port – Optional SSH port to use

  • password – Optional ssh password for login or private key

  • key_filename – Optional path to private keyfile

  • ssh_command – Optional SSH command

Returns:

class dulwich.client.SendPackResult(refs, agent=None, ref_status=None)

Bases: object

Result of a upload-pack operation.

refs

Dictionary with all remote refs

agent

User agent string

ref_status

Optional dictionary mapping ref name to error message (if it failed to update), or None if it was updated successfully

exception dulwich.client.StrangeHostname(hostname)

Bases: Exception

Refusing to connect to strange SSH hostname.

class dulwich.client.SubprocessGitClient(path_encoding='utf-8', **kwargs)

Bases: TraditionalGitClient

Git client that talks to a server using a subprocess.

Create a new GitClient instance.

Parameters
  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

  • include_tags – send annotated tags when sending the objects they point to

classmethod from_parsedurl(parsedurl, **kwargs)

Create an instance of this client from a urlparse.parsed object.

Parameters

parsedurl – Result of urlparse()

Returns

A GitClient object

git_command = None
class dulwich.client.SubprocessSSHVendor

Bases: SSHVendor

SSH vendor that shells out to the local ‘ssh’ command.

run_command(host, command, username=None, port=None, password=None, key_filename=None, ssh_command=None)

Connect to an SSH server.

Run a command remotely and return a file-like object for interaction with the remote command.

Parameters
  • host – Host name

  • command – Command to run (as argv array)

  • username – Optional ame of user to log in as

  • port – Optional SSH port to use

  • password – Optional ssh password for login or private key

  • key_filename – Optional path to private keyfile

  • ssh_command – Optional SSH command

Returns:

class dulwich.client.SubprocessWrapper(proc)

Bases: object

A socket-like object that talks to a subprocess via pipes.

can_read()
close()
property stderr
class dulwich.client.TCPGitClient(host, port=None, **kwargs)

Bases: TraditionalGitClient

A Git Client that works over TCP directly (i.e. git://).

Create a new GitClient instance.

Parameters
  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

  • include_tags – send annotated tags when sending the objects they point to

classmethod from_parsedurl(parsedurl, **kwargs)

Create an instance of this client from a urlparse.parsed object.

Parameters

parsedurl – Result of urlparse()

Returns

A GitClient object

get_url(path)

Retrieves full url to given path.

Parameters

path – Repository path (as string)

Returns

Url to path (as string)

class dulwich.client.TraditionalGitClient(path_encoding='utf-8', **kwargs)

Bases: GitClient

Traditional Git client.

Create a new GitClient instance.

Parameters
  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

  • include_tags – send annotated tags when sending the objects they point to

DEFAULT_ENCODING = 'utf-8'
archive(path, committish, write_data, progress=None, write_error=None, format=None, subdirs=None, prefix=None)

Retrieve an archive of the specified tree.

fetch_pack(path, determine_wants, graph_walker, pack_data, progress=None, depth=None)

Retrieve a pack from a git smart server.

Parameters
  • path – Remote path to fetch from

  • determine_wants – Function determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch.

  • graph_walker – Object with next() and ack().

  • pack_data – Callback called for each bit of data in the pack

  • progress – Callback for progress reports (strings)

  • depth – Shallow fetch depth

Returns

FetchPackResult object

get_refs(path)

Retrieve the current refs from a git smart server.

send_pack(path, update_refs, generate_pack_data, progress=None)

Upload a pack to a remote repository.

Parameters
  • path – Repository path (as bytestring)

  • update_refs – Function to determine changes to remote refs. Receive dict with existing remote refs, returns dict with changed refs (name -> sha, where sha=ZERO_SHA for deletions)

  • generate_pack_data – Function that can return a tuple with number of objects and pack data to upload.

  • progress – Optional callback called with progress updates

Returns

SendPackResult

Raises

SendPackError – if server rejects the pack data

class dulwich.client.Urllib3HttpGitClient(base_url, dumb=None, pool_manager=None, config=None, username=None, password=None, **kwargs)

Bases: AbstractHttpGitClient

Create a new GitClient instance.

Parameters
  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

  • include_tags – send annotated tags when sending the objects they point to

dulwich.client.check_for_proxy_bypass(base_url)
dulwich.client.check_wants(wants, refs)

Check that a set of wants is valid.

Parameters
  • wants – Set of object SHAs to fetch

  • refs – Refs dictionary to check against

Returns:

dulwich.client.default_local_git_client_cls

alias of LocalGitClient

dulwich.client.default_urllib3_manager(config, pool_manager_cls=None, proxy_manager_cls=None, base_url=None, **override_kwargs) Union[urllib3.ProxyManager, urllib3.PoolManager]

Return urllib3 connection pool manager.

Honour detected proxy configurations.

Parameters
  • configdulwich.config.ConfigDict instance with Git configuration.

  • override_kwargs – Additional arguments for urllib3.ProxyManager

Returns

Either pool_manager_cls (defaults to urllib3.ProxyManager) instance for proxy configurations, proxy_manager_cls (defaults to urllib3.PoolManager) instance otherwise

dulwich.client.default_user_agent_string()
dulwich.client.find_git_command() List[str]

Find command to run for system Git (usually C Git).

dulwich.client.get_credentials_from_store(scheme, hostname, username=None, fnames=['/root/.git-credentials', '/root/.config/git/credentials'])
dulwich.client.get_ssh_vendor

alias of SubprocessSSHVendor

dulwich.client.get_transport_and_path(location: str, config: Optional[Config] = None, operation: Optional[str] = None, **kwargs: Any) Tuple[GitClient, str]

Obtain a git client from a URL.

Parameters
  • location – URL or path (a string)

  • config – Optional config object

  • operation – Kind of operation that’ll be performed; “pull” or “push”

  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

Returns

Tuple with client instance and relative path.

dulwich.client.get_transport_and_path_from_url(url: str, config: Optional[Config] = None, operation: Optional[str] = None, **kwargs) Tuple[GitClient, str]

Obtain a git client from a URL.

Parameters
  • url – URL to open (a unicode string)

  • config – Optional config object

  • operation – Kind of operation that’ll be performed; “pull” or “push”

  • thin_packs – Whether or not thin packs should be retrieved

  • report_activity – Optional callback for reporting transport activity.

Returns

Tuple with client instance and relative path.

dulwich.client.parse_rsync_url(location: str) Tuple[Optional[str], str, str]

Parse a rsync-style URL.

dulwich.client.read_pkt_refs(pkt_seq)