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