]>
Commit | Line | Data |
---|---|---|
f5918330 | 1 | /* |
5e0de328 | 2 | * Copyright (C) 2009-2012 the libgit2 contributors |
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 | */ | |
21 | GIT_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 | 36 | GIT_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 | 49 | GIT_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 | 79 | GIT_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 | 98 | typedef 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 | */ |
120 | GIT_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 | ||
3315782c VM |
126 | /** |
127 | * Free a previously allocated repository | |
6b2a1941 | 128 | * |
f0d08b7c VM |
129 | * Note that after a repository is free'd, all the objects it has spawned |
130 | * will still exist until they are manually closed by the user | |
45e79e37 | 131 | * with `git_object_free`, but accessing any of the attributes of |
f0d08b7c VM |
132 | * an object without a backing repository will result in undefined |
133 | * behavior | |
134 | * | |
3315782c VM |
135 | * @param repo repository handle to close. If NULL nothing occurs. |
136 | */ | |
137 | GIT_EXTERN(void) git_repository_free(git_repository *repo); | |
138 | ||
e1f8cad0 | 139 | /** |
40c44d2f | 140 | * Creates a new Git repository in the given folder. |
e1f8cad0 | 141 | * |
40c44d2f VM |
142 | * TODO: |
143 | * - Reinit the repository | |
e1f8cad0 | 144 | * |
c9fc4a6f | 145 | * @param out pointer to the repo which will be created or reinitialized |
e1f8cad0 | 146 | * @param path the path to the repository |
662880ca RB |
147 | * @param is_bare if true, a Git repository without a working directory is |
148 | * created at the pointed path. If false, provided path will be | |
149 | * considered as the working directory into which the .git directory | |
150 | * will be created. | |
40c44d2f | 151 | * |
e172cf08 | 152 | * @return 0 or an error code |
e1f8cad0 | 153 | */ |
662880ca | 154 | GIT_EXTERN(int) git_repository_init( |
c9fc4a6f | 155 | git_repository **out, |
662880ca RB |
156 | const char *path, |
157 | unsigned is_bare); | |
158 | ||
159 | /** | |
160 | * Option flags for `git_repository_init_ext`. | |
161 | * | |
162 | * These flags configure extra behaviors to `git_repository_init_ext`. | |
163 | * In every case, the default behavior is the zero value (i.e. flag is | |
164 | * not set). Just OR the flag values together for the `flags` parameter | |
165 | * when initializing a new repo. Details of individual values are: | |
166 | * | |
167 | * * BARE - Create a bare repository with no working directory. | |
168 | * * NO_REINIT - Return an EEXISTS error if the repo_path appears to | |
169 | * already be an git repository. | |
170 | * * NO_DOTGIT_DIR - Normally a "/.git/" will be appended to the repo | |
171 | * path for non-bare repos (if it is not already there), but | |
172 | * passing this flag prevents that behavior. | |
173 | * * MKDIR - Make the repo_path (and workdir_path) as needed. Init is | |
174 | * always willing to create the ".git" directory even without this | |
175 | * flag. This flag tells init to create the trailing component of | |
176 | * the repo and workdir paths as needed. | |
177 | * * MKPATH - Recursively make all components of the repo and workdir | |
178 | * paths as necessary. | |
179 | * * EXTERNAL_TEMPLATE - libgit2 normally uses internal templates to | |
180 | * initialize a new repo. This flags enables external templates, | |
181 | * looking the "template_path" from the options if set, or the | |
182 | * `init.templatedir` global config if not, or falling back on | |
183 | * "/usr/share/git-core/templates" if it exists. | |
662880ca | 184 | */ |
f4a62c30 | 185 | typedef enum { |
662880ca RB |
186 | GIT_REPOSITORY_INIT_BARE = (1u << 0), |
187 | GIT_REPOSITORY_INIT_NO_REINIT = (1u << 1), | |
188 | GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = (1u << 2), | |
189 | GIT_REPOSITORY_INIT_MKDIR = (1u << 3), | |
190 | GIT_REPOSITORY_INIT_MKPATH = (1u << 4), | |
191 | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = (1u << 5), | |
f4a62c30 | 192 | } git_repository_init_flag_t; |
ca1b6e54 RB |
193 | |
194 | /** | |
195 | * Mode options for `git_repository_init_ext`. | |
196 | * | |
197 | * Set the mode field of the `git_repository_init_options` structure | |
198 | * either to the custom mode that you would like, or to one of the | |
199 | * following modes: | |
200 | * | |
201 | * * SHARED_UMASK - Use permissions configured by umask - the default. | |
202 | * * SHARED_GROUP - Use "--shared=group" behavior, chmod'ing the new repo | |
203 | * to be group writable and "g+sx" for sticky group assignment. | |
204 | * * SHARED_ALL - Use "--shared=all" behavior, adding world readability. | |
205 | * * Anything else - Set to custom value. | |
206 | */ | |
f4a62c30 | 207 | typedef enum { |
ca1b6e54 RB |
208 | GIT_REPOSITORY_INIT_SHARED_UMASK = 0, |
209 | GIT_REPOSITORY_INIT_SHARED_GROUP = 0002775, | |
210 | GIT_REPOSITORY_INIT_SHARED_ALL = 0002777, | |
f4a62c30 | 211 | } git_repository_init_mode_t; |
662880ca RB |
212 | |
213 | /** | |
214 | * Extended options structure for `git_repository_init_ext`. | |
215 | * | |
216 | * This contains extra options for `git_repository_init_ext` that enable | |
217 | * additional initialization features. The fields are: | |
218 | * | |
219 | * * flags - Combination of GIT_REPOSITORY_INIT flags above. | |
ca1b6e54 RB |
220 | * * mode - Set to one of the standard GIT_REPOSITORY_INIT_SHARED_... |
221 | * constants above, or to a custom value that you would like. | |
662880ca | 222 | * * workdir_path - The path to the working dir or NULL for default (i.e. |
ca1b6e54 RB |
223 | * repo_path parent on non-bare repos). IF THIS IS RELATIVE PATH, |
224 | * IT WILL BE EVALUATED RELATIVE TO THE REPO_PATH. If this is not | |
225 | * the "natural" working directory, a .git gitlink file will be | |
226 | * created here linking to the repo_path. | |
662880ca RB |
227 | * * description - If set, this will be used to initialize the "description" |
228 | * file in the repository, instead of using the template content. | |
229 | * * template_path - When GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE is set, | |
230 | * this contains the path to use for the template directory. If | |
231 | * this is NULL, the config or default directory options will be | |
232 | * used instead. | |
233 | * * initial_head - The name of the head to point HEAD at. If NULL, then | |
234 | * this will be treated as "master" and the HEAD ref will be set | |
235 | * to "refs/heads/master". If this begins with "refs/" it will be | |
236 | * used verbatim; otherwise "refs/heads/" will be prefixed. | |
237 | * * origin_url - If this is non-NULL, then after the rest of the | |
238 | * repository initialization is completed, an "origin" remote | |
239 | * will be added pointing to this URL. | |
240 | */ | |
ca94e031 | 241 | typedef struct { |
bde336ea | 242 | unsigned int version; |
662880ca RB |
243 | uint32_t flags; |
244 | uint32_t mode; | |
245 | const char *workdir_path; | |
246 | const char *description; | |
247 | const char *template_path; | |
248 | const char *initial_head; | |
249 | const char *origin_url; | |
250 | } git_repository_init_options; | |
251 | ||
bde336ea | 252 | #define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1 |
fac43c54 | 253 | #define GIT_REPOSITORY_INIT_OPTIONS_INIT {GIT_REPOSITORY_INIT_OPTIONS_VERSION} |
bde336ea | 254 | |
662880ca RB |
255 | /** |
256 | * Create a new Git repository in the given folder with extended controls. | |
257 | * | |
258 | * This will initialize a new git repository (creating the repo_path | |
259 | * if requested by flags) and working directory as needed. It will | |
260 | * auto-detect the case sensitivity of the file system and if the | |
261 | * file system supports file mode bits correctly. | |
262 | * | |
c9fc4a6f | 263 | * @param out Pointer to the repo which will be created or reinitialized. |
662880ca RB |
264 | * @param repo_path The path to the repository. |
265 | * @param opts Pointer to git_repository_init_options struct. | |
266 | * @return 0 or an error code on failure. | |
267 | */ | |
268 | GIT_EXTERN(int) git_repository_init_ext( | |
c9fc4a6f | 269 | git_repository **out, |
662880ca RB |
270 | const char *repo_path, |
271 | git_repository_init_options *opts); | |
4b8e27c8 | 272 | |
3601c4bf | 273 | /** |
274 | * Retrieve and resolve the reference pointed at by HEAD. | |
275 | * | |
ca94e031 RB |
276 | * The returned `git_reference` will be owned by caller and |
277 | * `git_reference_free()` must be called when done with it to release the | |
278 | * allocated memory and prevent a leak. | |
279 | * | |
c9fc4a6f | 280 | * @param out pointer to the reference which will be retrieved |
3601c4bf | 281 | * @param repo a repository object |
282 | * | |
8b05bea8 | 283 | * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing |
b1a3a70e | 284 | * branch, GIT_ENOTFOUND when HEAD is missing; an error code otherwise |
3601c4bf | 285 | */ |
c9fc4a6f | 286 | GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo); |
3601c4bf | 287 | |
35502d2e CMN |
288 | /** |
289 | * Check if a repository's HEAD is detached | |
290 | * | |
291 | * A repository's HEAD is detached when it points directly to a commit | |
292 | * instead of a branch. | |
293 | * | |
294 | * @param repo Repo to test | |
d73c94b2 | 295 | * @return 1 if HEAD is detached, 0 if it's not; error code if there |
35502d2e CMN |
296 | * was an error. |
297 | */ | |
408d733b | 298 | GIT_EXTERN(int) git_repository_head_detached(git_repository *repo); |
35502d2e CMN |
299 | |
300 | /** | |
301 | * Check if the current branch is an orphan | |
302 | * | |
303 | * An orphan branch is one named from HEAD but which doesn't exist in | |
304 | * the refs namespace, because it doesn't have any commit to point to. | |
305 | * | |
306 | * @param repo Repo to test | |
307 | * @return 1 if the current branch is an orphan, 0 if it's not; error | |
d73c94b2 | 308 | * code if there was an error |
35502d2e | 309 | */ |
408d733b | 310 | GIT_EXTERN(int) git_repository_head_orphan(git_repository *repo); |
35502d2e | 311 | |
41233c40 VM |
312 | /** |
313 | * Check if a repository is empty | |
314 | * | |
315 | * An empty repository has just been initialized and contains | |
6091457e | 316 | * no references. |
41233c40 VM |
317 | * |
318 | * @param repo Repo to test | |
319 | * @return 1 if the repository is empty, 0 if it isn't, error code | |
320 | * if the repository is corrupted | |
321 | */ | |
322 | GIT_EXTERN(int) git_repository_is_empty(git_repository *repo); | |
323 | ||
6632c155 VM |
324 | /** |
325 | * Get the path of this repository | |
326 | * | |
327 | * This is the path of the `.git` folder for normal repositories, | |
328 | * or of the repository itself for bare repositories. | |
329 | * | |
330 | * @param repo A repository object | |
331 | * @return the path to the repository | |
332 | */ | |
9462c471 | 333 | GIT_EXTERN(const char *) git_repository_path(git_repository *repo); |
6632c155 VM |
334 | |
335 | /** | |
336 | * Get the path of the working directory for this repository | |
337 | * | |
338 | * If the repository is bare, this function will always return | |
339 | * NULL. | |
340 | * | |
341 | * @param repo A repository object | |
342 | * @return the path to the working dir, if it exists | |
343 | */ | |
9462c471 | 344 | GIT_EXTERN(const char *) git_repository_workdir(git_repository *repo); |
6632c155 VM |
345 | |
346 | /** | |
347 | * Set the path to the working directory for this repository | |
348 | * | |
349 | * The working directory doesn't need to be the same one | |
350 | * that contains the `.git` folder for this repository. | |
351 | * | |
352 | * If this repository is bare, setting its working directory | |
353 | * will turn it into a normal repository, capable of performing | |
354 | * all the common workdir operations (checkout, status, index | |
355 | * manipulation, etc). | |
356 | * | |
357 | * @param repo A repository object | |
358 | * @param workdir The path to a working directory | |
991a56c7 RB |
359 | * @param update_gitlink Create/update gitlink in workdir and set config |
360 | * "core.worktree" (if workdir is not the parent of the .git directory) | |
e172cf08 | 361 | * @return 0, or an error code |
6632c155 | 362 | */ |
991a56c7 RB |
363 | GIT_EXTERN(int) git_repository_set_workdir( |
364 | git_repository *repo, const char *workdir, int update_gitlink); | |
4a34b3a9 | 365 | |
fa9bcd81 | 366 | /** |
367 | * Check if a repository is bare | |
368 | * | |
369 | * @param repo Repo to test | |
28ba94ce | 370 | * @return 1 if the repository is bare, 0 otherwise. |
fa9bcd81 | 371 | */ |
372 | GIT_EXTERN(int) git_repository_is_bare(git_repository *repo); | |
373 | ||
6632c155 VM |
374 | /** |
375 | * Get the configuration file for this repository. | |
376 | * | |
377 | * If a configuration file has not been set, the default | |
378 | * config set for the repository will be returned, including | |
379 | * global and system configurations (if they are available). | |
380 | * | |
381 | * The configuration file must be freed once it's no longer | |
382 | * being used by the user. | |
383 | * | |
384 | * @param out Pointer to store the loaded config file | |
385 | * @param repo A repository object | |
e172cf08 | 386 | * @return 0, or an error code |
6632c155 | 387 | */ |
9462c471 | 388 | GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo); |
6632c155 VM |
389 | |
390 | /** | |
391 | * Set the configuration file for this repository | |
392 | * | |
393 | * This configuration file will be used for all configuration | |
394 | * queries involving this repository. | |
395 | * | |
396 | * The repository will keep a reference to the config file; | |
397 | * the user must still free the config after setting it | |
398 | * to the repository, or it will leak. | |
399 | * | |
400 | * @param repo A repository object | |
401 | * @param config A Config object | |
402 | */ | |
9462c471 | 403 | GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config); |
40fe5fbe | 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 | 419 | GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo); |
6632c155 VM |
420 | |
421 | /** | |
422 | * Set the Object Database for this repository | |
423 | * | |
424 | * The ODB will be used for all object-related operations | |
425 | * involving this repository. | |
426 | * | |
427 | * The repository will keep a reference to the ODB; the user | |
428 | * must still free the ODB object after setting it to the | |
429 | * repository, or it will leak. | |
430 | * | |
431 | * @param repo A repository object | |
432 | * @param odb An ODB object | |
433 | */ | |
9462c471 | 434 | GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb); |
b22d1479 | 435 | |
6632c155 VM |
436 | /** |
437 | * Get the Index file for this repository. | |
438 | * | |
439 | * If a custom index has not been set, the default | |
440 | * index for the repository will be returned (the one | |
441 | * located in `.git/index`). | |
442 | * | |
443 | * The index must be freed once it's no longer being used by | |
444 | * the user. | |
445 | * | |
446 | * @param out Pointer to store the loaded index | |
447 | * @param repo A repository object | |
e172cf08 | 448 | * @return 0, or an error code |
6632c155 | 449 | */ |
9462c471 | 450 | GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo); |
6632c155 VM |
451 | |
452 | /** | |
453 | * Set the index file for this repository | |
454 | * | |
455 | * This index will be used for all index-related operations | |
456 | * involving this repository. | |
457 | * | |
458 | * The repository will keep a reference to the index file; | |
459 | * the user must still free the index after setting it | |
460 | * to the repository, or it will leak. | |
461 | * | |
462 | * @param repo A repository object | |
463 | * @param index An index object | |
464 | */ | |
9462c471 | 465 | GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index); |
40fe5fbe | 466 | |
074841ec | 467 | /** |
cc548c7b | 468 | * Retrieve git's prepared message |
074841ec CMN |
469 | * |
470 | * Operations such as git revert/cherry-pick/merge with the -n option | |
471 | * stop just short of creating a commit with the changes and save | |
472 | * their prepared message in .git/MERGE_MSG so the next git-commit | |
473 | * execution can present it to the user for them to amend if they | |
474 | * wish. | |
475 | * | |
476 | * Use this function to get the contents of this file. Don't forget to | |
477 | * remove the file after you create the commit. | |
e9ca852e | 478 | * |
c9fc4a6f | 479 | * @param out Buffer to write data into or NULL to just read required size |
e9ca852e RB |
480 | * @param len Length of buffer in bytes |
481 | * @param repo Repository to read prepared message from | |
482 | * @return Bytes written to buffer, GIT_ENOTFOUND if no message, or -1 on error | |
074841ec | 483 | */ |
c9fc4a6f | 484 | GIT_EXTERN(int) git_repository_message(char *out, size_t len, git_repository *repo); |
074841ec CMN |
485 | |
486 | /** | |
487 | * Remove git's prepared message. | |
488 | * | |
489 | * Remove the message that `git_repository_message` retrieves. | |
490 | */ | |
491 | GIT_EXTERN(int) git_repository_message_remove(git_repository *repo); | |
492 | ||
ad2bc32f ET |
493 | /** |
494 | * Remove all the metadata associated with an ongoing git merge, including | |
495 | * MERGE_HEAD, MERGE_MSG, etc. | |
496 | * | |
497 | * @param repo A repository object | |
498 | * @return 0 on success, or error | |
499 | */ | |
500 | GIT_EXTERN(int) git_repository_merge_cleanup(git_repository *repo); | |
501 | ||
7fcec834 ET |
502 | typedef int (*git_repository_fetchhead_foreach_cb)(const char *ref_name, |
503 | const char *remote_url, | |
504 | const git_oid *oid, | |
505 | unsigned int is_merge, | |
506 | void *payload); | |
507 | ||
508 | /** | |
509 | * Call callback 'callback' for each entry in the given FETCH_HEAD file. | |
510 | * | |
511 | * @param repo A repository object | |
512 | * @param callback Callback function | |
513 | * @param payload Pointer to callback data (optional) | |
514 | * @return 0 on success, GIT_ENOTFOUND, GIT_EUSER or error | |
515 | */ | |
516 | GIT_EXTERN(int) git_repository_fetchhead_foreach(git_repository *repo, | |
517 | git_repository_fetchhead_foreach_cb callback, | |
518 | void *payload); | |
519 | ||
42e50b5e ET |
520 | typedef int (*git_repository_mergehead_foreach_cb)(const git_oid *oid, |
521 | void *payload); | |
522 | ||
523 | /** | |
524 | * If a merge is in progress, call callback 'cb' for each commit ID in the | |
525 | * MERGE_HEAD file. | |
526 | * | |
527 | * @param repo A repository object | |
528 | * @param callback Callback function | |
529 | * @param apyload Pointer to callback data (optional) | |
530 | * @return 0 on success, GIT_ENOTFOUND, GIT_EUSER or error | |
531 | */ | |
532 | GIT_EXTERN(int) git_repository_mergehead_foreach(git_repository *repo, | |
533 | git_repository_mergehead_foreach_cb callback, | |
534 | void *payload); | |
535 | ||
47bfa0be RB |
536 | /** |
537 | * Calculate hash of file using repository filtering rules. | |
538 | * | |
539 | * If you simply want to calculate the hash of a file on disk with no filters, | |
540 | * you can just use the `git_odb_hashfile()` API. However, if you want to | |
541 | * hash a file in the repository and you want to apply filtering rules (e.g. | |
542 | * crlf filters) before generating the SHA, then use this function. | |
543 | * | |
544 | * @param out Output value of calculated SHA | |
a13fb55a | 545 | * @param repo Repository pointer |
47bfa0be RB |
546 | * @param path Path to file on disk whose contents should be hashed. If the |
547 | * repository is not NULL, this can be a relative path. | |
548 | * @param type The object type to hash as (e.g. GIT_OBJ_BLOB) | |
549 | * @param as_path The path to use to look up filtering rules. If this is | |
550 | * NULL, then the `path` parameter will be used instead. If | |
551 | * this is passed as the empty string, then no filters will be | |
552 | * applied when calculating the hash. | |
553 | */ | |
554 | GIT_EXTERN(int) git_repository_hashfile( | |
555 | git_oid *out, | |
556 | git_repository *repo, | |
557 | const char *path, | |
558 | git_otype type, | |
559 | const char *as_path); | |
074841ec | 560 | |
44af67a8 | 561 | /** |
562 | * Make the repository HEAD point to the specified reference. | |
563 | * | |
564 | * If the provided reference points to a Tree or a Blob, the HEAD is | |
565 | * unaltered and -1 is returned. | |
566 | * | |
567 | * If the provided reference points to a branch, the HEAD will point | |
568 | * to that branch, staying attached, or become attached if it isn't yet. | |
569 | * If the branch doesn't exist yet, no error will be return. The HEAD | |
570 | * will then be attached to an unborn branch. | |
571 | * | |
572 | * Otherwise, the HEAD will be detached and will directly point to | |
573 | * the Commit. | |
574 | * | |
575 | * @param repo Repository pointer | |
576 | * @param refname Canonical name of the reference the HEAD should point at | |
577 | * @return 0 on success, or an error code | |
578 | */ | |
579 | GIT_EXTERN(int) git_repository_set_head( | |
580 | git_repository* repo, | |
581 | const char* refname); | |
582 | ||
4ebe38bd | 583 | /** |
584 | * Make the repository HEAD directly point to the Commit. | |
585 | * | |
586 | * If the provided committish cannot be found in the repository, the HEAD | |
587 | * is unaltered and GIT_ENOTFOUND is returned. | |
588 | * | |
589 | * If the provided commitish cannot be peeled into a commit, the HEAD | |
590 | * is unaltered and -1 is returned. | |
591 | * | |
592 | * Otherwise, the HEAD will eventually be detached and will directly point to | |
593 | * the peeled Commit. | |
594 | * | |
595 | * @param repo Repository pointer | |
596 | * @param commitish Object id of the Commit the HEAD should point to | |
597 | * @return 0 on success, or an error code | |
598 | */ | |
599 | GIT_EXTERN(int) git_repository_set_head_detached( | |
600 | git_repository* repo, | |
601 | const git_oid* commitish); | |
602 | ||
3f4c3072 | 603 | /** |
604 | * Detach the HEAD. | |
605 | * | |
606 | * If the HEAD is already detached and points to a Commit, 0 is returned. | |
607 | * | |
608 | * If the HEAD is already detached and points to a Tag, the HEAD is | |
609 | * updated into making it point to the peeled Commit, and 0 is returned. | |
610 | * | |
611 | * If the HEAD is already detached and points to a non commitish, the HEAD is | |
612 | * unaletered, and -1 is returned. | |
613 | * | |
614 | * Otherwise, the HEAD will be detached and point to the peeled Commit. | |
615 | * | |
616 | * @param repo Repository pointer | |
8b05bea8 | 617 | * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing |
875b16eb | 618 | * branch or an error code |
3f4c3072 | 619 | */ |
620 | GIT_EXTERN(int) git_repository_detach_head( | |
621 | git_repository* repo); | |
622 | ||
632d8b23 ET |
623 | typedef enum { |
624 | GIT_REPOSITORY_STATE_NONE, | |
625 | GIT_REPOSITORY_STATE_MERGE, | |
626 | GIT_REPOSITORY_STATE_REVERT, | |
627 | GIT_REPOSITORY_STATE_CHERRY_PICK, | |
31966d20 | 628 | GIT_REPOSITORY_STATE_BISECT, |
629 | GIT_REPOSITORY_STATE_REBASE, | |
630 | GIT_REPOSITORY_STATE_REBASE_INTERACTIVE, | |
631 | GIT_REPOSITORY_STATE_REBASE_MERGE, | |
632 | GIT_REPOSITORY_STATE_APPLY_MAILBOX, | |
633 | GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE, | |
632d8b23 ET |
634 | } git_repository_state_t; |
635 | ||
636 | /** | |
637 | * Determines the status of a git repository - ie, whether an operation | |
638 | * (merge, cherry-pick, etc) is in progress. | |
639 | * | |
640 | * @param repo Repository pointer | |
641 | * @return The state of the repository | |
642 | */ | |
643 | GIT_EXTERN(int) git_repository_state(git_repository *repo); | |
644 | ||
3315782c VM |
645 | /** @} */ |
646 | GIT_END_DECL | |
647 | #endif |