Remotes

  • Repository.remotes
  • The collection of configured remotes, an instance ofpygit2.remote.RemoteCollection

  • Repository.createremote(_name, url)

  • Create a new remote. Return a object.

This method is deprecated, please use Remote.remotes.create()

The remote collection

  • class pygit2.remote.RemoteCollection(repo)
  • Collection of configured remotes

You can use this class to look up and manage the remotes configuredin a repository. You can access repositories using indexaccess. E.g. to look up the “origin” remote, you can use

  1. >>> repo.remotes["origin"]
  • addfetch(_name, refspec)
  • Add a fetch refspec (str) to the remote

  • addpush(_name, refspec)

  • Add a push refspec (str) to the remote

  • create(name, url, fetch=None)

  • Create a new remote with the given name and url. Returns a object.

If ‘fetch’ is provided, this fetch refspec will be used instead of the default

  • delete(name)
  • Remove a remote from the configuration

All remote-tracking branches and configuration settings for the remote will be removed.

  • rename(name, new_name)
  • Rename a remote in the configuration. The refspecs in standardformat will be renamed.

Returns a list of fetch refspecs (list of strings) which were not inthe standard format and thus could not be remapped.

  • setpush_url(_name, url)
  • Set the push-URL for a remote

  • seturl(_name, url)

  • Set the URL for a remote

The Remote type

  • class pygit2.Remote(repo, ptr)
    • fetch(refspecs=None, message=None, callbacks=None, prune=0)
    • Perform a fetch against this remote. Returns a object.

Parameters:

  1. - prune :enum
  2. - Either <git_fetch_prune_unspecified>, <git_fetch_prune>, or<git_fetch_no_prune>. The first uses the configuration from therepo, the second will remove any remote branch in the localrepository that does not exist in the remote and the last willalways keep the remote branches
  • fetch_refspecs
  • Refspecs that will be used for fetching

  • getrefspec(_n)

  • Return the object at the given position.

  • name

  • Name of the remote

  • prune(callbacks=None)

  • Perform a prune against this remote.

  • push(specs, callbacks=None)

  • Push the given refspec to the remote. Raises GitError on protocolerror or unpack failure.

When the remote has a githook installed, that denies the reference thisfunction will return successfully. Thus it is strongly recommended toinstall a callback, that implementsRemoteCallbacks.push_update_reference() and check the passedparameters for successfull operations.

Parameters:

  1. - specs :[str]
  2. - Push refspecs to use.
  • push_refspecs
  • Refspecs that will be used for pushing

  • push_url

  • Push url of the remote

  • refspec_count

  • Total number of refspecs in this remote

  • save()

  • Save a remote to its repository’s configuration.

  • url

  • Url of the remote

The RemoteCallbacks type

  • class pygit2.RemoteCallbacks(credentials=None, certificate=None)
  • Base class for pygit2 remote callbacks.

Inherit from this class and override the callbacks which you want to usein your class, which you can then pass to the network operations.

  • certificatecheck(_certificate, valid, host)
  • Certificate callback. Override with your own function to determinewhether to accept the server’s certificate.

Returns: True to connect, False to abort.

Parameters:

  1. - certificate :None
  2. - The certificate. It is currently always None while we figure outhow to represent it cross-platform.
  3. - valid :bool
  4. - Whether the TLS/SSH library thinks the certificate is valid.
  5. - host :str
  6. - The hostname we want to connect to.
  • credentials(url, username_from_url, allowed_types)
  • Credentials callback. If the remote server requires authentication,this function will be called and its return value used forauthentication. Override it if you want to be able to performauthentication.

Returns: credential

Parameters:

  1. - url :str
  2. - The url of the remote.
  3. - username_from_url :str or None
  4. - Username extracted from the url, if any.
  5. - allowed_types :int
  6. - Credential types supported by the remote.
  • pushupdate_reference(_refname, message)
  • Push update reference callback. Override with your own function toreport the remote’s acceptance or rejection of reference updates.

    • refname :str
    • The name of the reference (on the remote).
    • message :str
    • Rejection message from the remote. If None, the update was accepted.
  • sidebandprogress(_string)
  • Progress output callback. Override this function with your ownprogress reporting function

Parameters:

  1. - string :str
  2. - Progress output from the remote.
  • transferprogress(_stats)
  • Transfer progress callback. Override with your own function to reporttransfer progress.

Parameters:

  1. - stats :TransferProgress
  2. - The progress up to now.
  • updatetips(_refname, old, new)
  • Update tips callabck. Override with your own function to reportreference updates.

Parameters:

  1. - refname :str
  2. - The name of the reference thats being updated.
  3. - old :Oid
  4. - The references old value.
  5. - new :Oid
  6. - The references new value.

The TransferProgress type

This class contains the data which is available to us during a fetch.

  • class pygit2.remote.TransferProgress(tp)
  • Progress downloading and indexing data during a fetch

    • indexeddeltas = None_
    • Deltas which have been indexed

    • indexedobjects = None_

    • Objects which have been indexed

    • localobjects = None_

    • Local objects which were used to fix the thin pack

    • receivedbytes = None_

    • “Number of bytes received up to now

    • receivedobjects = None_

    • Objects which have been received up to now

    • totaldeltas = None_

    • Total number of deltas in the pack

    • totalobjects = None_

    • Total number of objects to download

The Refspec type

Refspecs objects are not constructed directly, but returned bypygit2.Remote.get_refspec(). To create a new a refspec on a Remote, usepygit2.Remote.add_fetch() or pygit2.Remote.add_push().

  • class pygit2.refspec.Refspec(owner, ptr)
  • The constructor is for internal use only

    • direction
    • Direction of this refspec (fetch or push)

    • dst

    • Destinaton or rhs of the refspec

    • dstmatches(_ref)

    • Return True if the given string matches the destination of thisrefspec, False otherwise.

    • force

    • Whether this refspeca llows non-fast-forward updates

    • rtransform(ref)

    • Transform a reference name according to this refspec from the lhs tothe rhs. Return an string.

    • src

    • Source or lhs of the refspec

    • srcmatches(_ref)

    • Return True if the given string matches the source of this refspec,False otherwise.

    • string

    • String which was used to create this refspec

    • transform(ref)

    • Transform a reference name according to this refspec from the lhs tothe rhs. Return an string.

Credentials

There are several types of credentials. All of them are callable objects, withthe appropriate signature for the credentials callback.

They will ignore all the arguments and return themselves. This is useful forscripts where the credentials are known ahead of time. More complete interfaceswould want to look up in their keychain or ask the user for the data to use inthe credentials.

  • class pygit2.Username(username)
  • Username credentials

This is an object suitable for passing to a remote’s credentialscallback and for returning from said callback.

  • class pygit2.UserPass(username, password)
  • Username/Password credentials

This is an object suitable for passing to a remote’s credentialscallback and for returning from said callback.

  • class pygit2.Keypair(username, pubkey, privkey, passphrase)
  • SSH key pair credentials.

This is an object suitable for passing to a remote’s credentialscallback and for returning from said callback.

Parameters:

  • username :str
  • The username being used to authenticate with the remote server.
  • pubkey :str
  • The path to the user’s public key file.
  • privkey :str
  • The path to the user’s private key file.
  • passphrase :str
  • The password used to decrypt the private key file, or empty string ifno passphrase is required.
    • class pygit2.KeypairFromAgent(username)
    • class pygit2.KeypairFromMemory(username, pubkey, privkey, passphrase)