| 1 | package Git::Raw::Remote; | ||
| 2 | 1 | $Git::Raw::Remote::VERSION = '0.90'; | |
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use Git::Raw; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Git::Raw::Remote - Git remote class | ||
| 11 | |||
| 12 | =head1 VERSION | ||
| 13 | |||
| 14 | version 0.90 | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | use Git::Raw; | ||
| 19 | |||
| 20 | # open the Git repository at $path | ||
| 21 | my $repo = Git::Raw::Repository -> open($path); | ||
| 22 | |||
| 23 | # add a new remote | ||
| 24 | my $remote = Git::Raw::Remote -> create($repo, 'origin', $url); | ||
| 25 | |||
| 26 | # connect the remote and set the acquire credentials callback | ||
| 27 | $remote -> connect('fetch', { | ||
| 28 | 'credentials' => sub { | ||
| 29 | Git::Raw::Cred -> userpass($usr, $pwd) | ||
| 30 | }, | ||
| 31 | }); | ||
| 32 | |||
| 33 | # fetch from the remote and update the local tips | ||
| 34 | $remote -> download; | ||
| 35 | $remote -> update_tips({ | ||
| 36 | 'update_tips' => sub { | ||
| 37 | my ($ref, $a, $b) = @_; | ||
| 38 | print "Updated $ref: $a -> $b", "\n"; | ||
| 39 | } | ||
| 40 | }); | ||
| 41 | |||
| 42 | # disconnect | ||
| 43 | $remote -> disconnect; | ||
| 44 | |||
| 45 | my $empty_repo = Git::Raw::Repository -> new; | ||
| 46 | my $anonymous_remote = Git::Raw::Remote -> create_anonymous($repo, $url); | ||
| 47 | my $list = $anonymous_remote -> ls; | ||
| 48 | |||
| 49 | =head1 DESCRIPTION | ||
| 50 | |||
| 51 | A C<Git::Raw::Remote> represents a Git remote. | ||
| 52 | |||
| 53 | B<WARNING>: The API of this module is unstable and may change without warning | ||
| 54 | (any change will be appropriately documented in the changelog). | ||
| 55 | |||
| 56 | =head1 METHODS | ||
| 57 | |||
| 58 | =head2 create( $repo, $name, $url, [$fetch] ) | ||
| 59 | |||
| 60 | Create a remote with the default fetch refspec or C<$fetch> if | ||
| 61 | provided, and add it to the repository's configuration. | ||
| 62 | |||
| 63 | =head2 create_anonymous( $repo, $url ) | ||
| 64 | |||
| 65 | Create a remote in memory (anonymous). | ||
| 66 | |||
| 67 | =head2 load( $repo, $name ) | ||
| 68 | |||
| 69 | Load an existing remote. Returns a L<Git::Raw::Remote> object if the remote | ||
| 70 | was found, otherwise C<undef>. | ||
| 71 | |||
| 72 | =head2 delete( $repo, $name ) | ||
| 73 | |||
| 74 | Delete an existing remote. | ||
| 75 | |||
| 76 | =head2 owner( ) | ||
| 77 | |||
| 78 | Retrieve the L<Git::Raw::Repository> owning the remote. | ||
| 79 | |||
| 80 | =head2 default_branch( ) | ||
| 81 | |||
| 82 | Retrieve the default branch of remote repository, that is, the branch which | ||
| 83 | HEAD points to. If the remote does not support reporting this information | ||
| 84 | directly, it performs the guess as git does, that is, if there are multiple | ||
| 85 | branches which point to the same commit, the first one is chosen. If the master | ||
| 86 | branch is a candidate, it wins. If the information cannot be determined, this | ||
| 87 | function will return C<undef>. B<Note>, this function should only be called after | ||
| 88 | the remote has established a connection. | ||
| 89 | |||
| 90 | =head2 name( ) | ||
| 91 | |||
| 92 | Retrieve the name of the remote. | ||
| 93 | |||
| 94 | =head2 rename( $repo, $old_name, $new_name, [ \@problems ] ) | ||
| 95 | |||
| 96 | Rename a remote. Non-default refspecs cannot be renamed and will be stored in | ||
| 97 | C<@problems> if provided. | ||
| 98 | |||
| 99 | =head2 url( [ $url ] ) | ||
| 100 | |||
| 101 | Retrieve the URL of the remote. If C<$url> is passed, the remote's URL will be | ||
| 102 | updated and returned. | ||
| 103 | |||
| 104 | =head2 pushurl( [ $url ] ) | ||
| 105 | |||
| 106 | Retrieve the push URL for the remote. If C<$url> is passed, the remote's push | ||
| 107 | URL will be updated and returned. | ||
| 108 | |||
| 109 | =head2 add_fetch( $spec ) | ||
| 110 | |||
| 111 | Add a fetch spec to the remote. | ||
| 112 | |||
| 113 | =head2 add_push( $spec ) | ||
| 114 | |||
| 115 | Add a push spec to the remote. | ||
| 116 | |||
| 117 | =head2 refspec_count( ) | ||
| 118 | |||
| 119 | Retrieve the refspec count. | ||
| 120 | |||
| 121 | =head2 refspecs( ) | ||
| 122 | |||
| 123 | Retrieve the remote's refspecs. Returns a list of L<Git::Raw::RefSpec> objects. | ||
| 124 | |||
| 125 | =head2 ls( ) | ||
| 126 | |||
| 127 | Retrieve the list of refs at the remote. Returns a hash reference where the key | ||
| 128 | is the name of the reference, and the value is a hash reference containing the | ||
| 129 | following values: | ||
| 130 | |||
| 131 | =over 4 | ||
| 132 | |||
| 133 | =item * "local" | ||
| 134 | |||
| 135 | Whether the reference exists locally. | ||
| 136 | |||
| 137 | =item * "id" | ||
| 138 | |||
| 139 | The OID of the reference. | ||
| 140 | |||
| 141 | =item * "lid" | ||
| 142 | |||
| 143 | The local OID of the reference (optional). | ||
| 144 | |||
| 145 | =back | ||
| 146 | |||
| 147 | =head2 fetch( [ \%fetch_opts, [ \@refspecs ] ] ) | ||
| 148 | |||
| 149 | Download new data and update tips. Convenience function to connect to a remote, | ||
| 150 | download the data, disconnect and update the remote-tracking branches. | ||
| 151 | C<@refspecs> is an optional list of refspecs to use for the negotiation with | ||
| 152 | the server to determine the missing objects that need to be downloaded. Valid | ||
| 153 | fields for the C<%fetch_opts> hash are: | ||
| 154 | |||
| 155 | =over 4 | ||
| 156 | |||
| 157 | =item * "callbacks" | ||
| 158 | |||
| 159 | See L<CALLBACKS/"CALLBACKS">. | ||
| 160 | |||
| 161 | =item * "prune" | ||
| 162 | |||
| 163 | NOT IMPLEMENTED. | ||
| 164 | |||
| 165 | =item * "update_fetchead" | ||
| 166 | |||
| 167 | NOT IMPLEMENTED. | ||
| 168 | |||
| 169 | =item * "download_tags" | ||
| 170 | |||
| 171 | NOT IMPLEMENTED. | ||
| 172 | |||
| 173 | =item * "custom_headers" | ||
| 174 | |||
| 175 | NOT IMPLEMENTED. | ||
| 176 | |||
| 177 | =back | ||
| 178 | |||
| 179 | =head2 push( \@refspecs, [ \%push_opts ] ) | ||
| 180 | |||
| 181 | Perform all the steps of a push, including uploading new data and updating the | ||
| 182 | remote tracking-branches. Valid fields for the C<%push_opts> hash are: | ||
| 183 | |||
| 184 | =over 4 | ||
| 185 | |||
| 186 | =item * "callbacks" | ||
| 187 | |||
| 188 | See L<CALLBACKS/"CALLBACKS">. | ||
| 189 | |||
| 190 | =item * "custom_headers" | ||
| 191 | |||
| 192 | NOT IMPLEMENTED. | ||
| 193 | |||
| 194 | =back | ||
| 195 | |||
| 196 | =head2 connect( $direction, [ \%callbacks ] ) | ||
| 197 | |||
| 198 | Connect to the remote. The C<$direction> should either be C<"fetch"> or C<"push">. | ||
| 199 | |||
| 200 | =head2 disconnect( ) | ||
| 201 | |||
| 202 | Disconnect the remote. | ||
| 203 | |||
| 204 | =head2 download( [ \%fetch_opts, [ \@refspecs ] ] ) | ||
| 205 | |||
| 206 | Download the remote packfile. See C<Git::Raw::Remote-E<gt>fetch()> for valid | ||
| 207 | C<%fetch_opts> and C<@refspecs> values. | ||
| 208 | |||
| 209 | =head2 upload( \@refspecs, [ \%push_opts ] ) | ||
| 210 | |||
| 211 | Create a packfile and send it to the server. C<@refspecs> is a list of refspecs | ||
| 212 | to use for the negotiation with the server to determine the missing objects | ||
| 213 | that need to be uploaded. | ||
| 214 | |||
| 215 | =head2 prune( [ \%callbacks ] ) | ||
| 216 | |||
| 217 | Prune tracking refs that are no longer present on remote. | ||
| 218 | |||
| 219 | =head2 update_tips( [ \%callbacks ] ) | ||
| 220 | |||
| 221 | Update the tips to the new status. | ||
| 222 | |||
| 223 | =head2 is_connected( ) | ||
| 224 | |||
| 225 | Check if the remote is connected. | ||
| 226 | |||
| 227 | =head1 CALLBACKS | ||
| 228 | |||
| 229 | =head2 credentials | ||
| 230 | |||
| 231 | The callback to be called any time authentication is required to connect to the | ||
| 232 | remote repository. The callback receives a string C<$url> containing the URL of | ||
| 233 | the remote, the C<$user> extracted from the URL and a list of supported | ||
| 234 | authentication C<$types>. The callback should return either a L<Git::Raw::Cred> | ||
| 235 | object or alternatively C<undef> to abort the authentication process. C<$types> | ||
| 236 | may contain one or more of the following: | ||
| 237 | |||
| 238 | =over 4 | ||
| 239 | |||
| 240 | =item * "userpass_plaintext" | ||
| 241 | |||
| 242 | Plaintext username and password. | ||
| 243 | |||
| 244 | =item * "ssh_key" | ||
| 245 | |||
| 246 | A SSH key from disk | ||
| 247 | |||
| 248 | =item * "ssh_custom" | ||
| 249 | |||
| 250 | A SSH key with a custom signature function. | ||
| 251 | |||
| 252 | =item * "ssh_interactive" | ||
| 253 | |||
| 254 | Keyboard-interactive based SSH authentication | ||
| 255 | |||
| 256 | =item * "username" | ||
| 257 | |||
| 258 | Username-only credential information. | ||
| 259 | |||
| 260 | =item * "default" | ||
| 261 | |||
| 262 | A key for NTLM/Kerberos default credentials. | ||
| 263 | |||
| 264 | =back | ||
| 265 | |||
| 266 | B<Note:> this callback may be invoked more than once. | ||
| 267 | |||
| 268 | =head2 certificate_check | ||
| 269 | |||
| 270 | Callback to be invoked if cert verification fails. The callback receives a | ||
| 271 | L<Git::Raw::Cert::X509> or L<Git::Raw::Cert::HostKey> object, a truthy | ||
| 272 | value C<$valid> and C<$host>. This callback should return a negative number to | ||
| 273 | abort. | ||
| 274 | |||
| 275 | =head2 sideband_progress | ||
| 276 | |||
| 277 | Textual progress from the remote. Text sent over the progress side-band will be | ||
| 278 | passed to this function (this is the 'counting objects' output or any other | ||
| 279 | information the remote sends). The callback receives a string C<$msg> | ||
| 280 | containing the progress information. | ||
| 281 | |||
| 282 | =head2 transfer_progress | ||
| 283 | |||
| 284 | During the download of new data, this will be regularly called with the current | ||
| 285 | count of progress done by the indexer. The callback receives a | ||
| 286 | L<Git::Raw::TransferProgress> object. | ||
| 287 | |||
| 288 | =head2 update_tips | ||
| 289 | |||
| 290 | Each time a reference is updated locally, this function will be called with | ||
| 291 | information about it. The callback receives a string containing the reference | ||
| 292 | C<$ref> of the reference that was updated, and the two OID's C<$a> before and | ||
| 293 | after C<$b> the update. C<$a> will be C<undef> if the reference was created, | ||
| 294 | likewise C<$b> will be C<undef> if the reference was removed. | ||
| 295 | |||
| 296 | =head2 push_transfer_progress | ||
| 297 | |||
| 298 | During the upload of new data, this will regularly be called with the transfer | ||
| 299 | progress. The callback receives the following integers: | ||
| 300 | C<$current>, C<$total> and C<$bytes>. | ||
| 301 | |||
| 302 | =head2 push_update_reference | ||
| 303 | |||
| 304 | For each of the updated references, this will be called with a status report | ||
| 305 | for the reference. The callback receives C<$ref> and C<$msg> as strings. If | ||
| 306 | C<$msg> is defined, the reference mentioned in C<$ref> has not been updated. | ||
| 307 | |||
| 308 | =head2 push_negotation | ||
| 309 | |||
| 310 | The callbacks receives a list of updates that will be sent to the destination. | ||
| 311 | Each items consists of C<$src_refname>, C<$dst_refname> as well as their OIDs, | ||
| 312 | C<$src> and C<$dst>. This callback should return a negative number to abort. | ||
| 313 | |||
| 314 | =head2 pack_progress | ||
| 315 | |||
| 316 | During the packing of new data, this will regularly be called with the progress | ||
| 317 | of the pack operation. Be aware that this is called inline with pack | ||
| 318 | building operations, so performance may be affected. The callback receives the | ||
| 319 | following integers: | ||
| 320 | C<$stage>, C<$current> and C<$total>. | ||
| 321 | |||
| 322 | =head1 AUTHOR | ||
| 323 | |||
| 324 | Alessandro Ghedini <alexbio@cpan.org> | ||
| 325 | |||
| 326 | Jacques Germishuys <jacquesg@cpan.org> | ||
| 327 | |||
| 328 | =head1 LICENSE AND COPYRIGHT | ||
| 329 | |||
| 330 | Copyright 2012 Alessandro Ghedini. | ||
| 331 | |||
| 332 | This program is free software; you can redistribute it and/or modify it | ||
| 333 | under the terms of either: the GNU General Public License as published | ||
| 334 | by the Free Software Foundation; or the Artistic License. | ||
| 335 | |||
| 336 | See http://dev.perl.org/licenses/ for more information. | ||
| 337 | |||
| 338 | =cut | ||
| 339 | |||
| 340 | 1 | 1; # End of Git::Raw::Remote | |