1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 #ifndef INCLUDE_git_submodule_h__
8 #define INCLUDE_git_submodule_h__
9 
10 #include "common.h"
11 #include "types.h"
12 #include "oid.h"
13 #include "remote.h"
14 #include "checkout.h"
15 
16 /**
17  * @file git2/submodule.h
18  * @brief Git submodule management utilities
19  *
20  * Submodule support in libgit2 builds a list of known submodules and keeps
21  * it in the repository.  The list is built from the .gitmodules file, the
22  * .git/config file, the index, and the HEAD tree.  Items in the working
23  * directory that look like submodules (i.e. a git repo) but are not
24  * mentioned in those places won't be tracked.
25  *
26  * @defgroup git_submodule Git submodule management routines
27  * @ingroup Git
28  * @{
29  */
30 GIT_BEGIN_DECL
31 
32 /**
33  * Return codes for submodule status.
34  *
35  * A combination of these flags will be returned to describe the status of a
36  * submodule.  Depending on the "ignore" property of the submodule, some of
37  * the flags may never be returned because they indicate changes that are
38  * supposed to be ignored.
39  *
40  * Submodule info is contained in 4 places: the HEAD tree, the index, config
41  * files (both .git/config and .gitmodules), and the working directory.  Any
42  * or all of those places might be missing information about the submodule
43  * depending on what state the repo is in.  We consider all four places to
44  * build the combination of status flags.
45  *
46  * There are four values that are not really status, but give basic info
47  * about what sources of submodule data are available.  These will be
48  * returned even if ignore is set to "ALL".
49  *
50  * * IN_HEAD   - superproject head contains submodule
51  * * IN_INDEX  - superproject index contains submodule
52  * * IN_CONFIG - superproject gitmodules has submodule
53  * * IN_WD     - superproject workdir has submodule
54  *
55  * The following values will be returned so long as ignore is not "ALL".
56  *
57  * * INDEX_ADDED       - in index, not in head
58  * * INDEX_DELETED     - in head, not in index
59  * * INDEX_MODIFIED    - index and head don't match
60  * * WD_UNINITIALIZED  - workdir contains empty directory
61  * * WD_ADDED          - in workdir, not index
62  * * WD_DELETED        - in index, not workdir
63  * * WD_MODIFIED       - index and workdir head don't match
64  *
65  * The following can only be returned if ignore is "NONE" or "UNTRACKED".
66  *
67  * * WD_INDEX_MODIFIED - submodule workdir index is dirty
68  * * WD_WD_MODIFIED    - submodule workdir has modified files
69  *
70  * Lastly, the following will only be returned for ignore "NONE".
71  *
72  * * WD_UNTRACKED      - wd contains untracked files
73  */
74 typedef enum {
75 	GIT_SUBMODULE_STATUS_IN_HEAD           = (1u << 0),
76 	GIT_SUBMODULE_STATUS_IN_INDEX          = (1u << 1),
77 	GIT_SUBMODULE_STATUS_IN_CONFIG         = (1u << 2),
78 	GIT_SUBMODULE_STATUS_IN_WD             = (1u << 3),
79 	GIT_SUBMODULE_STATUS_INDEX_ADDED       = (1u << 4),
80 	GIT_SUBMODULE_STATUS_INDEX_DELETED     = (1u << 5),
81 	GIT_SUBMODULE_STATUS_INDEX_MODIFIED    = (1u << 6),
82 	GIT_SUBMODULE_STATUS_WD_UNINITIALIZED  = (1u << 7),
83 	GIT_SUBMODULE_STATUS_WD_ADDED          = (1u << 8),
84 	GIT_SUBMODULE_STATUS_WD_DELETED        = (1u << 9),
85 	GIT_SUBMODULE_STATUS_WD_MODIFIED       = (1u << 10),
86 	GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11),
87 	GIT_SUBMODULE_STATUS_WD_WD_MODIFIED    = (1u << 12),
88 	GIT_SUBMODULE_STATUS_WD_UNTRACKED      = (1u << 13),
89 } git_submodule_status_t;
90 
91 #define GIT_SUBMODULE_STATUS__IN_FLAGS		0x000Fu
92 #define GIT_SUBMODULE_STATUS__INDEX_FLAGS	0x0070u
93 #define GIT_SUBMODULE_STATUS__WD_FLAGS		0x3F80u
94 
95 #define GIT_SUBMODULE_STATUS_IS_UNMODIFIED(S) \
96 	(((S) & ~GIT_SUBMODULE_STATUS__IN_FLAGS) == 0)
97 
98 #define GIT_SUBMODULE_STATUS_IS_INDEX_UNMODIFIED(S) \
99 	(((S) & GIT_SUBMODULE_STATUS__INDEX_FLAGS) == 0)
100 
101 #define GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(S) \
102 	(((S) & (GIT_SUBMODULE_STATUS__WD_FLAGS & \
103 	~GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)) == 0)
104 
105 #define GIT_SUBMODULE_STATUS_IS_WD_DIRTY(S) \
106 	(((S) & (GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED | \
107 	GIT_SUBMODULE_STATUS_WD_WD_MODIFIED | \
108 	GIT_SUBMODULE_STATUS_WD_UNTRACKED)) != 0)
109 
110 /**
111  * Function pointer to receive each submodule
112  *
113  * @param sm git_submodule currently being visited
114  * @param name name of the submodule
115  * @param payload value you passed to the foreach function as payload
116  * @return 0 on success or error code
117  */
118 typedef int GIT_CALLBACK(git_submodule_cb)(
119 	git_submodule *sm, const char *name, void *payload);
120 
121 /**
122  * Submodule update options structure
123  *
124  * Initialize with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`. Alternatively, you can
125  * use `git_submodule_update_options_init`.
126  *
127  */
128 typedef struct git_submodule_update_options {
129 	unsigned int version;
130 
131 	/**
132 	 * These options are passed to the checkout step. To disable
133 	 * checkout, set the `checkout_strategy` to
134 	 * `GIT_CHECKOUT_NONE`. Generally you will want the use
135 	 * GIT_CHECKOUT_SAFE to update files in the working
136 	 * directory.
137 	 */
138 	git_checkout_options checkout_opts;
139 
140 	/**
141 	 * Options which control the fetch, including callbacks.
142 	 *
143 	 * The callbacks to use for reporting fetch progress, and for acquiring
144 	 * credentials in the event they are needed.
145 	 */
146 	git_fetch_options fetch_opts;
147 
148 	/**
149 	 * Allow fetching from the submodule's default remote if the target
150 	 * commit isn't found. Enabled by default.
151 	 */
152 	int allow_fetch;
153 } git_submodule_update_options;
154 
155 #define GIT_SUBMODULE_UPDATE_OPTIONS_VERSION 1
156 #define GIT_SUBMODULE_UPDATE_OPTIONS_INIT \
157 	{ GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, \
158 		{ GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
159 	GIT_FETCH_OPTIONS_INIT, 1 }
160 
161 /**
162  * Initialize git_submodule_update_options structure
163  *
164  * Initializes a `git_submodule_update_options` with default values. Equivalent to
165  * creating an instance with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`.
166  *
167  * @param opts The `git_submodule_update_options` struct to initialize.
168  * @param version The struct version; pass `GIT_SUBMODULE_UPDATE_OPTIONS_VERSION`.
169  * @return Zero on success; -1 on failure.
170  */
171 GIT_EXTERN(int) git_submodule_update_options_init(
172 	git_submodule_update_options *opts, unsigned int version);
173 
174 /**
175  * Update a submodule. This will clone a missing submodule and
176  * checkout the subrepository to the commit specified in the index of
177  * the containing repository. If the submodule repository doesn't contain
178  * the target commit (e.g. because fetchRecurseSubmodules isn't set), then
179  * the submodule is fetched using the fetch options supplied in options.
180  *
181  * @param submodule Submodule object
182  * @param init If the submodule is not initialized, setting this flag to true
183  *        will initialize the submodule before updating. Otherwise, this will
184  *        return an error if attempting to update an uninitialzed repository.
185  *        but setting this to true forces them to be updated.
186  * @param options configuration options for the update.  If NULL, the
187  *        function works as though GIT_SUBMODULE_UPDATE_OPTIONS_INIT was passed.
188  * @return 0 on success, any non-zero return value from a callback
189  *         function, or a negative value to indicate an error (use
190  *         `git_error_last` for a detailed error message).
191  */
192 GIT_EXTERN(int) git_submodule_update(git_submodule *submodule, int init, git_submodule_update_options *options);
193 
194 /**
195  * Lookup submodule information by name or path.
196  *
197  * Given either the submodule name or path (they are usually the same), this
198  * returns a structure describing the submodule.
199  *
200  * There are two expected error scenarios:
201  *
202  * - The submodule is not mentioned in the HEAD, the index, and the config,
203  *   but does "exist" in the working directory (i.e. there is a subdirectory
204  *   that appears to be a Git repository).  In this case, this function
205  *   returns GIT_EEXISTS to indicate a sub-repository exists but not in a
206  *   state where a git_submodule can be instantiated.
207  * - The submodule is not mentioned in the HEAD, index, or config and the
208  *   working directory doesn't contain a value git repo at that path.
209  *   There may or may not be anything else at that path, but nothing that
210  *   looks like a submodule.  In this case, this returns GIT_ENOTFOUND.
211  *
212  * You must call `git_submodule_free` when done with the submodule.
213  *
214  * @param out Output ptr to submodule; pass NULL to just get return code
215  * @param repo The parent repository
216  * @param name The name of or path to the submodule; trailing slashes okay
217  * @return 0 on success, GIT_ENOTFOUND if submodule does not exist,
218  *         GIT_EEXISTS if a repository is found in working directory only,
219  *         -1 on other errors.
220  */
221 GIT_EXTERN(int) git_submodule_lookup(
222 	git_submodule **out,
223 	git_repository *repo,
224 	const char *name);
225 
226 /**
227  * Release a submodule
228  *
229  * @param submodule Submodule object
230  */
231 GIT_EXTERN(void) git_submodule_free(git_submodule *submodule);
232 
233 /**
234  * Iterate over all tracked submodules of a repository.
235  *
236  * See the note on `git_submodule` above.  This iterates over the tracked
237  * submodules as described therein.
238  *
239  * If you are concerned about items in the working directory that look like
240  * submodules but are not tracked, the diff API will generate a diff record
241  * for workdir items that look like submodules but are not tracked, showing
242  * them as added in the workdir.  Also, the status API will treat the entire
243  * subdirectory of a contained git repo as a single GIT_STATUS_WT_NEW item.
244  *
245  * @param repo The repository
246  * @param callback Function to be called with the name of each submodule.
247  *        Return a non-zero value to terminate the iteration.
248  * @param payload Extra data to pass to callback
249  * @return 0 on success, -1 on error, or non-zero return value of callback
250  */
251 GIT_EXTERN(int) git_submodule_foreach(
252 	git_repository *repo,
253 	git_submodule_cb callback,
254 	void *payload);
255 
256 /**
257  * Set up a new git submodule for checkout.
258  *
259  * This does "git submodule add" up to the fetch and checkout of the
260  * submodule contents.  It preps a new submodule, creates an entry in
261  * .gitmodules and creates an empty initialized repository either at the
262  * given path in the working directory or in .git/modules with a gitlink
263  * from the working directory to the new repo.
264  *
265  * To fully emulate "git submodule add" call this function, then open the
266  * submodule repo and perform the clone step as needed (if you don't need
267  * anything custom see `git_submodule_add_clone()`). Lastly, call
268  * `git_submodule_add_finalize()` to wrap up adding the new submodule and
269  * .gitmodules to the index to be ready to commit.
270  *
271  * You must call `git_submodule_free` on the submodule object when done.
272  *
273  * @param out The newly created submodule ready to open for clone
274  * @param repo The repository in which you want to create the submodule
275  * @param url URL for the submodule's remote
276  * @param path Path at which the submodule should be created
277  * @param use_gitlink Should workdir contain a gitlink to the repo in
278  *        .git/modules vs. repo directly in workdir.
279  * @return 0 on success, GIT_EEXISTS if submodule already exists,
280  *         -1 on other errors.
281  */
282 GIT_EXTERN(int) git_submodule_add_setup(
283 	git_submodule **out,
284 	git_repository *repo,
285 	const char *url,
286 	const char *path,
287 	int use_gitlink);
288 
289 /**
290  * Perform the clone step for a newly created submodule.
291  *
292  * This performs the necessary `git_clone` to setup a newly-created submodule.
293  *
294  * @param out The newly created repository object. Optional.
295  * @param submodule The submodule currently waiting for its clone.
296  * @param opts The options to use.
297  *
298  * @return 0 on success, -1 on other errors (see git_clone).
299  */
300 GIT_EXTERN(int) git_submodule_clone(
301 	git_repository **out,
302 	git_submodule *submodule,
303 	const git_submodule_update_options *opts);
304 
305 /**
306  * Resolve the setup of a new git submodule.
307  *
308  * This should be called on a submodule once you have called add setup
309  * and done the clone of the submodule.  This adds the .gitmodules file
310  * and the newly cloned submodule to the index to be ready to be committed
311  * (but doesn't actually do the commit).
312  *
313  * @param submodule The submodule to finish adding.
314  */
315 GIT_EXTERN(int) git_submodule_add_finalize(git_submodule *submodule);
316 
317 /**
318  * Add current submodule HEAD commit to index of superproject.
319  *
320  * @param submodule The submodule to add to the index
321  * @param write_index Boolean if this should immediately write the index
322  *            file.  If you pass this as false, you will have to get the
323  *            git_index and explicitly call `git_index_write()` on it to
324  *            save the change.
325  * @return 0 on success, <0 on failure
326  */
327 GIT_EXTERN(int) git_submodule_add_to_index(
328 	git_submodule *submodule,
329 	int write_index);
330 
331 /**
332  * Get the containing repository for a submodule.
333  *
334  * This returns a pointer to the repository that contains the submodule.
335  * This is a just a reference to the repository that was passed to the
336  * original `git_submodule_lookup()` call, so if that repository has been
337  * freed, then this may be a dangling reference.
338  *
339  * @param submodule Pointer to submodule object
340  * @return Pointer to `git_repository`
341  */
342 GIT_EXTERN(git_repository *) git_submodule_owner(git_submodule *submodule);
343 
344 /**
345  * Get the name of submodule.
346  *
347  * @param submodule Pointer to submodule object
348  * @return Pointer to the submodule name
349  */
350 GIT_EXTERN(const char *) git_submodule_name(git_submodule *submodule);
351 
352 /**
353  * Get the path to the submodule.
354  *
355  * The path is almost always the same as the submodule name, but the
356  * two are actually not required to match.
357  *
358  * @param submodule Pointer to submodule object
359  * @return Pointer to the submodule path
360  */
361 GIT_EXTERN(const char *) git_submodule_path(git_submodule *submodule);
362 
363 /**
364  * Get the URL for the submodule.
365  *
366  * @param submodule Pointer to submodule object
367  * @return Pointer to the submodule url
368  */
369 GIT_EXTERN(const char *) git_submodule_url(git_submodule *submodule);
370 
371 /**
372  * Resolve a submodule url relative to the given repository.
373  *
374  * @param out buffer to store the absolute submodule url in
375  * @param repo Pointer to repository object
376  * @param url Relative url
377  * @return 0 or an error code
378  */
379 GIT_EXTERN(int) git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *url);
380 
381 /**
382 * Get the branch for the submodule.
383 *
384 * @param submodule Pointer to submodule object
385 * @return Pointer to the submodule branch
386 */
387 GIT_EXTERN(const char *) git_submodule_branch(git_submodule *submodule);
388 
389 /**
390  * Set the branch for the submodule in the configuration
391  *
392  * After calling this, you may wish to call `git_submodule_sync()` to
393  * write the changes to the checked out submodule repository.
394  *
395  * @param repo the repository to affect
396  * @param name the name of the submodule to configure
397  * @param branch Branch that should be used for the submodule
398  * @return 0 on success, <0 on failure
399  */
400 GIT_EXTERN(int) git_submodule_set_branch(git_repository *repo, const char *name, const char *branch);
401 
402 /**
403  * Set the URL for the submodule in the configuration
404  *
405  *
406  * After calling this, you may wish to call `git_submodule_sync()` to
407  * write the changes to the checked out submodule repository.
408  *
409  * @param repo the repository to affect
410  * @param name the name of the submodule to configure
411  * @param url URL that should be used for the submodule
412  * @return 0 on success, <0 on failure
413  */
414 GIT_EXTERN(int) git_submodule_set_url(git_repository *repo, const char *name, const char *url);
415 
416 /**
417  * Get the OID for the submodule in the index.
418  *
419  * @param submodule Pointer to submodule object
420  * @return Pointer to git_oid or NULL if submodule is not in index.
421  */
422 GIT_EXTERN(const git_oid *) git_submodule_index_id(git_submodule *submodule);
423 
424 /**
425  * Get the OID for the submodule in the current HEAD tree.
426  *
427  * @param submodule Pointer to submodule object
428  * @return Pointer to git_oid or NULL if submodule is not in the HEAD.
429  */
430 GIT_EXTERN(const git_oid *) git_submodule_head_id(git_submodule *submodule);
431 
432 /**
433  * Get the OID for the submodule in the current working directory.
434  *
435  * This returns the OID that corresponds to looking up 'HEAD' in the checked
436  * out submodule.  If there are pending changes in the index or anything
437  * else, this won't notice that.  You should call `git_submodule_status()`
438  * for a more complete picture about the state of the working directory.
439  *
440  * @param submodule Pointer to submodule object
441  * @return Pointer to git_oid or NULL if submodule is not checked out.
442  */
443 GIT_EXTERN(const git_oid *) git_submodule_wd_id(git_submodule *submodule);
444 
445 /**
446  * Get the ignore rule that will be used for the submodule.
447  *
448  * These values control the behavior of `git_submodule_status()` for this
449  * submodule.  There are four ignore values:
450  *
451  *  - **GIT_SUBMODULE_IGNORE_NONE** will consider any change to the contents
452  *    of the submodule from a clean checkout to be dirty, including the
453  *    addition of untracked files.  This is the default if unspecified.
454  *  - **GIT_SUBMODULE_IGNORE_UNTRACKED** examines the contents of the
455  *    working tree (i.e. call `git_status_foreach()` on the submodule) but
456  *    UNTRACKED files will not count as making the submodule dirty.
457  *  - **GIT_SUBMODULE_IGNORE_DIRTY** means to only check if the HEAD of the
458  *    submodule has moved for status.  This is fast since it does not need to
459  *    scan the working tree of the submodule at all.
460  *  - **GIT_SUBMODULE_IGNORE_ALL** means not to open the submodule repo.
461  *    The working directory will be consider clean so long as there is a
462  *    checked out version present.
463  *
464  * @param submodule The submodule to check
465  * @return The current git_submodule_ignore_t valyue what will be used for
466  *         this submodule.
467  */
468 GIT_EXTERN(git_submodule_ignore_t) git_submodule_ignore(
469 	git_submodule *submodule);
470 
471 /**
472  * Set the ignore rule for the submodule in the configuration
473  *
474  * This does not affect any currently-loaded instances.
475  *
476  * @param repo the repository to affect
477  * @param name the name of the submdule
478  * @param ignore The new value for the ignore rule
479  * @return 0 or an error code
480  */
481 GIT_EXTERN(int) git_submodule_set_ignore(
482 	git_repository *repo,
483 	const char *name,
484 	git_submodule_ignore_t ignore);
485 
486 /**
487  * Get the update rule that will be used for the submodule.
488  *
489  * This value controls the behavior of the `git submodule update` command.
490  * There are four useful values documented with `git_submodule_update_t`.
491  *
492  * @param submodule The submodule to check
493  * @return The current git_submodule_update_t value that will be used
494  *         for this submodule.
495  */
496 GIT_EXTERN(git_submodule_update_t) git_submodule_update_strategy(
497 	git_submodule *submodule);
498 
499 /**
500  * Set the update rule for the submodule in the configuration
501  *
502  * This setting won't affect any existing instances.
503  *
504  * @param repo the repository to affect
505  * @param name the name of the submodule to configure
506  * @param update The new value to use
507  * @return 0 or an error code
508  */
509 GIT_EXTERN(int) git_submodule_set_update(
510 	git_repository *repo,
511 	const char *name,
512 	git_submodule_update_t update);
513 
514 /**
515  * Read the fetchRecurseSubmodules rule for a submodule.
516  *
517  * This accesses the submodule.<name>.fetchRecurseSubmodules value for
518  * the submodule that controls fetching behavior for the submodule.
519  *
520  * Note that at this time, libgit2 does not honor this setting and the
521  * fetch functionality current ignores submodules.
522  *
523  * @return 0 if fetchRecurseSubmodules is false, 1 if true
524  */
525 GIT_EXTERN(git_submodule_recurse_t) git_submodule_fetch_recurse_submodules(
526 	git_submodule *submodule);
527 
528 /**
529  * Set the fetchRecurseSubmodules rule for a submodule in the configuration
530  *
531  * This setting won't affect any existing instances.
532  *
533  * @param repo the repository to affect
534  * @param name the submodule to configure
535  * @param fetch_recurse_submodules Boolean value
536  * @return old value for fetchRecurseSubmodules
537  */
538 GIT_EXTERN(int) git_submodule_set_fetch_recurse_submodules(
539 	git_repository *repo,
540 	const char *name,
541 	git_submodule_recurse_t fetch_recurse_submodules);
542 
543 /**
544  * Copy submodule info into ".git/config" file.
545  *
546  * Just like "git submodule init", this copies information about the
547  * submodule into ".git/config".  You can use the accessor functions
548  * above to alter the in-memory git_submodule object and control what
549  * is written to the config, overriding what is in .gitmodules.
550  *
551  * @param submodule The submodule to write into the superproject config
552  * @param overwrite By default, existing entries will not be overwritten,
553  *                  but setting this to true forces them to be updated.
554  * @return 0 on success, <0 on failure.
555  */
556 GIT_EXTERN(int) git_submodule_init(git_submodule *submodule, int overwrite);
557 
558 /**
559  * Set up the subrepository for a submodule in preparation for clone.
560  *
561  * This function can be called to init and set up a submodule
562  * repository from a submodule in preparation to clone it from
563  * its remote.
564  *
565  * @param out Output pointer to the created git repository.
566  * @param sm The submodule to create a new subrepository from.
567  * @param use_gitlink Should the workdir contain a gitlink to
568  *        the repo in .git/modules vs. repo directly in workdir.
569  * @return 0 on success, <0 on failure.
570  */
571 GIT_EXTERN(int) git_submodule_repo_init(
572 	git_repository **out,
573 	const git_submodule *sm,
574 	int use_gitlink);
575 
576 /**
577  * Copy submodule remote info into submodule repo.
578  *
579  * This copies the information about the submodules URL into the checked out
580  * submodule config, acting like "git submodule sync".  This is useful if
581  * you have altered the URL for the submodule (or it has been altered by a
582  * fetch of upstream changes) and you need to update your local repo.
583  */
584 GIT_EXTERN(int) git_submodule_sync(git_submodule *submodule);
585 
586 /**
587  * Open the repository for a submodule.
588  *
589  * This is a newly opened repository object.  The caller is responsible for
590  * calling `git_repository_free()` on it when done.  Multiple calls to this
591  * function will return distinct `git_repository` objects.  This will only
592  * work if the submodule is checked out into the working directory.
593  *
594  * @param repo Pointer to the submodule repo which was opened
595  * @param submodule Submodule to be opened
596  * @return 0 on success, <0 if submodule repo could not be opened.
597  */
598 GIT_EXTERN(int) git_submodule_open(
599 	git_repository **repo,
600 	git_submodule *submodule);
601 
602 /**
603  * Reread submodule info from config, index, and HEAD.
604  *
605  * Call this to reread cached submodule information for this submodule if
606  * you have reason to believe that it has changed.
607  *
608  * @param submodule The submodule to reload
609  * @param force Force reload even if the data doesn't seem out of date
610  * @return 0 on success, <0 on error
611  */
612 GIT_EXTERN(int) git_submodule_reload(git_submodule *submodule, int force);
613 
614 /**
615  * Get the status for a submodule.
616  *
617  * This looks at a submodule and tries to determine the status.  It
618  * will return a combination of the `GIT_SUBMODULE_STATUS` values above.
619  * How deeply it examines the working directory to do this will depend
620  * on the `git_submodule_ignore_t` value for the submodule.
621  *
622  * @param status Combination of `GIT_SUBMODULE_STATUS` flags
623  * @param repo the repository in which to look
624  * @param name name of the submodule
625  * @param ignore the ignore rules to follow
626  * @return 0 on success, <0 on error
627  */
628 GIT_EXTERN(int) git_submodule_status(
629 	unsigned int *status,
630 	git_repository *repo,
631 	const char *name,
632 	git_submodule_ignore_t ignore);
633 
634 /**
635  * Get the locations of submodule information.
636  *
637  * This is a bit like a very lightweight version of `git_submodule_status`.
638  * It just returns a made of the first four submodule status values (i.e.
639  * the ones like GIT_SUBMODULE_STATUS_IN_HEAD, etc) that tell you where the
640  * submodule data comes from (i.e. the HEAD commit, gitmodules file, etc.).
641  * This can be useful if you want to know if the submodule is present in the
642  * working directory at this point in time, etc.
643  *
644  * @param location_status Combination of first four `GIT_SUBMODULE_STATUS` flags
645  * @param submodule Submodule for which to get status
646  * @return 0 on success, <0 on error
647  */
648 GIT_EXTERN(int) git_submodule_location(
649 	unsigned int *location_status,
650 	git_submodule *submodule);
651 
652 /** @} */
653 GIT_END_DECL
654 #endif
655