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 module libgit2_d.repository; 8 9 10 private static import libgit2_d.buffer; 11 private static import libgit2_d.oid; 12 private static import libgit2_d.types; 13 private static import std.conv; 14 15 /** 16 * @file git2/repository.h 17 * @brief Git repository management routines 18 * @defgroup git_repository Git repository management routines 19 * @ingroup Git 20 * @{ 21 */ 22 extern (C): 23 nothrow @nogc: 24 public: 25 26 /** 27 * Open a git repository. 28 * 29 * The 'path' argument must point to either a git repository 30 * folder, or an existing work dir. 31 * 32 * The method will automatically detect if 'path' is a normal 33 * or bare repository or fail is 'path' is neither. 34 * 35 * @param out_ pointer to the repo which will be opened 36 * @param path the path to the repository 37 * @return 0 or an error code 38 */ 39 //GIT_EXTERN 40 int git_repository_open(libgit2_d.types.git_repository** out_, const (char)* path); 41 42 /** 43 * Open working tree as a repository 44 * 45 * Open the working directory of the working tree as a normal 46 * repository that can then be worked on. 47 * 48 * @param out_ Output pointer containing opened repository 49 * @param wt Working tree to open 50 * @return 0 or an error code 51 */ 52 //GIT_EXTERN 53 int git_repository_open_from_worktree(libgit2_d.types.git_repository** out_, libgit2_d.types.git_worktree* wt); 54 55 /** 56 * Create a "fake" repository to wrap an object database 57 * 58 * Create a repository object to wrap an object database to be used 59 * with the API when all you have is an object database. This doesn't 60 * have any paths associated with it, so use with care. 61 * 62 * @param out_ pointer to the repo 63 * @param odb the object database to wrap 64 * @return 0 or an error code 65 */ 66 //GIT_EXTERN 67 int git_repository_wrap_odb(libgit2_d.types.git_repository** out_, libgit2_d.types.git_odb* odb); 68 69 /** 70 * Look for a git repository and copy its path in the given buffer. 71 * The lookup start from base_path and walk across parent directories 72 * if nothing has been found. The lookup ends when the first repository 73 * is found, or when reaching a directory referenced in ceiling_dirs 74 * or when the filesystem changes (in case across_fs is true). 75 * 76 * The method will automatically detect if the repository is bare 77 * (if there is a repository). 78 * 79 * @param out_ A pointer to a user-allocated git_buf which will contain 80 * the found path. 81 * 82 * @param start_path The base path where the lookup starts. 83 * 84 * @param across_fs If true, then the lookup will not stop when a 85 * filesystem device change is detected while exploring parent directories. 86 * 87 * @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR separated list of 88 * absolute symbolic link free paths. The lookup will stop when any 89 * of this paths is reached. Note that the lookup always performs on 90 * start_path no matter start_path appears in ceiling_dirs ceiling_dirs 91 * might be null (which is equivalent to an empty string) 92 * 93 * @return 0 or an error code 94 */ 95 //GIT_EXTERN 96 int git_repository_discover(libgit2_d.buffer.git_buf* out_, const (char)* start_path, int across_fs, const (char)* ceiling_dirs); 97 98 /** 99 * Option flags for `git_repository_open_ext`. 100 */ 101 enum git_repository_open_flag_t 102 { 103 /** 104 * Only open the repository if it can be immediately found in the 105 * start_path. Do not walk up from the start_path looking at parent 106 * directories. 107 */ 108 GIT_REPOSITORY_OPEN_NO_SEARCH = 1 << 0, 109 110 /** 111 * Unless this flag is set, open will not continue searching across 112 * filesystem boundaries (i.e. when `st_dev` changes from the `stat` 113 * system call). For example, searching in a user's home directory at 114 * "/home/user/source/" will not return "/.git/" as the found repo if 115 * "/" is a different filesystem than "/home". 116 */ 117 GIT_REPOSITORY_OPEN_CROSS_FS = 1 << 1, 118 119 /** 120 * Open repository as a bare repo regardless of core.bare config, and 121 * defer loading config file for faster setup. 122 * Unlike `git_repository_open_bare`, this can follow gitlinks. 123 */ 124 GIT_REPOSITORY_OPEN_BARE = 1 << 2, 125 126 /** 127 * Do not check for a repository by appending /.git to the start_path; 128 * only open the repository if start_path itself points to the git 129 * directory. 130 */ 131 GIT_REPOSITORY_OPEN_NO_DOTGIT = 1 << 3, 132 133 /** 134 * Find and open a git repository, respecting the environment variables 135 * used by the git command-line tools. 136 * If set, `git_repository_open_ext` will ignore the other flags and 137 * the `ceiling_dirs` argument, and will allow a NULL `path` to use 138 * `GIT_DIR` or search from the current directory. 139 * The search for a repository will respect $GIT_CEILING_DIRECTORIES and 140 * $GIT_DISCOVERY_ACROSS_FILESYSTEM. The opened repository will 141 * respect $GIT_INDEX_FILE, $GIT_NAMESPACE, $GIT_OBJECT_DIRECTORY, and 142 * $GIT_ALTERNATE_OBJECT_DIRECTORIES. 143 * In the future, this flag will also cause `git_repository_open_ext` 144 * to respect $GIT_WORK_TREE and $GIT_COMMON_DIR; currently, 145 * `git_repository_open_ext` with this flag will error out if either 146 * $GIT_WORK_TREE or $GIT_COMMON_DIR is set. 147 */ 148 GIT_REPOSITORY_OPEN_FROM_ENV = 1 << 4, 149 } 150 151 /** 152 * Find and open a repository with extended controls. 153 * 154 * @param out_ Pointer to the repo which will be opened. This can 155 * actually be null if you only want to use the error code to 156 * see if a repo at this path could be opened. 157 * @param path Path to open as git repository. If the flags 158 * permit "searching", then this can be a path to a subdirectory 159 * inside the working directory of the repository. May be null if 160 * flags is git_repository_open_flag_t.GIT_REPOSITORY_OPEN_FROM_ENV. 161 * @param flags A combination of the GIT_REPOSITORY_OPEN flags above. 162 * @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR delimited list of path 163 * prefixes at which the search for a containing repository should 164 * terminate. 165 * @return 0 on success, git_error_code.GIT_ENOTFOUND if no repository could be found, 166 * or -1 if there was a repository but open failed for some reason 167 * (such as repo corruption or system errors). 168 */ 169 //GIT_EXTERN 170 int git_repository_open_ext(libgit2_d.types.git_repository** out_, const (char)* path, uint flags, const (char)* ceiling_dirs); 171 172 /** 173 * Open a bare repository on the serverside. 174 * 175 * This is a fast open for bare repositories that will come in handy 176 * if you're e.g. hosting git repositories and need to access them 177 * efficiently 178 * 179 * @param out_ Pointer to the repo which will be opened. 180 * @param bare_path Direct path to the bare repository 181 * @return 0 on success, or an error code 182 */ 183 //GIT_EXTERN 184 int git_repository_open_bare(libgit2_d.types.git_repository** out_, const (char)* bare_path); 185 186 /** 187 * Free a previously allocated repository 188 * 189 * Note that after a repository is free'd, all the objects it has spawned 190 * will still exist until they are manually closed by the user 191 * with `git_object_free`, but accessing any of the attributes of 192 * an object without a backing repository will result in undefined 193 * behavior 194 * 195 * @param repo repository handle to close. If null nothing occurs. 196 */ 197 //GIT_EXTERN 198 void git_repository_free(libgit2_d.types.git_repository* repo); 199 200 /** 201 * Creates a new Git repository in the given folder. 202 * 203 * TODO: 204 * - Reinit the repository 205 * 206 * @param out_ pointer to the repo which will be created or reinitialized 207 * @param path the path to the repository 208 * @param is_bare if true, a Git repository without a working directory is 209 * created at the pointed path. If false, provided path will be 210 * considered as the working directory into which the .git 211 *directory will be created. 212 * 213 * @return 0 or an error code 214 */ 215 //GIT_EXTERN 216 int git_repository_init(libgit2_d.types.git_repository** out_, const (char)* path, uint is_bare); 217 218 /** 219 * Option flags for `git_repository_init_ext`. 220 * 221 * These flags configure extra behaviors to `git_repository_init_ext`. 222 * In every case, the default behavior is the zero value (i.e. flag is 223 * not set). Just OR the flag values together for the `flags` parameter 224 * when initializing a new repo. Details of individual values are: 225 * 226 * * BARE - Create a bare repository with no working directory. 227 * * NO_REINIT - Return an git_error_code.GIT_EEXISTS error if the repo_path appears to 228 * already be an git repository. 229 * * NO_DOTGIT_DIR - Normally a "/.git/" will be appended to the repo 230 * path for non-bare repos (if it is not already there), but 231 * passing this flag prevents that behavior. 232 * * MKDIR - Make the repo_path (and workdir_path) as needed. Init is 233 * always willing to create the ".git" directory even without this 234 * flag. This flag tells init to create the trailing component of 235 * the repo and workdir paths as needed. 236 * * MKPATH - Recursively make all components of the repo and workdir 237 * paths as necessary. 238 * * EXTERNAL_TEMPLATE - libgit2 normally uses internal templates to 239 * initialize a new repo. This flags enables external templates, 240 * looking the "template_path" from the options if set, or the 241 * `init.templatedir` global config if not, or falling back on 242 * "/usr/share/git-core/templates" if it exists. 243 * * GIT_REPOSITORY_INIT_RELATIVE_GITLINK - If an alternate workdir is 244 * specified, use relative paths for the gitdir and core.worktree. 245 */ 246 enum git_repository_init_flag_t 247 { 248 GIT_REPOSITORY_INIT_BARE = 1u << 0, 249 GIT_REPOSITORY_INIT_NO_REINIT = 1u << 1, 250 GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = 1u << 2, 251 GIT_REPOSITORY_INIT_MKDIR = 1u << 3, 252 GIT_REPOSITORY_INIT_MKPATH = 1u << 4, 253 GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = 1u << 5, 254 GIT_REPOSITORY_INIT_RELATIVE_GITLINK = 1u << 6, 255 } 256 257 /** 258 * Mode options for `git_repository_init_ext`. 259 * 260 * Set the mode field of the `git_repository_init_options` structure 261 * either to the custom mode that you would like, or to one of the 262 * following modes: 263 * 264 * * SHARED_UMASK - Use permissions configured by umask - the default. 265 * * SHARED_GROUP - Use "--shared=group" behavior, chmod'ing the new repo 266 * to be group writable and "g+sx" for sticky group assignment. 267 * * SHARED_ALL - Use "--shared=all" behavior, adding world readability. 268 * * Anything else - Set to custom value. 269 */ 270 enum git_repository_init_mode_t 271 { 272 GIT_REPOSITORY_INIT_SHARED_UMASK = 0, 273 GIT_REPOSITORY_INIT_SHARED_GROUP = std.conv.octal!(2775), 274 GIT_REPOSITORY_INIT_SHARED_ALL = std.conv.octal!(2777), 275 } 276 277 /** 278 * Extended options structure for `git_repository_init_ext`. 279 * 280 * This contains extra options for `git_repository_init_ext` that enable 281 * additional initialization features. The fields are: 282 * 283 * * flags - Combination of GIT_REPOSITORY_INIT flags above. 284 * * mode - Set to one of the standard GIT_REPOSITORY_INIT_SHARED_... 285 * constants above, or to a custom value that you would like. 286 * * workdir_path - The path to the working dir or null for default (i.e. 287 * repo_path parent on non-bare repos). IF THIS IS RELATIVE PATH, 288 * IT WILL BE EVALUATED RELATIVE TO THE REPO_PATH. If this is not 289 * the "natural" working directory, a .git gitlink file will be 290 * created here linking to the repo_path. 291 * * description - If set, this will be used to initialize the "description" 292 * file in the repository, instead of using the template content. 293 * * template_path - When git_repository_init_flag_t.GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE is set, 294 * this contains the path to use for the template directory. If 295 * this is null, the config or default directory options will be 296 * used instead. 297 * * initial_head - The name of the head to point HEAD at. If null, then 298 * this will be treated as "master" and the HEAD ref will be set 299 * to "refs/heads/master". If this begins with "refs/" it will be 300 * used verbatim; otherwise "refs/heads/" will be prefixed. 301 * * origin_url - If this is non-null, then after the rest of the 302 * repository initialization is completed, an "origin" remote 303 * will be added pointing to this URL. 304 */ 305 struct git_repository_init_options 306 { 307 uint version_; 308 uint flags; 309 uint mode; 310 const (char)* workdir_path; 311 const (char)* description; 312 const (char)* template_path; 313 const (char)* initial_head; 314 const (char)* origin_url; 315 } 316 317 enum GIT_REPOSITORY_INIT_OPTIONS_VERSION = 1; 318 319 pragma(inline, true) 320 pure nothrow @safe @nogc 321 .git_repository_init_options GIT_REPOSITORY_INIT_OPTIONS_INIT() 322 323 do 324 { 325 .git_repository_init_options OUTPUT = 326 { 327 version_: .GIT_REPOSITORY_INIT_OPTIONS_VERSION, 328 }; 329 330 return OUTPUT; 331 } 332 333 /** 334 * Initialize git_repository_init_options structure 335 * 336 * Initializes a `git_repository_init_options` with default values. Equivalent to 337 * creating an instance with `GIT_REPOSITORY_INIT_OPTIONS_INIT`. 338 * 339 * @param opts The `git_repository_init_options` struct to initialize. 340 * @param version The struct version; pass `GIT_REPOSITORY_INIT_OPTIONS_VERSION`. 341 * @return Zero on success; -1 on failure. 342 */ 343 //GIT_EXTERN 344 int git_repository_init_options_init(.git_repository_init_options* opts, uint version_); 345 346 /** 347 * Create a new Git repository in the given folder with extended controls. 348 * 349 * This will initialize a new git repository (creating the repo_path 350 * if requested by flags) and working directory as needed. It will 351 * auto-detect the case sensitivity of the file system and if the 352 * file system supports file mode bits correctly. 353 * 354 * @param out_ Pointer to the repo which will be created or reinitialized. 355 * @param repo_path The path to the repository. 356 * @param opts Pointer to git_repository_init_options struct. 357 * @return 0 or an error code on failure. 358 */ 359 //GIT_EXTERN 360 int git_repository_init_ext(libgit2_d.types.git_repository** out_, const (char)* repo_path, .git_repository_init_options* opts); 361 362 /** 363 * Retrieve and resolve the reference pointed at by HEAD. 364 * 365 * The returned `git_reference` will be owned by caller and 366 * `git_reference_free()` must be called when done with it to release the 367 * allocated memory and prevent a leak. 368 * 369 * @param out_ pointer to the reference which will be retrieved 370 * @param repo a repository object 371 * 372 * @return 0 on success, git_error_code.GIT_EUNBORNBRANCH when HEAD points to a non existing 373 * branch, git_error_code.GIT_ENOTFOUND when HEAD is missing; an error code otherwise 374 */ 375 //GIT_EXTERN 376 int git_repository_head(libgit2_d.types.git_reference** out_, libgit2_d.types.git_repository* repo); 377 378 /** 379 * Retrieve the referenced HEAD for the worktree 380 * 381 * @param out_ pointer to the reference which will be retrieved 382 * @param repo a repository object 383 * @param name name of the worktree to retrieve HEAD for 384 * @return 0 when successful, error-code otherwise 385 */ 386 //GIT_EXTERN 387 int git_repository_head_for_worktree(libgit2_d.types.git_reference** out_, libgit2_d.types.git_repository* repo, const (char)* name); 388 389 /** 390 * Check if a repository's HEAD is detached 391 * 392 * A repository's HEAD is detached when it points directly to a commit 393 * instead of a branch. 394 * 395 * @param repo Repo to test 396 * @return 1 if HEAD is detached, 0 if it's not; error code if there 397 * was an error. 398 */ 399 //GIT_EXTERN 400 int git_repository_head_detached(libgit2_d.types.git_repository* repo); 401 402 /** 403 * Check if a worktree's HEAD is detached 404 * 405 * A worktree's HEAD is detached when it points directly to a 406 * commit instead of a branch. 407 * 408 * @param repo a repository object 409 * @param name name of the worktree to retrieve HEAD for 410 * @return 1 if HEAD is detached, 0 if its not; error code if 411 * there was an error 412 */ 413 //GIT_EXTERN 414 int git_repository_head_detached_for_worktree(libgit2_d.types.git_repository* repo, const (char)* name); 415 416 /** 417 * Check if the current branch is unborn 418 * 419 * An unborn branch is one named from HEAD but which doesn't exist in 420 * the refs namespace, because it doesn't have any commit to point to. 421 * 422 * @param repo Repo to test 423 * @return 1 if the current branch is unborn, 0 if it's not; error 424 * code if there was an error 425 */ 426 //GIT_EXTERN 427 int git_repository_head_unborn(libgit2_d.types.git_repository* repo); 428 429 /** 430 * Check if a repository is empty 431 * 432 * An empty repository has just been initialized and contains no references 433 * apart from HEAD, which must be pointing to the unborn master branch. 434 * 435 * @param repo Repo to test 436 * @return 1 if the repository is empty, 0 if it isn't, error code 437 * if the repository is corrupted 438 */ 439 //GIT_EXTERN 440 int git_repository_is_empty(libgit2_d.types.git_repository* repo); 441 442 /** 443 * List of items which belong to the git repository layout 444 */ 445 enum git_repository_item_t 446 { 447 GIT_REPOSITORY_ITEM_GITDIR, 448 GIT_REPOSITORY_ITEM_WORKDIR, 449 GIT_REPOSITORY_ITEM_COMMONDIR, 450 GIT_REPOSITORY_ITEM_INDEX, 451 GIT_REPOSITORY_ITEM_OBJECTS, 452 GIT_REPOSITORY_ITEM_REFS, 453 GIT_REPOSITORY_ITEM_PACKED_REFS, 454 GIT_REPOSITORY_ITEM_REMOTES, 455 GIT_REPOSITORY_ITEM_CONFIG, 456 GIT_REPOSITORY_ITEM_INFO, 457 GIT_REPOSITORY_ITEM_HOOKS, 458 GIT_REPOSITORY_ITEM_LOGS, 459 GIT_REPOSITORY_ITEM_MODULES, 460 GIT_REPOSITORY_ITEM_WORKTREES, 461 GIT_REPOSITORY_ITEM__LAST, 462 } 463 464 /** 465 * Get the location of a specific repository file or directory 466 * 467 * This function will retrieve the path of a specific repository 468 * item. It will thereby honor things like the repository's 469 * common directory, gitdir, etc. In case a file path cannot 470 * exist for a given item (e.g. the working directory of a bare 471 * repository), git_error_code.GIT_ENOTFOUND is returned. 472 * 473 * @param out_ Buffer to store the path at 474 * @param repo Repository to get path for 475 * @param item The repository item for which to retrieve the path 476 * @return 0, git_error_code.GIT_ENOTFOUND if the path cannot exist or an error code 477 */ 478 //GIT_EXTERN 479 int git_repository_item_path(libgit2_d.buffer.git_buf* out_, const (libgit2_d.types.git_repository)* repo, .git_repository_item_t item); 480 481 /** 482 * Get the path of this repository 483 * 484 * This is the path of the `.git` folder for normal repositories, 485 * or of the repository itself for bare repositories. 486 * 487 * @param repo A repository object 488 * @return the path to the repository 489 */ 490 //GIT_EXTERN 491 const (char)* git_repository_path(const (libgit2_d.types.git_repository)* repo); 492 493 /** 494 * Get the path of the working directory for this repository 495 * 496 * If the repository is bare, this function will always return 497 * null. 498 * 499 * @param repo A repository object 500 * @return the path to the working dir, if it exists 501 */ 502 //GIT_EXTERN 503 const (char)* git_repository_workdir(const (libgit2_d.types.git_repository)* repo); 504 505 /** 506 * Get the path of the shared common directory for this repository 507 * 508 * If the repository is bare is not a worktree, the git directory 509 * path is returned. 510 * 511 * @param repo A repository object 512 * @return the path to the common dir 513 */ 514 //GIT_EXTERN 515 const (char)* git_repository_commondir(const (libgit2_d.types.git_repository)* repo); 516 517 /** 518 * Set the path to the working directory for this repository 519 * 520 * The working directory doesn't need to be the same one 521 * that contains the `.git` folder for this repository. 522 * 523 * If this repository is bare, setting its working directory 524 * will turn it into a normal repository, capable of performing 525 * all the common workdir operations (checkout, status, index 526 * manipulation, etc). 527 * 528 * @param repo A repository object 529 * @param workdir The path to a working directory 530 * @param update_gitlink Create/update gitlink in workdir and set config 531 * "core.worktree" (if workdir is not the parent of the .git directory) 532 * @return 0, or an error code 533 */ 534 //GIT_EXTERN 535 int git_repository_set_workdir(libgit2_d.types.git_repository* repo, const (char)* workdir, int update_gitlink); 536 537 /** 538 * Check if a repository is bare 539 * 540 * @param repo Repo to test 541 * @return 1 if the repository is bare, 0 otherwise. 542 */ 543 //GIT_EXTERN 544 int git_repository_is_bare(const (libgit2_d.types.git_repository)* repo); 545 546 /** 547 * Check if a repository is a linked work tree 548 * 549 * @param repo Repo to test 550 * @return 1 if the repository is a linked work tree, 0 otherwise. 551 */ 552 //GIT_EXTERN 553 int git_repository_is_worktree(const (libgit2_d.types.git_repository)* repo); 554 555 /** 556 * Get the configuration file for this repository. 557 * 558 * If a configuration file has not been set, the default 559 * config set for the repository will be returned, including 560 * global and system configurations (if they are available). 561 * 562 * The configuration file must be freed once it's no longer 563 * being used by the user. 564 * 565 * @param out_ Pointer to store the loaded configuration 566 * @param repo A repository object 567 * @return 0, or an error code 568 */ 569 //GIT_EXTERN 570 int git_repository_config(libgit2_d.types.git_config** out_, libgit2_d.types.git_repository* repo); 571 572 /** 573 * Get a snapshot of the repository's configuration 574 * 575 * Convenience function to take a snapshot from the repository's 576 * configuration. The contents of this snapshot will not change, 577 * even if the underlying config files are modified. 578 * 579 * The configuration file must be freed once it's no longer 580 * being used by the user. 581 * 582 * @param out_ Pointer to store the loaded configuration 583 * @param repo the repository 584 * @return 0, or an error code 585 */ 586 //GIT_EXTERN 587 int git_repository_config_snapshot(libgit2_d.types.git_config** out_, libgit2_d.types.git_repository* repo); 588 589 /** 590 * Get the Object Database for this repository. 591 * 592 * If a custom ODB has not been set, the default 593 * database for the repository will be returned (the one 594 * located in `.git/objects`). 595 * 596 * The ODB must be freed once it's no longer being used by 597 * the user. 598 * 599 * @param out_ Pointer to store the loaded ODB 600 * @param repo A repository object 601 * @return 0, or an error code 602 */ 603 //GIT_EXTERN 604 int git_repository_odb(libgit2_d.types.git_odb** out_, libgit2_d.types.git_repository* repo); 605 606 /** 607 * Get the Reference Database Backend for this repository. 608 * 609 * If a custom refsdb has not been set, the default database for 610 * the repository will be returned (the one that manipulates loose 611 * and packed references in the `.git` directory). 612 * 613 * The refdb must be freed once it's no longer being used by 614 * the user. 615 * 616 * @param out_ Pointer to store the loaded refdb 617 * @param repo A repository object 618 * @return 0, or an error code 619 */ 620 //GIT_EXTERN 621 int git_repository_refdb(libgit2_d.types.git_refdb** out_, libgit2_d.types.git_repository* repo); 622 623 /** 624 * Get the Index file for this repository. 625 * 626 * If a custom index has not been set, the default 627 * index for the repository will be returned (the one 628 * located in `.git/index`). 629 * 630 * The index must be freed once it's no longer being used by 631 * the user. 632 * 633 * @param out_ Pointer to store the loaded index 634 * @param repo A repository object 635 * @return 0, or an error code 636 */ 637 //GIT_EXTERN 638 int git_repository_index(libgit2_d.types.git_index** out_, libgit2_d.types.git_repository* repo); 639 640 /** 641 * Retrieve git's prepared message 642 * 643 * Operations such as git revert/cherry-pick/merge with the -n option 644 * stop just short of creating a commit with the changes and save 645 * their prepared message in .git/MERGE_MSG so the next git-commit 646 * execution can present it to the user for them to amend if they 647 * wish. 648 * 649 * Use this function to get the contents of this file. Don't forget to 650 * remove the file after you create the commit. 651 * 652 * @param out_ git_buf to write data into 653 * @param repo Repository to read prepared message from 654 * @return 0, git_error_code.GIT_ENOTFOUND if no message exists or an error code 655 */ 656 //GIT_EXTERN 657 int git_repository_message(libgit2_d.buffer.git_buf* out_, libgit2_d.types.git_repository* repo); 658 659 /** 660 * Remove git's prepared message. 661 * 662 * Remove the message that `git_repository_message` retrieves. 663 */ 664 //GIT_EXTERN 665 int git_repository_message_remove(libgit2_d.types.git_repository* repo); 666 667 /** 668 * Remove all the metadata associated with an ongoing command like merge, 669 * revert, cherry-pick, etc. For example: MERGE_HEAD, MERGE_MSG, etc. 670 * 671 * @param repo A repository object 672 * @return 0 on success, or error 673 */ 674 //GIT_EXTERN 675 int git_repository_state_cleanup(libgit2_d.types.git_repository* repo); 676 677 /** 678 * Callback used to iterate over each FETCH_HEAD entry 679 * 680 * @see git_repository_fetchhead_foreach 681 * 682 * @param ref_name The reference name 683 * @param remote_url The remote URL 684 * @param oid The reference target OID 685 * @param is_merge Was the reference the result of a merge 686 * @param payload Payload passed to git_repository_fetchhead_foreach 687 * @return non-zero to terminate the iteration 688 */ 689 alias git_repository_fetchhead_foreach_cb = int function(const (char)* ref_name, const (char)* remote_url, const (libgit2_d.oid.git_oid)* oid, uint is_merge, void* payload); 690 691 /** 692 * Invoke 'callback' for each entry in the given FETCH_HEAD file. 693 * 694 * Return a non-zero value from the callback to stop the loop. 695 * 696 * @param repo A repository object 697 * @param callback Callback function 698 * @param payload Pointer to callback data (optional) 699 * @return 0 on success, non-zero callback return value, git_error_code.GIT_ENOTFOUND if 700 * there is no FETCH_HEAD file, or other error code. 701 */ 702 //GIT_EXTERN 703 int git_repository_fetchhead_foreach(libgit2_d.types.git_repository* repo, .git_repository_fetchhead_foreach_cb callback, void* payload); 704 705 /** 706 * Callback used to iterate over each MERGE_HEAD entry 707 * 708 * @see git_repository_mergehead_foreach 709 * 710 * @param oid The merge OID 711 * @param payload Payload passed to git_repository_mergehead_foreach 712 * @return non-zero to terminate the iteration 713 */ 714 alias git_repository_mergehead_foreach_cb = int function(const (libgit2_d.oid.git_oid)* oid, void* payload); 715 716 /** 717 * If a merge is in progress, invoke 'callback' for each commit ID in the 718 * MERGE_HEAD file. 719 * 720 * Return a non-zero value from the callback to stop the loop. 721 * 722 * @param repo A repository object 723 * @param callback Callback function 724 * @param payload Pointer to callback data (optional) 725 * @return 0 on success, non-zero callback return value, git_error_code.GIT_ENOTFOUND if 726 * there is no MERGE_HEAD file, or other error code. 727 */ 728 //GIT_EXTERN 729 int git_repository_mergehead_foreach(libgit2_d.types.git_repository* repo, .git_repository_mergehead_foreach_cb callback, void* payload); 730 731 /** 732 * Calculate hash of file using repository filtering rules. 733 * 734 * If you simply want to calculate the hash of a file on disk with no filters, 735 * you can just use the `git_odb_hashfile()` API. However, if you want to 736 * hash a file in the repository and you want to apply filtering rules (e.g. 737 * crlf filters) before generating the SHA, then use this function. 738 * 739 * Note: if the repository has `core.safecrlf` set to fail and the 740 * filtering triggers that failure, then this function will return an 741 * error and not calculate the hash of the file. 742 * 743 * @param out_ Output value of calculated SHA 744 * @param repo Repository pointer 745 * @param path Path to file on disk whose contents should be hashed. If the 746 * repository is not null, this can be a relative path. 747 * @param type The object type to hash as (e.g. git_object_t.GIT_OBJECT_BLOB) 748 * @param as_path The path to use to look up filtering rules. If this is 749 * null, then the `path` parameter will be used instead. If 750 * this is passed as the empty string, then no filters will be 751 * applied when calculating the hash. 752 * @return 0 on success, or an error code 753 */ 754 //GIT_EXTERN 755 int git_repository_hashfile(libgit2_d.oid.git_oid* out_, libgit2_d.types.git_repository* repo, const (char)* path, libgit2_d.types.git_object_t type, const (char)* as_path); 756 757 /** 758 * Make the repository HEAD point to the specified reference. 759 * 760 * If the provided reference points to a Tree or a Blob, the HEAD is 761 * unaltered and -1 is returned. 762 * 763 * If the provided reference points to a branch, the HEAD will point 764 * to that branch, staying attached, or become attached if it isn't yet. 765 * If the branch doesn't exist yet, no error will be return. The HEAD 766 * will then be attached to an unborn branch. 767 * 768 * Otherwise, the HEAD will be detached and will directly point to 769 * the Commit. 770 * 771 * @param repo Repository pointer 772 * @param refname Canonical name of the reference the HEAD should point at 773 * @return 0 on success, or an error code 774 */ 775 //GIT_EXTERN 776 int git_repository_set_head(libgit2_d.types.git_repository* repo, const (char)* refname); 777 778 /** 779 * Make the repository HEAD directly point to the Commit. 780 * 781 * If the provided committish cannot be found in the repository, the HEAD 782 * is unaltered and git_error_code.GIT_ENOTFOUND is returned. 783 * 784 * If the provided commitish cannot be peeled into a commit, the HEAD 785 * is unaltered and -1 is returned. 786 * 787 * Otherwise, the HEAD will eventually be detached and will directly point to 788 * the peeled Commit. 789 * 790 * @param repo Repository pointer 791 * @param commitish Object id of the Commit the HEAD should point to 792 * @return 0 on success, or an error code 793 */ 794 //GIT_EXTERN 795 int git_repository_set_head_detached(libgit2_d.types.git_repository* repo, const (libgit2_d.oid.git_oid)* commitish); 796 797 /** 798 * Make the repository HEAD directly point to the Commit. 799 * 800 * This behaves like `git_repository_set_head_detached()` but takes an 801 * annotated commit, which lets you specify which extended sha syntax 802 * string was specified by a user, allowing for more exact reflog 803 * messages. 804 * 805 * See the documentation for `git_repository_set_head_detached()`. 806 * 807 * @see git_repository_set_head_detached 808 */ 809 //GIT_EXTERN 810 int git_repository_set_head_detached_from_annotated(libgit2_d.types.git_repository* repo, const (libgit2_d.types.git_annotated_commit)* commitish); 811 812 /** 813 * Detach the HEAD. 814 * 815 * If the HEAD is already detached and points to a Commit, 0 is returned. 816 * 817 * If the HEAD is already detached and points to a Tag, the HEAD is 818 * updated into making it point to the peeled Commit, and 0 is returned. 819 * 820 * If the HEAD is already detached and points to a non commitish, the HEAD is 821 * unaltered, and -1 is returned. 822 * 823 * Otherwise, the HEAD will be detached and point to the peeled Commit. 824 * 825 * @param repo Repository pointer 826 * @return 0 on success, git_error_code.GIT_EUNBORNBRANCH when HEAD points to a non existing 827 * branch or an error code 828 */ 829 //GIT_EXTERN 830 int git_repository_detach_head(libgit2_d.types.git_repository* repo); 831 832 /** 833 * Repository state 834 * 835 * These values represent possible states for the repository to be in, 836 * based on the current operation which is ongoing. 837 */ 838 enum git_repository_state_t 839 { 840 GIT_REPOSITORY_STATE_NONE, 841 GIT_REPOSITORY_STATE_MERGE, 842 GIT_REPOSITORY_STATE_REVERT, 843 GIT_REPOSITORY_STATE_REVERT_SEQUENCE, 844 GIT_REPOSITORY_STATE_CHERRYPICK, 845 GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE, 846 GIT_REPOSITORY_STATE_BISECT, 847 GIT_REPOSITORY_STATE_REBASE, 848 GIT_REPOSITORY_STATE_REBASE_INTERACTIVE, 849 GIT_REPOSITORY_STATE_REBASE_MERGE, 850 GIT_REPOSITORY_STATE_APPLY_MAILBOX, 851 GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE, 852 } 853 854 /** 855 * Determines the status of a git repository - ie, whether an operation 856 * (merge, cherry-pick, etc) is in progress. 857 * 858 * @param repo Repository pointer 859 * @return The state of the repository 860 */ 861 //GIT_EXTERN 862 int git_repository_state(libgit2_d.types.git_repository* repo); 863 864 /** 865 * Sets the active namespace for this Git Repository 866 * 867 * This namespace affects all reference operations for the repo. 868 * See `man gitnamespaces` 869 * 870 * @param repo The repo 871 * @param nmspace The namespace. This should not include the refs 872 * folder, e.g. to namespace all references under `refs/namespaces/foo/`, 873 * use `foo` as the namespace. 874 * @return 0 on success, -1 on error 875 */ 876 //GIT_EXTERN 877 int git_repository_set_namespace(libgit2_d.types.git_repository* repo, const (char)* nmspace); 878 879 /** 880 * Get the currently active namespace for this repository 881 * 882 * @param repo The repo 883 * @return the active namespace, or null if there isn't one 884 */ 885 //GIT_EXTERN 886 const (char)* git_repository_get_namespace(libgit2_d.types.git_repository* repo); 887 888 /** 889 * Determine if the repository was a shallow clone 890 * 891 * @param repo The repository 892 * @return 1 if shallow, zero if not 893 */ 894 //GIT_EXTERN 895 int git_repository_is_shallow(libgit2_d.types.git_repository* repo); 896 897 /** 898 * Retrieve the configured identity to use for reflogs 899 * 900 * The memory is owned by the repository and must not be freed by the 901 * user. 902 * 903 * @param name where to store the pointer to the name 904 * @param email where to store the pointer to the email 905 * @param repo the repository 906 */ 907 //GIT_EXTERN 908 int git_repository_ident(const (char)** name, const (char)** email, const (libgit2_d.types.git_repository)* repo); 909 910 /** 911 * Set the identity to be used for writing reflogs 912 * 913 * If both are set, this name and email will be used to write to the 914 * reflog. Pass null to unset. When unset, the identity will be taken 915 * from the repository's configuration. 916 * 917 * @param repo the repository to configure 918 * @param name the name to use for the reflog entries 919 * @param email the email to use for the reflog entries 920 */ 921 //GIT_EXTERN 922 int git_repository_set_ident(libgit2_d.types.git_repository* repo, const (char)* name, const (char)* email); 923 924 /** @} */