]> git.proxmox.com Git - libgit2.git/blame - include/git2/repository.h
Merge pull request #1668 from csware/WC_ERR_INVALID_CHARS
[libgit2.git] / include / git2 / repository.h
CommitLineData
f5918330 1/*
359fc2d2 2 * Copyright (C) the libgit2 contributors. All rights reserved.
f5918330 3 *
bb742ede
VM
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.
f5918330 6 */
3315782c
VM
7#ifndef INCLUDE_git_repository_h__
8#define INCLUDE_git_repository_h__
9
10#include "common.h"
d12299fe
VM
11#include "types.h"
12#include "oid.h"
3315782c
VM
13
14/**
f5918330 15 * @file git2/repository.h
d12299fe
VM
16 * @brief Git repository management routines
17 * @defgroup git_repository Git repository management routines
3315782c
VM
18 * @ingroup Git
19 * @{
20 */
21GIT_BEGIN_DECL
22
23/**
6fd195d7 24 * Open a git repository.
3315782c 25 *
9462c471
VM
26 * The 'path' argument must point to either a git repository
27 * folder, or an existing work dir.
3315782c 28 *
9462c471
VM
29 * The method will automatically detect if 'path' is a normal
30 * or bare repository or fail is 'path' is neither.
6fd195d7 31 *
c9fc4a6f 32 * @param out pointer to the repo which will be opened
6fd195d7 33 * @param path the path to the repository
e172cf08 34 * @return 0 or an error code
3315782c 35 */
c9fc4a6f 36GIT_EXTERN(int) git_repository_open(git_repository **out, const char *path);
3315782c 37
6782245e
CMN
38/**
39 * Create a "fake" repository to wrap an object database
40 *
41 * Create a repository object to wrap an object database to be used
42 * with the API when all you have is an object database. This doesn't
43 * have any paths associated with it, so use with care.
44 *
c9fc4a6f 45 * @param out pointer to the repo
6782245e
CMN
46 * @param odb the object database to wrap
47 * @return 0 or an error code
48 */
c9fc4a6f 49GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb);
6782245e 50
fd0574e5 51/**
9462c471
VM
52 * Look for a git repository and copy its path in the given buffer.
53 * The lookup start from base_path and walk across parent directories
54 * if nothing has been found. The lookup ends when the first repository
55 * is found, or when reaching a directory referenced in ceiling_dirs
56 * or when the filesystem changes (in case across_fs is true).
fd0574e5 57 *
9462c471
VM
58 * The method will automatically detect if the repository is bare
59 * (if there is a repository).
fd0574e5 60 *
c9fc4a6f 61 * @param path_out The user allocated buffer which will
9462c471 62 * contain the found path.
fd0574e5 63 *
c9fc4a6f 64 * @param path_size repository_path size
fd0574e5
RG
65 *
66 * @param start_path The base path where the lookup starts.
67 *
9462c471
VM
68 * @param across_fs If true, then the lookup will not stop when a
69 * filesystem device change is detected while exploring parent directories.
fd0574e5 70 *
9462c471
VM
71 * @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR separated list of
72 * absolute symbolic link free paths. The lookup will stop when any
73 * of this paths is reached. Note that the lookup always performs on
74 * start_path no matter start_path appears in ceiling_dirs ceiling_dirs
75 * might be NULL (which is equivalent to an empty string)
fd0574e5 76 *
e172cf08 77 * @return 0 or an error code
fd0574e5 78 */
9462c471 79GIT_EXTERN(int) git_repository_discover(
c9fc4a6f
BS
80 char *path_out,
81 size_t path_size,
9462c471
VM
82 const char *start_path,
83 int across_fs,
84 const char *ceiling_dirs);
6fd195d7 85
662880ca
RB
86/**
87 * Option flags for `git_repository_open_ext`.
88 *
89 * * GIT_REPOSITORY_OPEN_NO_SEARCH - Only open the repository if it can be
90 * immediately found in the start_path. Do not walk up from the
91 * start_path looking at parent directories.
ca1b6e54
RB
92 * * GIT_REPOSITORY_OPEN_CROSS_FS - Unless this flag is set, open will not
93 * continue searching across filesystem boundaries (i.e. when `st_dev`
94 * changes from the `stat` system call). (E.g. Searching in a user's home
95 * directory "/home/user/source/" will not return "/.git/" as the found
96 * repo if "/" is a different filesystem than "/home".)
662880ca 97 */
c9fc4a6f 98typedef enum {
7784bcbb
RB
99 GIT_REPOSITORY_OPEN_NO_SEARCH = (1 << 0),
100 GIT_REPOSITORY_OPEN_CROSS_FS = (1 << 1),
f4a62c30 101} git_repository_open_flag_t;
7784bcbb
RB
102
103/**
104 * Find and open a repository with extended controls.
662880ca 105 *
c9fc4a6f 106 * @param out Pointer to the repo which will be opened. This can
662880ca
RB
107 * actually be NULL if you only want to use the error code to
108 * see if a repo at this path could be opened.
c9fc4a6f 109 * @param path Path to open as git repository. If the flags
662880ca
RB
110 * permit "searching", then this can be a path to a subdirectory
111 * inside the working directory of the repository.
112 * @param flags A combination of the GIT_REPOSITORY_OPEN flags above.
113 * @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR delimited list of path
114 * prefixes at which the search for a containing repository should
115 * terminate.
116 * @return 0 on success, GIT_ENOTFOUND if no repository could be found,
117 * or -1 if there was a repository but open failed for some reason
118 * (such as repo corruption or system errors).
7784bcbb
RB
119 */
120GIT_EXTERN(int) git_repository_open_ext(
c9fc4a6f
BS
121 git_repository **out,
122 const char *path,
123 unsigned int flags,
7784bcbb
RB
124 const char *ceiling_dirs);
125
a442ed68
VM
126/**
127 * Open a bare repository on the serverside.
128 *
129 * This is a fast open for bare repositories that will come in handy
130 * if you're e.g. hosting git repositories and need to access them
131 * efficiently
132 *
133 * @param out Pointer to the repo which will be opened.
134 * @param bare_path Direct path to the bare repository
135 * @return 0 on success, or an error code
136 */
437d3666 137GIT_EXTERN(int) git_repository_open_bare(git_repository **out, const char *bare_path);
a442ed68 138
3315782c
VM
139/**
140 * Free a previously allocated repository
6b2a1941 141 *
f0d08b7c
VM
142 * Note that after a repository is free'd, all the objects it has spawned
143 * will still exist until they are manually closed by the user
45e79e37 144 * with `git_object_free`, but accessing any of the attributes of
f0d08b7c
VM
145 * an object without a backing repository will result in undefined
146 * behavior
147 *
3315782c
VM
148 * @param repo repository handle to close. If NULL nothing occurs.
149 */
150GIT_EXTERN(void) git_repository_free(git_repository *repo);
151
e1f8cad0 152/**
40c44d2f 153 * Creates a new Git repository in the given folder.
e1f8cad0 154 *
40c44d2f
VM
155 * TODO:
156 * - Reinit the repository
e1f8cad0 157 *
c9fc4a6f 158 * @param out pointer to the repo which will be created or reinitialized
e1f8cad0 159 * @param path the path to the repository
662880ca
RB
160 * @param is_bare if true, a Git repository without a working directory is
161 * created at the pointed path. If false, provided path will be
162 * considered as the working directory into which the .git directory
163 * will be created.
40c44d2f 164 *
e172cf08 165 * @return 0 or an error code
e1f8cad0 166 */
662880ca 167GIT_EXTERN(int) git_repository_init(
c9fc4a6f 168 git_repository **out,
662880ca
RB
169 const char *path,
170 unsigned is_bare);
171
172/**
173 * Option flags for `git_repository_init_ext`.
174 *
175 * These flags configure extra behaviors to `git_repository_init_ext`.
176 * In every case, the default behavior is the zero value (i.e. flag is
177 * not set). Just OR the flag values together for the `flags` parameter
178 * when initializing a new repo. Details of individual values are:
179 *
180 * * BARE - Create a bare repository with no working directory.
181 * * NO_REINIT - Return an EEXISTS error if the repo_path appears to
182 * already be an git repository.
183 * * NO_DOTGIT_DIR - Normally a "/.git/" will be appended to the repo
184 * path for non-bare repos (if it is not already there), but
185 * passing this flag prevents that behavior.
186 * * MKDIR - Make the repo_path (and workdir_path) as needed. Init is
187 * always willing to create the ".git" directory even without this
188 * flag. This flag tells init to create the trailing component of
189 * the repo and workdir paths as needed.
190 * * MKPATH - Recursively make all components of the repo and workdir
191 * paths as necessary.
192 * * EXTERNAL_TEMPLATE - libgit2 normally uses internal templates to
193 * initialize a new repo. This flags enables external templates,
194 * looking the "template_path" from the options if set, or the
195 * `init.templatedir` global config if not, or falling back on
196 * "/usr/share/git-core/templates" if it exists.
662880ca 197 */
f4a62c30 198typedef enum {
662880ca
RB
199 GIT_REPOSITORY_INIT_BARE = (1u << 0),
200 GIT_REPOSITORY_INIT_NO_REINIT = (1u << 1),
201 GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = (1u << 2),
202 GIT_REPOSITORY_INIT_MKDIR = (1u << 3),
203 GIT_REPOSITORY_INIT_MKPATH = (1u << 4),
204 GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = (1u << 5),
f4a62c30 205} git_repository_init_flag_t;
ca1b6e54
RB
206
207/**
208 * Mode options for `git_repository_init_ext`.
209 *
210 * Set the mode field of the `git_repository_init_options` structure
211 * either to the custom mode that you would like, or to one of the
212 * following modes:
213 *
214 * * SHARED_UMASK - Use permissions configured by umask - the default.
215 * * SHARED_GROUP - Use "--shared=group" behavior, chmod'ing the new repo
216 * to be group writable and "g+sx" for sticky group assignment.
217 * * SHARED_ALL - Use "--shared=all" behavior, adding world readability.
218 * * Anything else - Set to custom value.
219 */
f4a62c30 220typedef enum {
ca1b6e54
RB
221 GIT_REPOSITORY_INIT_SHARED_UMASK = 0,
222 GIT_REPOSITORY_INIT_SHARED_GROUP = 0002775,
223 GIT_REPOSITORY_INIT_SHARED_ALL = 0002777,
f4a62c30 224} git_repository_init_mode_t;
662880ca
RB
225
226/**
227 * Extended options structure for `git_repository_init_ext`.
228 *
229 * This contains extra options for `git_repository_init_ext` that enable
230 * additional initialization features. The fields are:
231 *
232 * * flags - Combination of GIT_REPOSITORY_INIT flags above.
ca1b6e54
RB
233 * * mode - Set to one of the standard GIT_REPOSITORY_INIT_SHARED_...
234 * constants above, or to a custom value that you would like.
662880ca 235 * * workdir_path - The path to the working dir or NULL for default (i.e.
ca1b6e54
RB
236 * repo_path parent on non-bare repos). IF THIS IS RELATIVE PATH,
237 * IT WILL BE EVALUATED RELATIVE TO THE REPO_PATH. If this is not
238 * the "natural" working directory, a .git gitlink file will be
239 * created here linking to the repo_path.
662880ca
RB
240 * * description - If set, this will be used to initialize the "description"
241 * file in the repository, instead of using the template content.
242 * * template_path - When GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE is set,
243 * this contains the path to use for the template directory. If
244 * this is NULL, the config or default directory options will be
245 * used instead.
246 * * initial_head - The name of the head to point HEAD at. If NULL, then
247 * this will be treated as "master" and the HEAD ref will be set
248 * to "refs/heads/master". If this begins with "refs/" it will be
249 * used verbatim; otherwise "refs/heads/" will be prefixed.
250 * * origin_url - If this is non-NULL, then after the rest of the
251 * repository initialization is completed, an "origin" remote
252 * will be added pointing to this URL.
253 */
ca94e031 254typedef struct {
bde336ea 255 unsigned int version;
662880ca
RB
256 uint32_t flags;
257 uint32_t mode;
258 const char *workdir_path;
259 const char *description;
260 const char *template_path;
261 const char *initial_head;
262 const char *origin_url;
263} git_repository_init_options;
264
bde336ea 265#define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1
fac43c54 266#define GIT_REPOSITORY_INIT_OPTIONS_INIT {GIT_REPOSITORY_INIT_OPTIONS_VERSION}
bde336ea 267
662880ca
RB
268/**
269 * Create a new Git repository in the given folder with extended controls.
270 *
271 * This will initialize a new git repository (creating the repo_path
272 * if requested by flags) and working directory as needed. It will
273 * auto-detect the case sensitivity of the file system and if the
274 * file system supports file mode bits correctly.
275 *
c9fc4a6f 276 * @param out Pointer to the repo which will be created or reinitialized.
662880ca
RB
277 * @param repo_path The path to the repository.
278 * @param opts Pointer to git_repository_init_options struct.
279 * @return 0 or an error code on failure.
280 */
281GIT_EXTERN(int) git_repository_init_ext(
c9fc4a6f 282 git_repository **out,
662880ca
RB
283 const char *repo_path,
284 git_repository_init_options *opts);
4b8e27c8 285
3601c4bf 286/**
287 * Retrieve and resolve the reference pointed at by HEAD.
288 *
ca94e031
RB
289 * The returned `git_reference` will be owned by caller and
290 * `git_reference_free()` must be called when done with it to release the
291 * allocated memory and prevent a leak.
292 *
c9fc4a6f 293 * @param out pointer to the reference which will be retrieved
3601c4bf 294 * @param repo a repository object
295 *
8b05bea8 296 * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
b1a3a70e 297 * branch, GIT_ENOTFOUND when HEAD is missing; an error code otherwise
3601c4bf 298 */
c9fc4a6f 299GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo);
3601c4bf 300
35502d2e
CMN
301/**
302 * Check if a repository's HEAD is detached
303 *
304 * A repository's HEAD is detached when it points directly to a commit
305 * instead of a branch.
306 *
307 * @param repo Repo to test
d73c94b2 308 * @return 1 if HEAD is detached, 0 if it's not; error code if there
35502d2e
CMN
309 * was an error.
310 */
408d733b 311GIT_EXTERN(int) git_repository_head_detached(git_repository *repo);
35502d2e
CMN
312
313/**
314 * Check if the current branch is an orphan
315 *
316 * An orphan branch is one named from HEAD but which doesn't exist in
317 * the refs namespace, because it doesn't have any commit to point to.
318 *
319 * @param repo Repo to test
320 * @return 1 if the current branch is an orphan, 0 if it's not; error
d73c94b2 321 * code if there was an error
35502d2e 322 */
408d733b 323GIT_EXTERN(int) git_repository_head_orphan(git_repository *repo);
35502d2e 324
41233c40
VM
325/**
326 * Check if a repository is empty
327 *
328 * An empty repository has just been initialized and contains
6091457e 329 * no references.
41233c40
VM
330 *
331 * @param repo Repo to test
332 * @return 1 if the repository is empty, 0 if it isn't, error code
333 * if the repository is corrupted
334 */
335GIT_EXTERN(int) git_repository_is_empty(git_repository *repo);
336
6632c155
VM
337/**
338 * Get the path of this repository
339 *
340 * This is the path of the `.git` folder for normal repositories,
341 * or of the repository itself for bare repositories.
342 *
343 * @param repo A repository object
344 * @return the path to the repository
345 */
9462c471 346GIT_EXTERN(const char *) git_repository_path(git_repository *repo);
6632c155
VM
347
348/**
349 * Get the path of the working directory for this repository
350 *
351 * If the repository is bare, this function will always return
352 * NULL.
353 *
354 * @param repo A repository object
355 * @return the path to the working dir, if it exists
356 */
9462c471 357GIT_EXTERN(const char *) git_repository_workdir(git_repository *repo);
6632c155
VM
358
359/**
360 * Set the path to the working directory for this repository
361 *
362 * The working directory doesn't need to be the same one
363 * that contains the `.git` folder for this repository.
364 *
365 * If this repository is bare, setting its working directory
366 * will turn it into a normal repository, capable of performing
367 * all the common workdir operations (checkout, status, index
368 * manipulation, etc).
369 *
370 * @param repo A repository object
371 * @param workdir The path to a working directory
991a56c7
RB
372 * @param update_gitlink Create/update gitlink in workdir and set config
373 * "core.worktree" (if workdir is not the parent of the .git directory)
e172cf08 374 * @return 0, or an error code
6632c155 375 */
991a56c7
RB
376GIT_EXTERN(int) git_repository_set_workdir(
377 git_repository *repo, const char *workdir, int update_gitlink);
4a34b3a9 378
fa9bcd81 379/**
380 * Check if a repository is bare
381 *
382 * @param repo Repo to test
28ba94ce 383 * @return 1 if the repository is bare, 0 otherwise.
fa9bcd81 384 */
385GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
386
6632c155
VM
387/**
388 * Get the configuration file for this repository.
389 *
390 * If a configuration file has not been set, the default
391 * config set for the repository will be returned, including
392 * global and system configurations (if they are available).
393 *
394 * The configuration file must be freed once it's no longer
395 * being used by the user.
396 *
397 * @param out Pointer to store the loaded config file
398 * @param repo A repository object
e172cf08 399 * @return 0, or an error code
6632c155 400 */
9462c471 401GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo);
6632c155 402
6632c155
VM
403/**
404 * Get the Object Database for this repository.
405 *
406 * If a custom ODB has not been set, the default
407 * database for the repository will be returned (the one
408 * located in `.git/objects`).
409 *
410 * The ODB must be freed once it's no longer being used by
411 * the user.
412 *
413 * @param out Pointer to store the loaded ODB
414 * @param repo A repository object
e172cf08 415 * @return 0, or an error code
6632c155 416 */
9462c471 417GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo);
6632c155 418
d00d5464
ET
419/**
420 * Get the Reference Database Backend for this repository.
421 *
422 * If a custom refsdb has not been set, the default database for
423 * the repository will be returned (the one that manipulates loose
424 * and packed references in the `.git` directory).
425 *
426 * The refdb must be freed once it's no longer being used by
427 * the user.
428 *
429 * @param out Pointer to store the loaded refdb
430 * @param repo A repository object
431 * @return 0, or an error code
432 */
433GIT_EXTERN(int) git_repository_refdb(git_refdb **out, git_repository *repo);
434
6632c155
VM
435/**
436 * Get the Index file for this repository.
437 *
438 * If a custom index has not been set, the default
439 * index for the repository will be returned (the one
440 * located in `.git/index`).
441 *
442 * The index must be freed once it's no longer being used by
443 * the user.
444 *
445 * @param out Pointer to store the loaded index
446 * @param repo A repository object
e172cf08 447 * @return 0, or an error code
6632c155 448 */
9462c471 449GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo);
6632c155 450
074841ec 451/**
cc548c7b 452 * Retrieve git's prepared message
074841ec
CMN
453 *
454 * Operations such as git revert/cherry-pick/merge with the -n option
455 * stop just short of creating a commit with the changes and save
456 * their prepared message in .git/MERGE_MSG so the next git-commit
457 * execution can present it to the user for them to amend if they
458 * wish.
459 *
460 * Use this function to get the contents of this file. Don't forget to
461 * remove the file after you create the commit.
e9ca852e 462 *
3d1c9f61
RB
463 * If the repository message exists and there are no errors reading it, this
464 * returns the bytes needed to store the message in memory (i.e. message
465 * file size plus one terminating NUL byte). That value is returned even if
466 * `out` is NULL or `len` is shorter than the necessary size.
467 *
468 * The `out` buffer will *always* be NUL terminated, even if truncation
469 * occurs.
470 *
c9fc4a6f 471 * @param out Buffer to write data into or NULL to just read required size
3d1c9f61 472 * @param len Length of `out` buffer in bytes
e9ca852e 473 * @param repo Repository to read prepared message from
3d1c9f61
RB
474 * @return GIT_ENOUTFOUND if no message exists, other value < 0 for other
475 * errors, or total bytes in message (may be > `len`) on success
074841ec 476 */
c9fc4a6f 477GIT_EXTERN(int) git_repository_message(char *out, size_t len, git_repository *repo);
074841ec
CMN
478
479/**
480 * Remove git's prepared message.
481 *
482 * Remove the message that `git_repository_message` retrieves.
483 */
484GIT_EXTERN(int) git_repository_message_remove(git_repository *repo);
485
ad2bc32f
ET
486/**
487 * Remove all the metadata associated with an ongoing git merge, including
488 * MERGE_HEAD, MERGE_MSG, etc.
489 *
490 * @param repo A repository object
491 * @return 0 on success, or error
492 */
493GIT_EXTERN(int) git_repository_merge_cleanup(git_repository *repo);
494
7fcec834
ET
495typedef int (*git_repository_fetchhead_foreach_cb)(const char *ref_name,
496 const char *remote_url,
497 const git_oid *oid,
498 unsigned int is_merge,
499 void *payload);
500
501/**
502 * Call callback 'callback' for each entry in the given FETCH_HEAD file.
503 *
504 * @param repo A repository object
505 * @param callback Callback function
506 * @param payload Pointer to callback data (optional)
507 * @return 0 on success, GIT_ENOTFOUND, GIT_EUSER or error
508 */
509GIT_EXTERN(int) git_repository_fetchhead_foreach(git_repository *repo,
510 git_repository_fetchhead_foreach_cb callback,
511 void *payload);
512
42e50b5e
ET
513typedef int (*git_repository_mergehead_foreach_cb)(const git_oid *oid,
514 void *payload);
515
516/**
517 * If a merge is in progress, call callback 'cb' for each commit ID in the
518 * MERGE_HEAD file.
519 *
520 * @param repo A repository object
521 * @param callback Callback function
522 * @param apyload Pointer to callback data (optional)
523 * @return 0 on success, GIT_ENOTFOUND, GIT_EUSER or error
524 */
525GIT_EXTERN(int) git_repository_mergehead_foreach(git_repository *repo,
526 git_repository_mergehead_foreach_cb callback,
527 void *payload);
528
47bfa0be
RB
529/**
530 * Calculate hash of file using repository filtering rules.
531 *
532 * If you simply want to calculate the hash of a file on disk with no filters,
533 * you can just use the `git_odb_hashfile()` API. However, if you want to
534 * hash a file in the repository and you want to apply filtering rules (e.g.
535 * crlf filters) before generating the SHA, then use this function.
536 *
537 * @param out Output value of calculated SHA
a13fb55a 538 * @param repo Repository pointer
47bfa0be
RB
539 * @param path Path to file on disk whose contents should be hashed. If the
540 * repository is not NULL, this can be a relative path.
541 * @param type The object type to hash as (e.g. GIT_OBJ_BLOB)
542 * @param as_path The path to use to look up filtering rules. If this is
543 * NULL, then the `path` parameter will be used instead. If
544 * this is passed as the empty string, then no filters will be
545 * applied when calculating the hash.
546 */
547GIT_EXTERN(int) git_repository_hashfile(
0cb16fe9
L
548 git_oid *out,
549 git_repository *repo,
550 const char *path,
551 git_otype type,
552 const char *as_path);
074841ec 553
44af67a8 554/**
555 * Make the repository HEAD point to the specified reference.
556 *
557 * If the provided reference points to a Tree or a Blob, the HEAD is
558 * unaltered and -1 is returned.
559 *
560 * If the provided reference points to a branch, the HEAD will point
561 * to that branch, staying attached, or become attached if it isn't yet.
562 * If the branch doesn't exist yet, no error will be return. The HEAD
563 * will then be attached to an unborn branch.
564 *
565 * Otherwise, the HEAD will be detached and will directly point to
566 * the Commit.
567 *
568 * @param repo Repository pointer
569 * @param refname Canonical name of the reference the HEAD should point at
570 * @return 0 on success, or an error code
571 */
572GIT_EXTERN(int) git_repository_set_head(
573 git_repository* repo,
574 const char* refname);
575
4ebe38bd 576/**
577 * Make the repository HEAD directly point to the Commit.
578 *
579 * If the provided committish cannot be found in the repository, the HEAD
580 * is unaltered and GIT_ENOTFOUND is returned.
581 *
582 * If the provided commitish cannot be peeled into a commit, the HEAD
583 * is unaltered and -1 is returned.
584 *
585 * Otherwise, the HEAD will eventually be detached and will directly point to
586 * the peeled Commit.
587 *
588 * @param repo Repository pointer
589 * @param commitish Object id of the Commit the HEAD should point to
590 * @return 0 on success, or an error code
591 */
592GIT_EXTERN(int) git_repository_set_head_detached(
593 git_repository* repo,
594 const git_oid* commitish);
595
3f4c3072 596/**
597 * Detach the HEAD.
598 *
599 * If the HEAD is already detached and points to a Commit, 0 is returned.
600 *
601 * If the HEAD is already detached and points to a Tag, the HEAD is
602 * updated into making it point to the peeled Commit, and 0 is returned.
603 *
604 * If the HEAD is already detached and points to a non commitish, the HEAD is
7eb222fc 605 * unaltered, and -1 is returned.
3f4c3072 606 *
607 * Otherwise, the HEAD will be detached and point to the peeled Commit.
608 *
609 * @param repo Repository pointer
8b05bea8 610 * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
875b16eb 611 * branch or an error code
3f4c3072 612 */
613GIT_EXTERN(int) git_repository_detach_head(
614 git_repository* repo);
615
632d8b23
ET
616typedef enum {
617 GIT_REPOSITORY_STATE_NONE,
618 GIT_REPOSITORY_STATE_MERGE,
619 GIT_REPOSITORY_STATE_REVERT,
620 GIT_REPOSITORY_STATE_CHERRY_PICK,
31966d20 621 GIT_REPOSITORY_STATE_BISECT,
622 GIT_REPOSITORY_STATE_REBASE,
623 GIT_REPOSITORY_STATE_REBASE_INTERACTIVE,
624 GIT_REPOSITORY_STATE_REBASE_MERGE,
625 GIT_REPOSITORY_STATE_APPLY_MAILBOX,
626 GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE,
632d8b23
ET
627} git_repository_state_t;
628
629/**
630 * Determines the status of a git repository - ie, whether an operation
631 * (merge, cherry-pick, etc) is in progress.
632 *
633 * @param repo Repository pointer
634 * @return The state of the repository
635 */
636GIT_EXTERN(int) git_repository_state(git_repository *repo);
637
bade5194
VM
638/**
639 * Sets the active namespace for this Git Repository
640 *
641 * This namespace affects all reference operations for the repo.
642 * See `man gitnamespaces`
643 *
644 * @param repo The repo
645 * @param nmspace The namespace. This should not include the refs
646 * folder, e.g. to namespace all references under `refs/namespaces/foo/`,
647 * use `foo` as the namespace.
648 * @return 0 on success, -1 on error
649 */
650GIT_EXTERN(int) git_repository_set_namespace(git_repository *repo, const char *nmspace);
651
652/**
653 * Get the currently active namespace for this repository
654 *
655 * @param repo The repo
656 * @return the active namespace, or NULL if there isn't one
657 */
658GIT_EXTERN(const char *) git_repository_get_namespace(git_repository *repo);
659
93d8f77f
BS
660
661/**
662 * Determine if the repository was a shallow clone
663 *
664 * @param repo The repository
665 * @return 1 if shallow, zero if not
666 */
667GIT_EXTERN(int) git_repository_is_shallow(git_repository *repo);
668
3315782c
VM
669/** @} */
670GIT_END_DECL
671#endif