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