Remotes
This method is deprecated, please use Remote.remotes.create()
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
addfetch
(_name, refspec)Add a fetch refspec (str) to the remote
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
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
- class
pygit2.
Remote
(repo, ptr)
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
Name of the remote
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:
push_refspecs
Refspecs that will be used for pushing
Total number of refspecs in this remote
Save a remote to its repository’s configuration.
url
- Url of the remote
- 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:
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:
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
indexeddeltas
= None_Deltas which have been indexed
Objects which have been indexed
localobjects
= None_“Number of bytes received up to now
receivedobjects
= None_Objects which have been received up to now
Total number of deltas in the pack
- Total number of objects to download
Refspecs objects are not constructed directly, but returned by. 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
dstmatches
(_ref)Return True if the given string matches the destination of thisrefspec, False otherwise.
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.
Source or lhs of the refspec
srcmatches
(_ref)Return True if the given string matches the source of this refspec,False otherwise.
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.
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.
- 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.