Remotes
Repository.
remotes
The collection of configured remotes, an instance of
pygit2.remote.RemoteCollection
- Create a new remote. Return a
object.
This method is deprecated, please use Remote.remotes.create()
The remote collection
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
- >>> repo.remotes["origin"]
addfetch
(_name, refspec)Add a fetch refspec (str) to the remote
Add a push refspec (str) to the remote
- 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
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.
The Remote type
Parameters:
- prune :enum
- 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
Return the
object at the given position. Name of the remote
Perform a prune against this remote.
- 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:
- specs :[str]
- Push refspecs to use.
push_refspecs
Refspecs that will be used for pushing
Push url of the remote
Total number of refspecs in this remote
Save a remote to its repository’s configuration.
- 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:
- certificate :None
- The certificate. It is currently always None while we figure outhow to represent it cross-platform.
- valid :bool
- Whether the TLS/SSH library thinks the certificate is valid.
- host :str
- 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:
- url :str
- The url of the remote.
- username_from_url :str or None
- Username extracted from the url, if any.
- allowed_types :int
- 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:
- string :str
- Progress output from the remote.
transferprogress
(_stats)- Transfer progress callback. Override with your own function to reporttransfer progress.
Parameters:
- stats :TransferProgress
- The progress up to now.
updatetips
(_refname, old, new)- Update tips callabck. Override with your own function to reportreference updates.
Parameters:
- refname :str
- The name of the reference that’s being updated.
- old :Oid
- The reference’s old value.
- new :Oid
- The reference’s 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
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)
Destinaton or rhs of the refspec
Return True if the given string matches the destination of thisrefspec, False otherwise.
Whether this refspeca llows non-fast-forward updates
Transform a reference name according to this refspec from the lhs tothe rhs. Return an string.
Source or lhs of the refspec
Return True if the given string matches the source of this refspec,False otherwise.
String which was used to create this refspec
- 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.
This is an object suitable for passing to a remote’s credentialscallback and for returning from said callback.
This is an object suitable for passing to a remote’s credentialscallback and for returning from said callback.
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.