1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 4 * This file is part of libgit2, distributed under the GNU GPL v2 with 5 * a Linking Exception. For full terms see the included COPYING file. 6 */ 7 /** 8 * License: GPL-2.0(Linking Exception) 9 */ 10 module libgit2.remote; 11 12 13 private static import libgit2.buffer; 14 private static import libgit2.cert; 15 private static import libgit2.credential; 16 private static import libgit2.indexer; 17 private static import libgit2.net; 18 private static import libgit2.oid; 19 private static import libgit2.pack; 20 private static import libgit2.proxy; 21 private static import libgit2.strarray; 22 private static import libgit2.transport; 23 private static import libgit2.types; 24 private import libgit2.common: GIT_EXTERN; 25 26 /* 27 * @file git2/remote.h 28 * @brief Git remote management functions 29 * @defgroup git_remote remote management functions 30 * @ingroup Git 31 * @{ 32 */ 33 extern (C): 34 nothrow @nogc: 35 public: 36 37 /** 38 * Add a remote with the default fetch refspec to the repository's 39 * configuration. 40 * 41 * Params: 42 * out_ = the resulting remote 43 * repo = the repository in which to create the remote 44 * name = the remote's name 45 * url = the remote's url 46 * 47 * Returns: 0, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EEXISTS or an error code 48 */ 49 @GIT_EXTERN 50 int git_remote_create(libgit2.types.git_remote** out_, libgit2.types.git_repository* repo, const (char)* name, const (char)* url); 51 52 /** 53 * Remote redirection settings; whether redirects to another host 54 * are permitted. By default, git will follow a redirect on the 55 * initial request (`/info/refs`), but not subsequent requests. 56 */ 57 enum git_remote_redirect_t 58 { 59 /** 60 * Do not follow any off-site redirects at any stage of 61 * the fetch or push. 62 */ 63 GIT_REMOTE_REDIRECT_NONE = 1 << 0, 64 65 /** 66 * Allow off-site redirects only upon the initial request. 67 * This is the default. 68 */ 69 GIT_REMOTE_REDIRECT_INITIAL = 1 << 1, 70 71 /** 72 * Allow redirects at any stage in the fetch or push. 73 */ 74 GIT_REMOTE_REDIRECT_ALL = 1 << 2, 75 } 76 77 //Declaration name in C language 78 enum 79 { 80 GIT_REMOTE_REDIRECT_NONE = .git_remote_redirect_t.GIT_REMOTE_REDIRECT_NONE, 81 GIT_REMOTE_REDIRECT_INITIAL = .git_remote_redirect_t.GIT_REMOTE_REDIRECT_INITIAL, 82 GIT_REMOTE_REDIRECT_ALL = .git_remote_redirect_t.GIT_REMOTE_REDIRECT_ALL, 83 } 84 85 /** 86 * Remote creation options flags 87 */ 88 enum git_remote_create_flags 89 { 90 /** 91 * Ignore the repository apply.insteadOf configuration 92 */ 93 GIT_REMOTE_CREATE_SKIP_INSTEADOF = 1 << 0, 94 95 /** 96 * Don't build a fetchspec from the name if none is set 97 */ 98 GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC = 1 << 1, 99 } 100 101 //Declaration name in C language 102 enum 103 { 104 GIT_REMOTE_CREATE_SKIP_INSTEADOF = .git_remote_create_flags.GIT_REMOTE_CREATE_SKIP_INSTEADOF, 105 GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC = .git_remote_create_flags.GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC, 106 } 107 108 /** 109 * Remote creation options structure 110 * 111 * Initialize with `GIT_REMOTE_CREATE_OPTIONS_INIT`. Alternatively, you can 112 * use `git_remote_create_options_init`. 113 * 114 */ 115 struct git_remote_create_options 116 { 117 uint version_; 118 119 /** 120 * The repository that should own the remote. 121 * Setting this to null results in a detached remote. 122 */ 123 libgit2.types.git_repository* repository; 124 125 /** 126 * The remote's name. 127 * Setting this to null results in an in-memory/anonymous remote. 128 */ 129 const (char)* name; 130 131 /** 132 * The fetchspec the remote should use. 133 */ 134 const (char)* fetchspec; 135 136 /** 137 * Additional flags for the remote. See git_remote_create_flags. 138 */ 139 uint flags; 140 } 141 142 enum GIT_REMOTE_CREATE_OPTIONS_VERSION = 1; 143 144 pragma(inline, true) 145 pure nothrow @safe @nogc @live 146 .git_remote_create_options GIT_REMOTE_CREATE_OPTIONS_INIT() 147 148 do 149 { 150 .git_remote_create_options OUTPUT = 151 { 152 version_: GIT_REMOTE_CREATE_OPTIONS_VERSION, 153 }; 154 155 return OUTPUT; 156 } 157 158 /** 159 * Initialize git_remote_create_options structure 160 * 161 * Initializes a `git_remote_create_options` with default values. Equivalent to 162 * creating an instance with `GIT_REMOTE_CREATE_OPTIONS_INIT`. 163 * 164 * Params: 165 * opts = The `git_remote_create_options` struct to initialize. 166 * version_ = The struct version; pass `GIT_REMOTE_CREATE_OPTIONS_VERSION`. 167 * 168 * Returns: Zero on success; -1 on failure. 169 */ 170 @GIT_EXTERN 171 int git_remote_create_options_init(.git_remote_create_options* opts, uint version_); 172 173 /** 174 * Create a remote, with options. 175 * 176 * This function allows more fine-grained control over the remote creation. 177 * 178 * Passing null as the opts argument will result in a detached remote. 179 * 180 * Params: 181 * out_ = the resulting remote 182 * url = the remote's url 183 * opts = the remote creation options 184 * 185 * Returns: 0, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EEXISTS or an error code 186 */ 187 @GIT_EXTERN 188 int git_remote_create_with_opts(libgit2.types.git_remote** out_, const (char)* url, const (.git_remote_create_options)* opts); 189 190 /** 191 * Add a remote with the provided fetch refspec (or default if null) to the 192 * repository's configuration. 193 * 194 * Params: 195 * out_ = the resulting remote 196 * repo = the repository in which to create the remote 197 * name = the remote's name 198 * url = the remote's url 199 * fetch = the remote fetch value 200 * 201 * Returns: 0, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EEXISTS or an error code 202 */ 203 @GIT_EXTERN 204 int git_remote_create_with_fetchspec(libgit2.types.git_remote** out_, libgit2.types.git_repository* repo, const (char)* name, const (char)* url, const (char)* fetch); 205 206 /** 207 * Create an anonymous remote 208 * 209 * Create a remote with the given url in-memory. You can use this when 210 * you have a URL instead of a remote's name. 211 * 212 * Params: 213 * out_ = pointer to the new remote objects 214 * repo = the associated repository 215 * url = the remote repository's URL 216 * 217 * Returns: 0 or an error code 218 */ 219 @GIT_EXTERN 220 int git_remote_create_anonymous(libgit2.types.git_remote** out_, libgit2.types.git_repository* repo, const (char)* url); 221 222 /** 223 * Create a remote without a connected local repo 224 * 225 * Create a remote with the given url in-memory. You can use this when 226 * you have a URL instead of a remote's name. 227 * 228 * Contrasted with git_remote_create_anonymous, a detached remote 229 * will not consider any repo configuration values (such as insteadof url 230 * substitutions). 231 * 232 * Params: 233 * out_ = pointer to the new remote objects 234 * url = the remote repository's URL 235 * 236 * Returns: 0 or an error code 237 */ 238 @GIT_EXTERN 239 int git_remote_create_detached(libgit2.types.git_remote** out_, const (char)* url); 240 241 /** 242 * Get the information for a particular remote 243 * 244 * The name will be checked for validity. 245 * See `git_tag_create()` for rules about valid names. 246 * 247 * Params: 248 * out_ = pointer to the new remote object 249 * repo = the associated repository 250 * name = the remote's name 251 * 252 * Returns: 0, git_error_code.GIT_ENOTFOUND, git_error_code.GIT_EINVALIDSPEC or an error code 253 */ 254 @GIT_EXTERN 255 int git_remote_lookup(libgit2.types.git_remote** out_, libgit2.types.git_repository* repo, const (char)* name); 256 257 /** 258 * Create a copy of an existing remote. All internal strings are also 259 * duplicated. Callbacks are not duplicated. 260 * 261 * Call `git_remote_free` to free the data. 262 * 263 * Params: 264 * dest = pointer where to store the copy 265 * source = object to copy 266 * 267 * Returns: 0 or an error code 268 */ 269 @GIT_EXTERN 270 int git_remote_dup(libgit2.types.git_remote** dest, libgit2.types.git_remote* source); 271 272 /** 273 * Get the remote's repository 274 * 275 * Params: 276 * remote = the remote 277 * 278 * Returns: a pointer to the repository 279 */ 280 @GIT_EXTERN 281 libgit2.types.git_repository* git_remote_owner(const (libgit2.types.git_remote)* remote); 282 283 /** 284 * Get the remote's name 285 * 286 * Params: 287 * remote = the remote 288 * 289 * Returns: a pointer to the name or null for in-memory remotes 290 */ 291 @GIT_EXTERN 292 const (char)* git_remote_name(const (libgit2.types.git_remote)* remote); 293 294 /** 295 * Get the remote's url 296 * 297 * If url.*.insteadOf has been configured for this URL, it will 298 * return the modified URL. If `git_remote_set_instance_pushurl` 299 * has been called for this remote, then that URL will be returned. 300 * 301 * Params: 302 * remote = the remote 303 * 304 * Returns: a pointer to the url 305 */ 306 @GIT_EXTERN 307 const (char)* git_remote_url(const (libgit2.types.git_remote)* remote); 308 309 /** 310 * Get the remote's url for pushing. 311 * 312 * If url.*.pushInsteadOf has been configured for this URL, it 313 * will return the modified URL. If `git_remote_set_instance_pushurl` 314 * has been called for this remote, then that URL will be returned. 315 * 316 * Params: 317 * remote = the remote 318 * 319 * Returns: a pointer to the url or null if no special url for pushing is set 320 */ 321 @GIT_EXTERN 322 const (char)* git_remote_pushurl(const (libgit2.types.git_remote)* remote); 323 324 /** 325 * Set the remote's url in the configuration 326 * 327 * Remote objects already in memory will not be affected. This assumes 328 * the common case of a single-url remote and will otherwise return an error. 329 * 330 * Params: 331 * repo = the repository in which to perform the change 332 * remote = the remote's name 333 * url = the url to set 334 * 335 * Returns: 0 or an error value 336 */ 337 @GIT_EXTERN 338 int git_remote_set_url(libgit2.types.git_repository* repo, const (char)* remote, const (char)* url); 339 340 /** 341 * Set the remote's url for pushing in the configuration. 342 * 343 * Remote objects already in memory will not be affected. This assumes 344 * the common case of a single-url remote and will otherwise return an error. 345 * 346 * 347 * Params: 348 * repo = the repository in which to perform the change 349 * remote = the remote's name 350 * url = the url to set 351 * 352 * Returns: 0, or an error code 353 */ 354 @GIT_EXTERN 355 int git_remote_set_pushurl(libgit2.types.git_repository* repo, const (char)* remote, const (char)* url); 356 357 /** 358 * Set the url for this particular url instance. The URL in the 359 * configuration will be ignored, and will not be changed. 360 * 361 * Params: 362 * remote = the remote's name 363 * url = the url to set 364 * 365 * Returns: 0 or an error value 366 */ 367 @GIT_EXTERN 368 int git_remote_set_instance_url(libgit2.types.git_remote* remote, const (char)* url); 369 370 /** 371 * Set the push url for this particular url instance. The URL in the 372 * configuration will be ignored, and will not be changed. 373 * 374 * Params: 375 * remote = the remote's name 376 * url = the url to set 377 * 378 * Returns: 0 or an error value 379 */ 380 @GIT_EXTERN 381 int git_remote_set_instance_pushurl(libgit2.types.git_remote* remote, const (char)* url); 382 383 /** 384 * Add a fetch refspec to the remote's configuration 385 * 386 * Add the given refspec to the fetch list in the configuration. No 387 * loaded remote instances will be affected. 388 * 389 * Params: 390 * repo = the repository in which to change the configuration 391 * remote = the name of the remote to change 392 * refspec = the new fetch refspec 393 * 394 * Returns: 0, git_error_code.GIT_EINVALIDSPEC if refspec is invalid or an error value 395 */ 396 @GIT_EXTERN 397 int git_remote_add_fetch(libgit2.types.git_repository* repo, const (char)* remote, const (char)* refspec); 398 399 /** 400 * Get the remote's list of fetch refspecs 401 * 402 * The memory is owned by the user and should be freed with 403 * `git_strarray_free`. 404 * 405 * Params: 406 * array = pointer to the array in which to store the strings 407 * remote = the remote to query 408 * 409 * Returns: 0 or an error code. 410 */ 411 @GIT_EXTERN 412 int git_remote_get_fetch_refspecs(libgit2.strarray.git_strarray* array, const (libgit2.types.git_remote)* remote); 413 414 /** 415 * Add a push refspec to the remote's configuration 416 * 417 * Add the given refspec to the push list in the configuration. No 418 * loaded remote instances will be affected. 419 * 420 * Params: 421 * repo = the repository in which to change the configuration 422 * remote = the name of the remote to change 423 * refspec = the new push refspec 424 * 425 * Returns: 0, git_error_code.GIT_EINVALIDSPEC if refspec is invalid or an error value 426 */ 427 @GIT_EXTERN 428 int git_remote_add_push(libgit2.types.git_repository* repo, const (char)* remote, const (char)* refspec); 429 430 /** 431 * Get the remote's list of push refspecs 432 * 433 * The memory is owned by the user and should be freed with 434 * `git_strarray_free`. 435 * 436 * Params: 437 * array = pointer to the array in which to store the strings 438 * remote = the remote to query 439 * 440 * Returns: 0 or an error code. 441 */ 442 @GIT_EXTERN 443 int git_remote_get_push_refspecs(libgit2.strarray.git_strarray* array, const (libgit2.types.git_remote)* remote); 444 445 /** 446 * Get the number of refspecs for a remote 447 * 448 * Params: 449 * remote = the remote 450 * 451 * Returns: the amount of refspecs configured in this remote 452 */ 453 @GIT_EXTERN 454 size_t git_remote_refspec_count(const (libgit2.types.git_remote)* remote); 455 456 /** 457 * Get a refspec from the remote 458 * 459 * Params: 460 * remote = the remote to query 461 * n = the refspec to get 462 * 463 * Returns: the nth refspec 464 */ 465 @GIT_EXTERN 466 const (libgit2.types.git_refspec)* git_remote_get_refspec(const (libgit2.types.git_remote)* remote, size_t n); 467 468 /** 469 * Get the remote repository's reference advertisement list 470 * 471 * Get the list of references with which the server responds to a new 472 * connection. 473 * 474 * The remote (or more exactly its transport) must have connected to 475 * the remote repository. This list is available as soon as the 476 * connection to the remote is initiated and it remains available 477 * after disconnecting. 478 * 479 * The memory belongs to the remote. The pointer will be valid as long 480 * as a new connection is not initiated, but it is recommended that 481 * you make a copy in order to make use of the data. 482 * 483 * Params: 484 * out_ = pointer to the array 485 * size = the number of remote heads 486 * remote = the remote 487 * 488 * Returns: 0 on success, or an error code 489 */ 490 @GIT_EXTERN 491 int git_remote_ls(const (libgit2.types.git_remote_head)*** out_, size_t* size, libgit2.types.git_remote* remote); 492 493 /** 494 * Check whether the remote is connected 495 * 496 * Check whether the remote's underlying transport is connected to the 497 * remote host. 498 * 499 * Params: 500 * remote = the remote 501 * 502 * Returns: 1 if it's connected, 0 otherwise. 503 */ 504 @GIT_EXTERN 505 int git_remote_connected(const (libgit2.types.git_remote)* remote); 506 507 /** 508 * Cancel the operation 509 * 510 * At certain points in its operation, the network code checks whether 511 * the operation has been cancelled and if so stops the operation. 512 * 513 * Params: 514 * remote = the remote 515 * 516 * Returns: 0 on success, or an error code 517 */ 518 @GIT_EXTERN 519 int git_remote_stop(libgit2.types.git_remote* remote); 520 521 /** 522 * Disconnect from the remote 523 * 524 * Close the connection to the remote. 525 * 526 * Params: 527 * remote = the remote to disconnect from 528 * 529 * Returns: 0 on success, or an error code 530 */ 531 @GIT_EXTERN 532 int git_remote_disconnect(libgit2.types.git_remote* remote); 533 534 /** 535 * Free the memory associated with a remote 536 * 537 * This also disconnects from the remote, if the connection 538 * has not been closed yet (using git_remote_disconnect). 539 * 540 * Params: 541 * remote = the remote to free 542 */ 543 @GIT_EXTERN 544 void git_remote_free(libgit2.types.git_remote* remote); 545 546 /** 547 * Get a list of the configured remotes for a repo 548 * 549 * The string array must be freed by the user. 550 * 551 * Params: 552 * out_ = a string array which receives the names of the remotes 553 * repo = the repository to query 554 * 555 * Returns: 0 or an error code 556 */ 557 @GIT_EXTERN 558 int git_remote_list(libgit2.strarray.git_strarray* out_, libgit2.types.git_repository* repo); 559 560 /** 561 * Argument to the completion callback which tells it which operation 562 * finished. 563 */ 564 enum git_remote_completion_t 565 { 566 GIT_REMOTE_COMPLETION_DOWNLOAD, 567 GIT_REMOTE_COMPLETION_INDEXING, 568 GIT_REMOTE_COMPLETION_ERROR, 569 } 570 571 //Declaration name in C language 572 enum 573 { 574 GIT_REMOTE_COMPLETION_DOWNLOAD = .git_remote_completion_t.GIT_REMOTE_COMPLETION_DOWNLOAD, 575 GIT_REMOTE_COMPLETION_INDEXING = .git_remote_completion_t.GIT_REMOTE_COMPLETION_INDEXING, 576 GIT_REMOTE_COMPLETION_ERROR = .git_remote_completion_t.GIT_REMOTE_COMPLETION_ERROR, 577 } 578 579 /** 580 * Push network progress notification function 581 */ 582 alias git_push_transfer_progress_cb = int function(uint current, uint total, size_t bytes, void* payload); 583 584 /** 585 * Represents an update which will be performed on the remote during push 586 */ 587 struct git_push_update 588 { 589 /** 590 * The source name of the reference 591 */ 592 char* src_refname; 593 594 /** 595 * The name of the reference to update on the server 596 */ 597 char* dst_refname; 598 599 /** 600 * The current target of the reference 601 */ 602 libgit2.oid.git_oid src; 603 604 /** 605 * The new target for the reference 606 */ 607 libgit2.oid.git_oid dst; 608 } 609 610 /** 611 * Callback used to inform of upcoming updates. 612 */ 613 /* 614 * Params: 615 * updates = an array containing the updates which will be sent as commands to the destination. 616 * len = number of elements in `updates` 617 * payload = Payload provided by the caller 618 */ 619 alias git_push_negotiation = int function(const (.git_push_update)** updates, size_t len, void* payload); 620 621 /** 622 * Callback used to inform of the update status from the remote. 623 * 624 * Called for each updated reference on push. If `status` is 625 * not `null`, the update was rejected by the remote server 626 * and `status` contains the reason given. 627 * 628 * Returns: 0 on success, otherwise an error 629 */ 630 /* 631 * Params: 632 * refname = refname specifying to the remote ref 633 * status = status message sent from the remote 634 * data = data provided by the caller 635 */ 636 alias git_push_update_reference_cb = int function(const (char)* refname, const (char)* status, void* data); 637 638 version (GIT_DEPRECATE_HARD) { 639 } else { 640 /** 641 * Callback to resolve URLs before connecting to remote 642 * 643 * If you return GIT_PASSTHROUGH, you don't need to write anything to 644 * url_resolved. 645 * 646 * @param url_resolved The buffer to write the resolved URL to 647 * @param url The URL to resolve 648 * @param direction GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH 649 * @param payload Payload provided by the caller 650 * @return 0 on success, GIT_PASSTHROUGH or an error 651 * @deprecated Use `git_remote_set_instance_url` 652 */ 653 alias git_url_resolve_cb = int function(libgit2.buffer.git_buf* url_resolved, const (char)* url, int direction, void* payload); 654 } 655 656 /** 657 * Callback invoked immediately before we attempt to connect to the 658 * given url. Callers may change the URL before the connection by 659 * calling `git_remote_set_instance_url` in the callback. 660 * 661 * Returns: 0 on success, or an error 662 */ 663 /* 664 * Params: 665 * remote = The remote to be connected 666 * direction = git_direction.GIT_DIRECTION_FETCH or git_direction.GIT_DIRECTION_PUSH 667 * payload = Payload provided by the caller 668 */ 669 alias git_remote_ready_cb = int function(libgit2.types.git_remote* remote, int direction, void* payload); 670 671 /** 672 * The callback settings structure 673 * 674 * Set the callbacks to be called by the remote when informing the user 675 * about the progress of the network operations. 676 */ 677 struct git_remote_callbacks 678 { 679 /** 680 * The version 681 */ 682 uint version_; 683 684 /** 685 * Textual progress from the remote. Text send over the 686 * progress side-band will be passed to this function (this is 687 * the 'counting objects' output). 688 */ 689 libgit2.transport.git_transport_message_cb sideband_progress; 690 691 /** 692 * Completion is called when different parts of the download 693 * process are done (currently unused). 694 */ 695 int function(.git_remote_completion_t type, void* data) completion; 696 697 /** 698 * This will be called if the remote host requires 699 * authentication in order to connect to it. 700 * 701 * Returning git_error_code.GIT_PASSTHROUGH will make libgit2 behave as 702 * though this field isn't set. 703 */ 704 libgit2.credential.git_credential_acquire_cb credentials; 705 706 /** 707 * If cert verification fails, this will be called to let the 708 * user make the final decision of whether to allow the 709 * connection to proceed. Returns 0 to allow the connection 710 * or a negative value to indicate an error. 711 */ 712 libgit2.cert.git_transport_certificate_check_cb certificate_check; 713 714 /** 715 * During the download of new data, this will be regularly 716 * called with the current count of progress done by the 717 * indexer. 718 */ 719 libgit2.indexer.git_indexer_progress_cb transfer_progress; 720 721 /** 722 * Each time a reference is updated locally, this function 723 * will be called with information about it. 724 */ 725 int function(const (char)* refname, const (libgit2.oid.git_oid)* a, const (libgit2.oid.git_oid)* b, void* data) update_tips; 726 727 /** 728 * Function to call with progress information during pack 729 * building. Be aware that this is called inline with pack 730 * building operations, so performance may be affected. 731 */ 732 libgit2.pack.git_packbuilder_progress pack_progress; 733 734 /** 735 * Function to call with progress information during the 736 * upload portion of a push. Be aware that this is called 737 * inline with pack building operations, so performance may be 738 * affected. 739 */ 740 .git_push_transfer_progress_cb push_transfer_progress; 741 742 /** 743 * See documentation of git_push_update_reference_cb 744 */ 745 .git_push_update_reference_cb push_update_reference; 746 747 /** 748 * Called once between the negotiation step and the upload. It 749 * provides information about what updates will be performed. 750 */ 751 .git_push_negotiation push_negotiation; 752 753 /** 754 * Create the transport to use for this operation. Leave null 755 * to auto-detect. 756 */ 757 libgit2.transport.git_transport_cb transport; 758 759 /** 760 * Callback when the remote is ready to connect. 761 */ 762 .git_remote_ready_cb remote_ready; 763 764 /** 765 * This will be passed to each of the callbacks in this struct 766 * as the last parameter. 767 */ 768 void* payload; 769 770 version (GIT_DEPRECATE_HARD) { 771 void* reserved; 772 } else { 773 /** 774 * Resolve URL before connecting to remote. 775 * The returned URL will be used to connect to the remote instead. 776 * 777 * This callback is deprecated; users should use 778 * git_remote_ready_cb and configure the instance URL instead. 779 */ 780 .git_url_resolve_cb resolve_url; 781 } 782 } 783 784 enum GIT_REMOTE_CALLBACKS_VERSION = 1; 785 786 pragma(inline, true) 787 pure nothrow @safe @nogc @live 788 .git_remote_callbacks GIT_REMOTE_CALLBACKS_INIT() 789 790 do 791 { 792 .git_remote_callbacks OUTPUT = 793 { 794 version_: .GIT_REMOTE_CALLBACKS_VERSION, 795 }; 796 797 return OUTPUT; 798 } 799 800 /** 801 * Initializes a `git_remote_callbacks` with default values. Equivalent to 802 * creating an instance with GIT_REMOTE_CALLBACKS_INIT. 803 * 804 * Params: 805 * opts = the `git_remote_callbacks` struct to initialize 806 * version_ = Version of struct; pass `GIT_REMOTE_CALLBACKS_VERSION` 807 * 808 * Returns: Zero on success; -1 on failure. 809 */ 810 @GIT_EXTERN 811 int git_remote_init_callbacks(.git_remote_callbacks* opts, uint version_); 812 813 /** 814 * Acceptable prune settings when fetching 815 */ 816 enum git_fetch_prune_t 817 { 818 /** 819 * Use the setting from the configuration 820 */ 821 GIT_FETCH_PRUNE_UNSPECIFIED, 822 823 /** 824 * Force pruning on 825 */ 826 GIT_FETCH_PRUNE, 827 828 /** 829 * Force pruning off 830 */ 831 GIT_FETCH_NO_PRUNE, 832 } 833 834 //Declaration name in C language 835 enum 836 { 837 GIT_FETCH_PRUNE_UNSPECIFIED = .git_fetch_prune_t.GIT_FETCH_PRUNE_UNSPECIFIED, 838 GIT_FETCH_PRUNE = .git_fetch_prune_t.GIT_FETCH_PRUNE, 839 GIT_FETCH_NO_PRUNE = .git_fetch_prune_t.GIT_FETCH_NO_PRUNE, 840 } 841 842 /** 843 * Automatic tag following option 844 * 845 * Lets us select the --tags option to use. 846 */ 847 enum git_remote_autotag_option_t 848 { 849 /** 850 * Use the setting from the configuration. 851 */ 852 GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED = 0, 853 854 /** 855 * Ask the server for tags pointing to objects we're already 856 * downloading. 857 */ 858 GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 859 860 /** 861 * Don't ask for any tags beyond the refspecs. 862 */ 863 GIT_REMOTE_DOWNLOAD_TAGS_NONE, 864 865 /** 866 * Ask for the all the tags. 867 */ 868 GIT_REMOTE_DOWNLOAD_TAGS_ALL, 869 } 870 871 //Declaration name in C language 872 enum 873 { 874 GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED = .git_remote_autotag_option_t.GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, 875 GIT_REMOTE_DOWNLOAD_TAGS_AUTO = .git_remote_autotag_option_t.GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 876 GIT_REMOTE_DOWNLOAD_TAGS_NONE = .git_remote_autotag_option_t.GIT_REMOTE_DOWNLOAD_TAGS_NONE, 877 GIT_REMOTE_DOWNLOAD_TAGS_ALL = .git_remote_autotag_option_t.GIT_REMOTE_DOWNLOAD_TAGS_ALL, 878 } 879 880 /** 881 * Fetch options structure. 882 * 883 * Zero out for defaults. Initialize with `GIT_FETCH_OPTIONS_INIT` macro to 884 * correctly set the `version_` field. E.g. 885 * 886 * git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; 887 */ 888 struct git_fetch_options 889 { 890 int version_; 891 892 /** 893 * Callbacks to use for this fetch operation 894 */ 895 .git_remote_callbacks callbacks; 896 897 /** 898 * Whether to perform a prune after the fetch 899 */ 900 .git_fetch_prune_t prune; 901 902 /** 903 * Whether to write the results to FETCH_HEAD. Defaults to 904 * on. Leave this default in order to behave like git. 905 */ 906 int update_fetchhead; 907 908 /** 909 * Determines how to behave regarding tags on the remote, such 910 * as auto-downloading tags for objects we're downloading or 911 * downloading all of them. 912 * 913 * The default is to auto-follow tags. 914 */ 915 .git_remote_autotag_option_t download_tags; 916 917 /** 918 * Proxy options to use, by default no proxy is used. 919 */ 920 libgit2.proxy.git_proxy_options proxy_opts; 921 922 /** 923 * Whether to allow off-site redirects. If this is not 924 * specified, the `http.followRedirects` configuration setting 925 * will be consulted. 926 */ 927 .git_remote_redirect_t follow_redirects; 928 929 /** 930 * Extra headers for this fetch operation 931 */ 932 libgit2.strarray.git_strarray custom_headers; 933 } 934 935 enum GIT_FETCH_OPTIONS_VERSION = 1; 936 937 pragma(inline, true) 938 pure nothrow @safe @nogc @live 939 .git_fetch_options GIT_FETCH_OPTIONS_INIT() 940 941 do 942 { 943 .git_fetch_options OUTPUT = 944 { 945 version_: .GIT_FETCH_OPTIONS_VERSION, 946 callbacks: .GIT_REMOTE_CALLBACKS_INIT(), 947 prune: .git_fetch_prune_t.GIT_FETCH_PRUNE_UNSPECIFIED, 948 update_fetchhead: 1, 949 download_tags: .git_remote_autotag_option_t.GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, 950 proxy_opts: libgit2.proxy.GIT_PROXY_OPTIONS_INIT(), 951 }; 952 953 return OUTPUT; 954 } 955 956 /** 957 * Initialize git_fetch_options structure 958 * 959 * Initializes a `git_fetch_options` with default values. Equivalent to 960 * creating an instance with `GIT_FETCH_OPTIONS_INIT`. 961 * 962 * Params: 963 * opts = The `git_fetch_options` struct to initialize. 964 * version_ = The struct version; pass `GIT_FETCH_OPTIONS_VERSION`. 965 * 966 * Returns: Zero on success; -1 on failure. 967 */ 968 @GIT_EXTERN 969 int git_fetch_options_init(.git_fetch_options* opts, uint version_); 970 971 /** 972 * Controls the behavior of a git_push object. 973 */ 974 struct git_push_options 975 { 976 uint version_; 977 978 /** 979 * If the transport being used to push to the remote requires the creation 980 * of a pack file, this controls the number of worker threads used by 981 * the packbuilder when creating that pack file to be sent to the remote. 982 * 983 * If set to 0, the packbuilder will auto-detect the number of threads 984 * to create. The default value is 1. 985 */ 986 uint pb_parallelism; 987 988 /** 989 * Callbacks to use for this push operation 990 */ 991 .git_remote_callbacks callbacks; 992 993 /** 994 * Proxy options to use, by default no proxy is used. 995 */ 996 libgit2.proxy.git_proxy_options proxy_opts; 997 998 /** 999 * Whether to allow off-site redirects. If this is not 1000 * specified, the `http.followRedirects` configuration setting 1001 * will be consulted. 1002 */ 1003 git_remote_redirect_t follow_redirects; 1004 1005 /** 1006 * Extra headers for this push operation 1007 */ 1008 libgit2.strarray.git_strarray custom_headers; 1009 } 1010 1011 enum GIT_PUSH_OPTIONS_VERSION = 1; 1012 1013 pragma(inline, true) 1014 pure nothrow @safe @nogc @live 1015 .git_push_options GIT_PUSH_OPTIONS_INIT() 1016 1017 do 1018 { 1019 .git_push_options OUTPUT = 1020 { 1021 version_: .GIT_PUSH_OPTIONS_VERSION, 1022 pb_parallelism: 1, 1023 callbacks: .GIT_REMOTE_CALLBACKS_INIT(), 1024 proxy_opts: libgit2.proxy.GIT_PROXY_OPTIONS_INIT(), 1025 }; 1026 1027 return OUTPUT; 1028 } 1029 1030 /** 1031 * Initialize git_push_options structure 1032 * 1033 * Initializes a `git_push_options` with default values. Equivalent to 1034 * creating an instance with `GIT_PUSH_OPTIONS_INIT`. 1035 * 1036 * Params: 1037 * opts = The `git_push_options` struct to initialize. 1038 * version_ = The struct version; pass `GIT_PUSH_OPTIONS_VERSION`. 1039 * 1040 * Returns: Zero on success; -1 on failure. 1041 */ 1042 @GIT_EXTERN 1043 int git_push_options_init(.git_push_options* opts, uint version_); 1044 1045 /** 1046 * Remote creation options structure 1047 * 1048 * Initialize with `GIT_REMOTE_CREATE_OPTIONS_INIT`. Alternatively, you can 1049 * use `git_remote_create_options_init`. 1050 * 1051 */ 1052 struct git_remote_connect_options 1053 { 1054 uint version_; 1055 1056 /** 1057 * Callbacks to use for this connection 1058 */ 1059 .git_remote_callbacks callbacks; 1060 1061 /** 1062 * HTTP Proxy settings 1063 */ 1064 libgit2.proxy.git_proxy_options proxy_opts; 1065 1066 /** 1067 * Whether to allow off-site redirects. If this is not 1068 * specified, the `http.followRedirects` configuration setting 1069 * will be consulted. 1070 */ 1071 .git_remote_redirect_t follow_redirects; 1072 1073 /** 1074 * Extra HTTP headers to use in this connection 1075 */ 1076 libgit2.strarray.git_strarray custom_headers; 1077 } 1078 1079 enum GIT_REMOTE_CONNECT_OPTIONS_VERSION = 1; 1080 1081 pragma(inline, true) 1082 pure nothrow @safe @nogc @live 1083 .git_remote_connect_options GIT_REMOTE_CONNECT_OPTIONS_INIT() 1084 1085 do 1086 { 1087 .git_remote_connect_options OUTPUT = 1088 { 1089 version_: .GIT_REMOTE_CONNECT_OPTIONS_VERSION, 1090 callbacks: .GIT_REMOTE_CALLBACKS_INIT(), 1091 proxy_opts: libgit2.proxy.GIT_PROXY_OPTIONS_INIT(), 1092 }; 1093 1094 return OUTPUT; 1095 } 1096 1097 /** 1098 * Initialize git_remote_connect_options structure. 1099 * 1100 * Initializes a `git_remote_connect_options` with default values. 1101 * Equivalent to creating an instance with 1102 * `GIT_REMOTE_CONNECT_OPTIONS_INIT`. 1103 * 1104 * Params: 1105 * opts = The `git_remote_connect_options` struct to initialize. 1106 * version_ = The struct version; pass `GIT_REMOTE_CONNECT_OPTIONS_VERSION`. 1107 * 1108 * Returns: Zero on success; -1 on failure. 1109 */ 1110 @GIT_EXTERN 1111 int git_remote_connect_options_init(.git_remote_connect_options* opts, uint version_); 1112 1113 /** 1114 * Open a connection to a remote. 1115 * 1116 * The transport is selected based on the URL; the direction argument 1117 * is due to a limitation of the git protocol which starts up a 1118 * specific binary which can only do the one or the other. 1119 * 1120 * Params: 1121 * remote = the remote to connect to 1122 * direction = GIT_DIRECTION_FETCH if you want to fetch or GIT_DIRECTION_PUSH if you want to push 1123 * callbacks = the callbacks to use for this connection 1124 * proxy_opts = proxy settings 1125 * custom_headers = extra HTTP headers to use in this connection 1126 * 1127 * Returns: 0 or an error code 1128 */ 1129 @GIT_EXTERN 1130 int git_remote_connect(libgit2.types.git_remote* remote, libgit2.net.git_direction direction, const (.git_remote_callbacks)* callbacks, const (libgit2.proxy.git_proxy_options)* proxy_opts, const (libgit2.strarray.git_strarray)* custom_headers); 1131 1132 /** 1133 * Open a connection to a remote with extended options. 1134 * 1135 * The transport is selected based on the URL; the direction argument 1136 * is due to a limitation of the git protocol which starts up a 1137 * specific binary which can only do the one or the other. 1138 * 1139 * The given options structure will form the defaults for connection 1140 * options and callback setup. Callers may override these defaults 1141 * by specifying `git_fetch_options` or `git_push_options` in 1142 * subsequent calls. 1143 * 1144 * Params: 1145 * remote = the remote to connect to 1146 * direction = GIT_DIRECTION_FETCH if you want to fetch or GIT_DIRECTION_PUSH if you want to push 1147 * opts = the remote connection options 1148 * 1149 * Returns: 0 or an error code 1150 */ 1151 @GIT_EXTERN 1152 int git_remote_connect_ext(libgit2.types.git_remote* remote, libgit2.net.git_direction direction, const (.git_remote_connect_options)* opts); 1153 1154 /** 1155 * Download and index the packfile 1156 * 1157 * Connect to the remote if it hasn't been done yet, negotiate with 1158 * the remote git which objects are missing, download and index the 1159 * packfile. 1160 * 1161 * The .idx file will be created and both it and the packfile with be 1162 * renamed to their final name. 1163 * 1164 * If options are specified and this remote is already connected then 1165 * the existing remote connection options will be discarded and the 1166 * remote will now use the new options. 1167 * 1168 * Params: 1169 * remote = the remote 1170 * refspecs = the refspecs to use for this negotiation and download. Use null or an empty array to use the base refspecs 1171 * opts = the options to use for this fetch or null 1172 * 1173 * Returns: 0 or an error code 1174 */ 1175 @GIT_EXTERN 1176 int git_remote_download(libgit2.types.git_remote* remote, const (libgit2.strarray.git_strarray)* refspecs, const (.git_fetch_options)* opts); 1177 1178 /** 1179 * Create a packfile and send it to the server 1180 * 1181 * Connect to the remote if it hasn't been done yet, negotiate with 1182 * the remote git which objects are missing, create a packfile with 1183 * the missing objects and send it. 1184 * 1185 * If options are specified and this remote is already connected then 1186 * the existing remote connection options will be discarded and the 1187 * remote will now use the new options. 1188 * 1189 * Params: 1190 * remote = the remote 1191 * refspecs = the refspecs to use for this negotiation and upload. Use null or an empty array to use the base refspecs 1192 * opts = the options to use for this push 1193 * 1194 * Returns: 0 or an error code 1195 */ 1196 @GIT_EXTERN 1197 int git_remote_upload(libgit2.types.git_remote* remote, const (libgit2.strarray.git_strarray)* refspecs, const (.git_push_options)* opts); 1198 1199 /** 1200 * Update the tips to the new state. 1201 * 1202 * If callbacks are not specified then the callbacks specified to 1203 * `git_remote_connect` will be used (if it was called). 1204 * 1205 * Params: 1206 * remote = the remote to update 1207 * reflog_message = The message to insert into the reflogs. If null and fetching, the default is "fetch <name>", where <name> is the name of the remote (or its url, for in-memory remotes). This parameter is ignored when pushing. 1208 * callbacks = pointer to the callback structure to use or null 1209 * update_fetchhead = whether to write to FETCH_HEAD. Pass 1 to behave like git. 1210 * download_tags = what the behaviour for downloading tags is for this fetch. This is ignored for push. This must be the same value passed to `git_remote_download()`. 1211 * 1212 * Returns: 0 or an error code 1213 */ 1214 @GIT_EXTERN 1215 int git_remote_update_tips(libgit2.types.git_remote* remote, const (.git_remote_callbacks)* callbacks, int update_fetchhead, .git_remote_autotag_option_t download_tags, const (char)* reflog_message); 1216 1217 /** 1218 * Download new data and update tips. 1219 * 1220 * Convenience function to connect to a remote, download the data, 1221 * disconnect and update the remote-tracking branches. 1222 * 1223 * If options are specified and this remote is already connected then 1224 * the existing remote connection options will be discarded and the 1225 * remote will now use the new options. 1226 * 1227 * Params: 1228 * remote = the remote to fetch from 1229 * refspecs = the refspecs to use for this fetch. Pass null or an empty array to use the base refspecs. 1230 * opts = options to use for this fetch or null 1231 * reflog_message = The message to insert into the reflogs. If null, the default is "fetch" 1232 * 1233 * Returns: 0 or an error code 1234 */ 1235 @GIT_EXTERN 1236 int git_remote_fetch(libgit2.types.git_remote* remote, const (libgit2.strarray.git_strarray)* refspecs, const (.git_fetch_options)* opts, const (char)* reflog_message); 1237 1238 /** 1239 * Prune tracking refs that are no longer present on remote. 1240 * 1241 * If callbacks are not specified then the callbacks specified to 1242 * `git_remote_connect` will be used (if it was called). 1243 * 1244 * Params: 1245 * remote = the remote to prune 1246 * callbacks = callbacks to use for this prune 1247 * 1248 * Returns: 0 or an error code 1249 */ 1250 @GIT_EXTERN 1251 int git_remote_prune(libgit2.types.git_remote* remote, const (.git_remote_callbacks)* callbacks); 1252 1253 /** 1254 * Perform a push. 1255 * 1256 * If options are specified and this remote is already connected then 1257 * the existing remote connection options will be discarded and the 1258 * remote will now use the new options. 1259 * 1260 * Params: 1261 * remote = the remote to push to 1262 * refspecs = the refspecs to use for pushing. If null or an empty array, the configured refspecs will be used 1263 * opts = options to use for this push 1264 * 1265 * Returns: 0 or an error code. 1266 */ 1267 @GIT_EXTERN 1268 int git_remote_push(libgit2.types.git_remote* remote, const (libgit2.strarray.git_strarray)* refspecs, const (.git_push_options)* opts); 1269 1270 /** 1271 * Get the statistics structure that is filled in by the fetch operation. 1272 */ 1273 @GIT_EXTERN 1274 const (libgit2.indexer.git_indexer_progress)* git_remote_stats(libgit2.types.git_remote* remote); 1275 1276 /** 1277 * Retrieve the tag auto-follow setting 1278 * 1279 * Params: 1280 * remote = the remote to query 1281 * 1282 * Returns: the auto-follow setting 1283 */ 1284 @GIT_EXTERN 1285 .git_remote_autotag_option_t git_remote_autotag(const (libgit2.types.git_remote)* remote); 1286 1287 /** 1288 * Set the remote's tag following setting. 1289 * 1290 * The change will be made in the configuration. No loaded remotes 1291 * will be affected. 1292 * 1293 * Params: 1294 * repo = the repository in which to make the change 1295 * remote = the name of the remote 1296 * value = the new value to take. 1297 * 1298 * Returns: 0, or an error code. 1299 */ 1300 @GIT_EXTERN 1301 int git_remote_set_autotag(libgit2.types.git_repository* repo, const (char)* remote, .git_remote_autotag_option_t value); 1302 1303 /** 1304 * Retrieve the ref-prune setting 1305 * 1306 * Params: 1307 * remote = the remote to query 1308 * 1309 * Returns: the ref-prune setting 1310 */ 1311 @GIT_EXTERN 1312 int git_remote_prune_refs(const (libgit2.types.git_remote)* remote); 1313 1314 /** 1315 * Give the remote a new name 1316 * 1317 * All remote-tracking branches and configuration settings 1318 * for the remote are updated. 1319 * 1320 * The new name will be checked for validity. 1321 * See `git_tag_create()` for rules about valid names. 1322 * 1323 * No loaded instances of a the remote with the old name will change 1324 * their name or their list of refspecs. 1325 * 1326 * Params: 1327 * problems = non-default refspecs cannot be renamed and will be stored here for further processing by the caller. Always free this strarray on successful return. 1328 * repo = the repository in which to rename 1329 * name = the current name of the remote 1330 * new_name = the new name the remote should bear 1331 * 1332 * Returns: 0, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EEXISTS or an error code 1333 */ 1334 @GIT_EXTERN 1335 int git_remote_rename(libgit2.strarray.git_strarray* problems, libgit2.types.git_repository* repo, const (char)* name, const (char)* new_name); 1336 1337 /** 1338 * Ensure the remote name is well-formed. 1339 * 1340 * Params: 1341 * valid = output pointer to set with validity of given remote name 1342 * remote_name = name to be checked. 1343 * 1344 * Returns: 0 on success or an error code 1345 */ 1346 @GIT_EXTERN 1347 int git_remote_name_is_valid(int* valid, const (char)* remote_name); 1348 1349 /** 1350 * Delete an existing persisted remote. 1351 * 1352 * All remote-tracking branches and configuration settings 1353 * for the remote will be removed. 1354 * 1355 * Params: 1356 * repo = the repository in which to act 1357 * name = the name of the remote to delete 1358 * 1359 * Returns: 0 on success, or an error code. 1360 */ 1361 @GIT_EXTERN 1362 int git_remote_delete(libgit2.types.git_repository* repo, const (char)* name); 1363 1364 /** 1365 * Retrieve the name of the remote's default branch 1366 * 1367 * The default branch of a repository is the branch which HEAD points 1368 * to. If the remote does not support reporting this information 1369 * directly, it performs the guess as git does; that is, if there are 1370 * multiple branches which point to the same commit, the first one is 1371 * chosen. If the master branch is a candidate, it wins. 1372 * 1373 * This function must only be called after connecting. 1374 * 1375 * Params: 1376 * out_ = the buffer in which to store the reference name 1377 * remote = the remote 1378 * 1379 * Returns: 0, git_error_code.GIT_ENOTFOUND if the remote does not have any references or none of them point to HEAD's commit, or an error message. 1380 */ 1381 @GIT_EXTERN 1382 int git_remote_default_branch(libgit2.buffer.git_buf* out_, libgit2.types.git_remote* remote); 1383 1384 /* @} */