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