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