]>
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 { |
662880ca RB |
242 | uint32_t flags; |
243 | uint32_t mode; | |
244 | const char *workdir_path; | |
245 | const char *description; | |
246 | const char *template_path; | |
247 | const char *initial_head; | |
248 | const char *origin_url; | |
249 | } git_repository_init_options; | |
250 | ||
251 | /** | |
252 | * Create a new Git repository in the given folder with extended controls. | |
253 | * | |
254 | * This will initialize a new git repository (creating the repo_path | |
255 | * if requested by flags) and working directory as needed. It will | |
256 | * auto-detect the case sensitivity of the file system and if the | |
257 | * file system supports file mode bits correctly. | |
258 | * | |
c9fc4a6f | 259 | * @param out Pointer to the repo which will be created or reinitialized. |
662880ca RB |
260 | * @param repo_path The path to the repository. |
261 | * @param opts Pointer to git_repository_init_options struct. | |
262 | * @return 0 or an error code on failure. | |
263 | */ | |
264 | GIT_EXTERN(int) git_repository_init_ext( | |
c9fc4a6f | 265 | git_repository **out, |
662880ca RB |
266 | const char *repo_path, |
267 | git_repository_init_options *opts); | |
4b8e27c8 | 268 | |
3601c4bf | 269 | /** |
270 | * Retrieve and resolve the reference pointed at by HEAD. | |
271 | * | |
ca94e031 RB |
272 | * The returned `git_reference` will be owned by caller and |
273 | * `git_reference_free()` must be called when done with it to release the | |
274 | * allocated memory and prevent a leak. | |
275 | * | |
c9fc4a6f | 276 | * @param out pointer to the reference which will be retrieved |
3601c4bf | 277 | * @param repo a repository object |
278 | * | |
8b05bea8 | 279 | * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing |
b1a3a70e | 280 | * branch, GIT_ENOTFOUND when HEAD is missing; an error code otherwise |
3601c4bf | 281 | */ |
c9fc4a6f | 282 | GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo); |
3601c4bf | 283 | |
35502d2e CMN |
284 | /** |
285 | * Check if a repository's HEAD is detached | |
286 | * | |
287 | * A repository's HEAD is detached when it points directly to a commit | |
288 | * instead of a branch. | |
289 | * | |
290 | * @param repo Repo to test | |
d73c94b2 | 291 | * @return 1 if HEAD is detached, 0 if it's not; error code if there |
35502d2e CMN |
292 | * was an error. |
293 | */ | |
408d733b | 294 | GIT_EXTERN(int) git_repository_head_detached(git_repository *repo); |
35502d2e CMN |
295 | |
296 | /** | |
297 | * Check if the current branch is an orphan | |
298 | * | |
299 | * An orphan branch is one named from HEAD but which doesn't exist in | |
300 | * the refs namespace, because it doesn't have any commit to point to. | |
301 | * | |
302 | * @param repo Repo to test | |
303 | * @return 1 if the current branch is an orphan, 0 if it's not; error | |
d73c94b2 | 304 | * code if there was an error |
35502d2e | 305 | */ |
408d733b | 306 | GIT_EXTERN(int) git_repository_head_orphan(git_repository *repo); |
35502d2e | 307 | |
41233c40 VM |
308 | /** |
309 | * Check if a repository is empty | |
310 | * | |
311 | * An empty repository has just been initialized and contains | |
6091457e | 312 | * no references. |
41233c40 VM |
313 | * |
314 | * @param repo Repo to test | |
315 | * @return 1 if the repository is empty, 0 if it isn't, error code | |
316 | * if the repository is corrupted | |
317 | */ | |
318 | GIT_EXTERN(int) git_repository_is_empty(git_repository *repo); | |
319 | ||
6632c155 VM |
320 | /** |
321 | * Get the path of this repository | |
322 | * | |
323 | * This is the path of the `.git` folder for normal repositories, | |
324 | * or of the repository itself for bare repositories. | |
325 | * | |
326 | * @param repo A repository object | |
327 | * @return the path to the repository | |
328 | */ | |
9462c471 | 329 | GIT_EXTERN(const char *) git_repository_path(git_repository *repo); |
6632c155 VM |
330 | |
331 | /** | |
332 | * Get the path of the working directory for this repository | |
333 | * | |
334 | * If the repository is bare, this function will always return | |
335 | * NULL. | |
336 | * | |
337 | * @param repo A repository object | |
338 | * @return the path to the working dir, if it exists | |
339 | */ | |
9462c471 | 340 | GIT_EXTERN(const char *) git_repository_workdir(git_repository *repo); |
6632c155 VM |
341 | |
342 | /** | |
343 | * Set the path to the working directory for this repository | |
344 | * | |
345 | * The working directory doesn't need to be the same one | |
346 | * that contains the `.git` folder for this repository. | |
347 | * | |
348 | * If this repository is bare, setting its working directory | |
349 | * will turn it into a normal repository, capable of performing | |
350 | * all the common workdir operations (checkout, status, index | |
351 | * manipulation, etc). | |
352 | * | |
353 | * @param repo A repository object | |
354 | * @param workdir The path to a working directory | |
991a56c7 RB |
355 | * @param update_gitlink Create/update gitlink in workdir and set config |
356 | * "core.worktree" (if workdir is not the parent of the .git directory) | |
e172cf08 | 357 | * @return 0, or an error code |
6632c155 | 358 | */ |
991a56c7 RB |
359 | GIT_EXTERN(int) git_repository_set_workdir( |
360 | git_repository *repo, const char *workdir, int update_gitlink); | |
4a34b3a9 | 361 | |
fa9bcd81 | 362 | /** |
363 | * Check if a repository is bare | |
364 | * | |
365 | * @param repo Repo to test | |
28ba94ce | 366 | * @return 1 if the repository is bare, 0 otherwise. |
fa9bcd81 | 367 | */ |
368 | GIT_EXTERN(int) git_repository_is_bare(git_repository *repo); | |
369 | ||
6632c155 VM |
370 | /** |
371 | * Get the configuration file for this repository. | |
372 | * | |
373 | * If a configuration file has not been set, the default | |
374 | * config set for the repository will be returned, including | |
375 | * global and system configurations (if they are available). | |
376 | * | |
377 | * The configuration file must be freed once it's no longer | |
378 | * being used by the user. | |
379 | * | |
380 | * @param out Pointer to store the loaded config file | |
381 | * @param repo A repository object | |
e172cf08 | 382 | * @return 0, or an error code |
6632c155 | 383 | */ |
9462c471 | 384 | GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo); |
6632c155 VM |
385 | |
386 | /** | |
387 | * Set the configuration file for this repository | |
388 | * | |
389 | * This configuration file will be used for all configuration | |
390 | * queries involving this repository. | |
391 | * | |
392 | * The repository will keep a reference to the config file; | |
393 | * the user must still free the config after setting it | |
394 | * to the repository, or it will leak. | |
395 | * | |
396 | * @param repo A repository object | |
397 | * @param config A Config object | |
398 | */ | |
9462c471 | 399 | GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config); |
40fe5fbe | 400 | |
6632c155 VM |
401 | /** |
402 | * Get the Object Database for this repository. | |
403 | * | |
404 | * If a custom ODB has not been set, the default | |
405 | * database for the repository will be returned (the one | |
406 | * located in `.git/objects`). | |
407 | * | |
408 | * The ODB must be freed once it's no longer being used by | |
409 | * the user. | |
410 | * | |
411 | * @param out Pointer to store the loaded ODB | |
412 | * @param repo A repository object | |
e172cf08 | 413 | * @return 0, or an error code |
6632c155 | 414 | */ |
9462c471 | 415 | GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo); |
6632c155 VM |
416 | |
417 | /** | |
418 | * Set the Object Database for this repository | |
419 | * | |
420 | * The ODB will be used for all object-related operations | |
421 | * involving this repository. | |
422 | * | |
423 | * The repository will keep a reference to the ODB; the user | |
424 | * must still free the ODB object after setting it to the | |
425 | * repository, or it will leak. | |
426 | * | |
427 | * @param repo A repository object | |
428 | * @param odb An ODB object | |
429 | */ | |
9462c471 | 430 | GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb); |
b22d1479 | 431 | |
6632c155 VM |
432 | /** |
433 | * Get the Index file for this repository. | |
434 | * | |
435 | * If a custom index has not been set, the default | |
436 | * index for the repository will be returned (the one | |
437 | * located in `.git/index`). | |
438 | * | |
439 | * The index must be freed once it's no longer being used by | |
440 | * the user. | |
441 | * | |
442 | * @param out Pointer to store the loaded index | |
443 | * @param repo A repository object | |
e172cf08 | 444 | * @return 0, or an error code |
6632c155 | 445 | */ |
9462c471 | 446 | GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo); |
6632c155 VM |
447 | |
448 | /** | |
449 | * Set the index file for this repository | |
450 | * | |
451 | * This index will be used for all index-related operations | |
452 | * involving this repository. | |
453 | * | |
454 | * The repository will keep a reference to the index file; | |
455 | * the user must still free the index after setting it | |
456 | * to the repository, or it will leak. | |
457 | * | |
458 | * @param repo A repository object | |
459 | * @param index An index object | |
460 | */ | |
9462c471 | 461 | GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index); |
40fe5fbe | 462 | |
074841ec | 463 | /** |
cc548c7b | 464 | * Retrieve git's prepared message |
074841ec CMN |
465 | * |
466 | * Operations such as git revert/cherry-pick/merge with the -n option | |
467 | * stop just short of creating a commit with the changes and save | |
468 | * their prepared message in .git/MERGE_MSG so the next git-commit | |
469 | * execution can present it to the user for them to amend if they | |
470 | * wish. | |
471 | * | |
472 | * Use this function to get the contents of this file. Don't forget to | |
473 | * remove the file after you create the commit. | |
e9ca852e | 474 | * |
c9fc4a6f | 475 | * @param out Buffer to write data into or NULL to just read required size |
e9ca852e RB |
476 | * @param len Length of buffer in bytes |
477 | * @param repo Repository to read prepared message from | |
478 | * @return Bytes written to buffer, GIT_ENOTFOUND if no message, or -1 on error | |
074841ec | 479 | */ |
c9fc4a6f | 480 | GIT_EXTERN(int) git_repository_message(char *out, size_t len, git_repository *repo); |
074841ec CMN |
481 | |
482 | /** | |
483 | * Remove git's prepared message. | |
484 | * | |
485 | * Remove the message that `git_repository_message` retrieves. | |
486 | */ | |
487 | GIT_EXTERN(int) git_repository_message_remove(git_repository *repo); | |
488 | ||
47bfa0be RB |
489 | /** |
490 | * Calculate hash of file using repository filtering rules. | |
491 | * | |
492 | * If you simply want to calculate the hash of a file on disk with no filters, | |
493 | * you can just use the `git_odb_hashfile()` API. However, if you want to | |
494 | * hash a file in the repository and you want to apply filtering rules (e.g. | |
495 | * crlf filters) before generating the SHA, then use this function. | |
496 | * | |
497 | * @param out Output value of calculated SHA | |
a13fb55a | 498 | * @param repo Repository pointer |
47bfa0be RB |
499 | * @param path Path to file on disk whose contents should be hashed. If the |
500 | * repository is not NULL, this can be a relative path. | |
501 | * @param type The object type to hash as (e.g. GIT_OBJ_BLOB) | |
502 | * @param as_path The path to use to look up filtering rules. If this is | |
503 | * NULL, then the `path` parameter will be used instead. If | |
504 | * this is passed as the empty string, then no filters will be | |
505 | * applied when calculating the hash. | |
506 | */ | |
507 | GIT_EXTERN(int) git_repository_hashfile( | |
508 | git_oid *out, | |
509 | git_repository *repo, | |
510 | const char *path, | |
511 | git_otype type, | |
512 | const char *as_path); | |
074841ec | 513 | |
44af67a8 | 514 | /** |
515 | * Make the repository HEAD point to the specified reference. | |
516 | * | |
517 | * If the provided reference points to a Tree or a Blob, the HEAD is | |
518 | * unaltered and -1 is returned. | |
519 | * | |
520 | * If the provided reference points to a branch, the HEAD will point | |
521 | * to that branch, staying attached, or become attached if it isn't yet. | |
522 | * If the branch doesn't exist yet, no error will be return. The HEAD | |
523 | * will then be attached to an unborn branch. | |
524 | * | |
525 | * Otherwise, the HEAD will be detached and will directly point to | |
526 | * the Commit. | |
527 | * | |
528 | * @param repo Repository pointer | |
529 | * @param refname Canonical name of the reference the HEAD should point at | |
530 | * @return 0 on success, or an error code | |
531 | */ | |
532 | GIT_EXTERN(int) git_repository_set_head( | |
533 | git_repository* repo, | |
534 | const char* refname); | |
535 | ||
4ebe38bd | 536 | /** |
537 | * Make the repository HEAD directly point to the Commit. | |
538 | * | |
539 | * If the provided committish cannot be found in the repository, the HEAD | |
540 | * is unaltered and GIT_ENOTFOUND is returned. | |
541 | * | |
542 | * If the provided commitish cannot be peeled into a commit, the HEAD | |
543 | * is unaltered and -1 is returned. | |
544 | * | |
545 | * Otherwise, the HEAD will eventually be detached and will directly point to | |
546 | * the peeled Commit. | |
547 | * | |
548 | * @param repo Repository pointer | |
549 | * @param commitish Object id of the Commit the HEAD should point to | |
550 | * @return 0 on success, or an error code | |
551 | */ | |
552 | GIT_EXTERN(int) git_repository_set_head_detached( | |
553 | git_repository* repo, | |
554 | const git_oid* commitish); | |
555 | ||
3f4c3072 | 556 | /** |
557 | * Detach the HEAD. | |
558 | * | |
559 | * If the HEAD is already detached and points to a Commit, 0 is returned. | |
560 | * | |
561 | * If the HEAD is already detached and points to a Tag, the HEAD is | |
562 | * updated into making it point to the peeled Commit, and 0 is returned. | |
563 | * | |
564 | * If the HEAD is already detached and points to a non commitish, the HEAD is | |
565 | * unaletered, and -1 is returned. | |
566 | * | |
567 | * Otherwise, the HEAD will be detached and point to the peeled Commit. | |
568 | * | |
569 | * @param repo Repository pointer | |
8b05bea8 | 570 | * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing |
875b16eb | 571 | * branch or an error code |
3f4c3072 | 572 | */ |
573 | GIT_EXTERN(int) git_repository_detach_head( | |
574 | git_repository* repo); | |
575 | ||
632d8b23 ET |
576 | typedef enum { |
577 | GIT_REPOSITORY_STATE_NONE, | |
578 | GIT_REPOSITORY_STATE_MERGE, | |
579 | GIT_REPOSITORY_STATE_REVERT, | |
580 | GIT_REPOSITORY_STATE_CHERRY_PICK, | |
31966d20 | 581 | GIT_REPOSITORY_STATE_BISECT, |
582 | GIT_REPOSITORY_STATE_REBASE, | |
583 | GIT_REPOSITORY_STATE_REBASE_INTERACTIVE, | |
584 | GIT_REPOSITORY_STATE_REBASE_MERGE, | |
585 | GIT_REPOSITORY_STATE_APPLY_MAILBOX, | |
586 | GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE, | |
632d8b23 ET |
587 | } git_repository_state_t; |
588 | ||
589 | /** | |
590 | * Determines the status of a git repository - ie, whether an operation | |
591 | * (merge, cherry-pick, etc) is in progress. | |
592 | * | |
593 | * @param repo Repository pointer | |
594 | * @return The state of the repository | |
595 | */ | |
596 | GIT_EXTERN(int) git_repository_state(git_repository *repo); | |
597 | ||
3315782c VM |
598 | /** @} */ |
599 | GIT_END_DECL | |
600 | #endif |