Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:39

0001 /*
0002  * Copyright (C) the libgit2 contributors. All rights reserved.
0003  *
0004  * This file is part of libgit2, distributed under the GNU GPL v2 with
0005  * a Linking Exception. For full terms see the included COPYING file.
0006  */
0007 #ifndef INCLUDE_git_submodule_h__
0008 #define INCLUDE_git_submodule_h__
0009 
0010 #include "common.h"
0011 #include "types.h"
0012 #include "oid.h"
0013 #include "remote.h"
0014 #include "checkout.h"
0015 
0016 /**
0017  * @file git2/submodule.h
0018  * @brief Git submodule management utilities
0019  *
0020  * Submodule support in libgit2 builds a list of known submodules and keeps
0021  * it in the repository.  The list is built from the .gitmodules file, the
0022  * .git/config file, the index, and the HEAD tree.  Items in the working
0023  * directory that look like submodules (i.e. a git repo) but are not
0024  * mentioned in those places won't be tracked.
0025  *
0026  * @defgroup git_submodule Git submodule management routines
0027  * @ingroup Git
0028  * @{
0029  */
0030 GIT_BEGIN_DECL
0031 
0032 /**
0033  * Return codes for submodule status.
0034  *
0035  * A combination of these flags will be returned to describe the status of a
0036  * submodule.  Depending on the "ignore" property of the submodule, some of
0037  * the flags may never be returned because they indicate changes that are
0038  * supposed to be ignored.
0039  *
0040  * Submodule info is contained in 4 places: the HEAD tree, the index, config
0041  * files (both .git/config and .gitmodules), and the working directory.  Any
0042  * or all of those places might be missing information about the submodule
0043  * depending on what state the repo is in.  We consider all four places to
0044  * build the combination of status flags.
0045  *
0046  * There are four values that are not really status, but give basic info
0047  * about what sources of submodule data are available.  These will be
0048  * returned even if ignore is set to "ALL".
0049  *
0050  * * IN_HEAD   - superproject head contains submodule
0051  * * IN_INDEX  - superproject index contains submodule
0052  * * IN_CONFIG - superproject gitmodules has submodule
0053  * * IN_WD     - superproject workdir has submodule
0054  *
0055  * The following values will be returned so long as ignore is not "ALL".
0056  *
0057  * * INDEX_ADDED       - in index, not in head
0058  * * INDEX_DELETED     - in head, not in index
0059  * * INDEX_MODIFIED    - index and head don't match
0060  * * WD_UNINITIALIZED  - workdir contains empty directory
0061  * * WD_ADDED          - in workdir, not index
0062  * * WD_DELETED        - in index, not workdir
0063  * * WD_MODIFIED       - index and workdir head don't match
0064  *
0065  * The following can only be returned if ignore is "NONE" or "UNTRACKED".
0066  *
0067  * * WD_INDEX_MODIFIED - submodule workdir index is dirty
0068  * * WD_WD_MODIFIED    - submodule workdir has modified files
0069  *
0070  * Lastly, the following will only be returned for ignore "NONE".
0071  *
0072  * * WD_UNTRACKED      - wd contains untracked files
0073  */
0074 typedef enum {
0075     GIT_SUBMODULE_STATUS_IN_HEAD           = (1u << 0),
0076     GIT_SUBMODULE_STATUS_IN_INDEX          = (1u << 1),
0077     GIT_SUBMODULE_STATUS_IN_CONFIG         = (1u << 2),
0078     GIT_SUBMODULE_STATUS_IN_WD             = (1u << 3),
0079     GIT_SUBMODULE_STATUS_INDEX_ADDED       = (1u << 4),
0080     GIT_SUBMODULE_STATUS_INDEX_DELETED     = (1u << 5),
0081     GIT_SUBMODULE_STATUS_INDEX_MODIFIED    = (1u << 6),
0082     GIT_SUBMODULE_STATUS_WD_UNINITIALIZED  = (1u << 7),
0083     GIT_SUBMODULE_STATUS_WD_ADDED          = (1u << 8),
0084     GIT_SUBMODULE_STATUS_WD_DELETED        = (1u << 9),
0085     GIT_SUBMODULE_STATUS_WD_MODIFIED       = (1u << 10),
0086     GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11),
0087     GIT_SUBMODULE_STATUS_WD_WD_MODIFIED    = (1u << 12),
0088     GIT_SUBMODULE_STATUS_WD_UNTRACKED      = (1u << 13)
0089 } git_submodule_status_t;
0090 
0091 #define GIT_SUBMODULE_STATUS__IN_FLAGS      0x000Fu
0092 #define GIT_SUBMODULE_STATUS__INDEX_FLAGS   0x0070u
0093 #define GIT_SUBMODULE_STATUS__WD_FLAGS      0x3F80u
0094 
0095 #define GIT_SUBMODULE_STATUS_IS_UNMODIFIED(S) \
0096     (((S) & ~GIT_SUBMODULE_STATUS__IN_FLAGS) == 0)
0097 
0098 #define GIT_SUBMODULE_STATUS_IS_INDEX_UNMODIFIED(S) \
0099     (((S) & GIT_SUBMODULE_STATUS__INDEX_FLAGS) == 0)
0100 
0101 #define GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(S) \
0102     (((S) & (GIT_SUBMODULE_STATUS__WD_FLAGS & \
0103     ~GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)) == 0)
0104 
0105 #define GIT_SUBMODULE_STATUS_IS_WD_DIRTY(S) \
0106     (((S) & (GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED | \
0107     GIT_SUBMODULE_STATUS_WD_WD_MODIFIED | \
0108     GIT_SUBMODULE_STATUS_WD_UNTRACKED)) != 0)
0109 
0110 /**
0111  * Function pointer to receive each submodule
0112  *
0113  * @param sm git_submodule currently being visited
0114  * @param name name of the submodule
0115  * @param payload value you passed to the foreach function as payload
0116  * @return 0 on success or error code
0117  */
0118 typedef int GIT_CALLBACK(git_submodule_cb)(
0119     git_submodule *sm, const char *name, void *payload);
0120 
0121 /**
0122  * Submodule update options structure
0123  *
0124  * Initialize with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`. Alternatively, you can
0125  * use `git_submodule_update_options_init`.
0126  *
0127  */
0128 typedef struct git_submodule_update_options {
0129     unsigned int version;
0130 
0131     /**
0132      * These options are passed to the checkout step. To disable
0133      * checkout, set the `checkout_strategy` to
0134      * `GIT_CHECKOUT_NONE`. Generally you will want the use
0135      * GIT_CHECKOUT_SAFE to update files in the working
0136      * directory.
0137      */
0138     git_checkout_options checkout_opts;
0139 
0140     /**
0141      * Options which control the fetch, including callbacks.
0142      *
0143      * The callbacks to use for reporting fetch progress, and for acquiring
0144      * credentials in the event they are needed.
0145      */
0146     git_fetch_options fetch_opts;
0147 
0148     /**
0149      * Allow fetching from the submodule's default remote if the target
0150      * commit isn't found. Enabled by default.
0151      */
0152     int allow_fetch;
0153 } git_submodule_update_options;
0154 
0155 #define GIT_SUBMODULE_UPDATE_OPTIONS_VERSION 1
0156 #define GIT_SUBMODULE_UPDATE_OPTIONS_INIT \
0157     { GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, \
0158         { GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
0159     GIT_FETCH_OPTIONS_INIT, 1 }
0160 
0161 /**
0162  * Initialize git_submodule_update_options structure
0163  *
0164  * Initializes a `git_submodule_update_options` with default values. Equivalent to
0165  * creating an instance with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`.
0166  *
0167  * @param opts The `git_submodule_update_options` struct to initialize.
0168  * @param version The struct version; pass `GIT_SUBMODULE_UPDATE_OPTIONS_VERSION`.
0169  * @return Zero on success; -1 on failure.
0170  */
0171 GIT_EXTERN(int) git_submodule_update_options_init(
0172     git_submodule_update_options *opts, unsigned int version);
0173 
0174 /**
0175  * Update a submodule. This will clone a missing submodule and
0176  * checkout the subrepository to the commit specified in the index of
0177  * the containing repository. If the submodule repository doesn't contain
0178  * the target commit (e.g. because fetchRecurseSubmodules isn't set), then
0179  * the submodule is fetched using the fetch options supplied in options.
0180  *
0181  * @param submodule Submodule object
0182  * @param init If the submodule is not initialized, setting this flag to true
0183  *        will initialize the submodule before updating. Otherwise, this will
0184  *        return an error if attempting to update an uninitialized repository.
0185  *        but setting this to true forces them to be updated.
0186  * @param options configuration options for the update.  If NULL, the
0187  *        function works as though GIT_SUBMODULE_UPDATE_OPTIONS_INIT was passed.
0188  * @return 0 on success, any non-zero return value from a callback
0189  *         function, or a negative value to indicate an error (use
0190  *         `git_error_last` for a detailed error message).
0191  */
0192 GIT_EXTERN(int) git_submodule_update(git_submodule *submodule, int init, git_submodule_update_options *options);
0193 
0194 /**
0195  * Lookup submodule information by name or path.
0196  *
0197  * Given either the submodule name or path (they are usually the same), this
0198  * returns a structure describing the submodule.
0199  *
0200  * There are two expected error scenarios:
0201  *
0202  * - The submodule is not mentioned in the HEAD, the index, and the config,
0203  *   but does "exist" in the working directory (i.e. there is a subdirectory
0204  *   that appears to be a Git repository).  In this case, this function
0205  *   returns GIT_EEXISTS to indicate a sub-repository exists but not in a
0206  *   state where a git_submodule can be instantiated.
0207  * - The submodule is not mentioned in the HEAD, index, or config and the
0208  *   working directory doesn't contain a value git repo at that path.
0209  *   There may or may not be anything else at that path, but nothing that
0210  *   looks like a submodule.  In this case, this returns GIT_ENOTFOUND.
0211  *
0212  * You must call `git_submodule_free` when done with the submodule.
0213  *
0214  * @param out Output ptr to submodule; pass NULL to just get return code
0215  * @param repo The parent repository
0216  * @param name The name of or path to the submodule; trailing slashes okay
0217  * @return 0 on success, GIT_ENOTFOUND if submodule does not exist,
0218  *         GIT_EEXISTS if a repository is found in working directory only,
0219  *         -1 on other errors.
0220  */
0221 GIT_EXTERN(int) git_submodule_lookup(
0222     git_submodule **out,
0223     git_repository *repo,
0224     const char *name);
0225 
0226 /**
0227  * Create an in-memory copy of a submodule. The copy must be explicitly
0228  * free'd or it will leak.
0229  *
0230  * @param out Pointer to store the copy of the submodule.
0231  * @param source Original submodule to copy.
0232  * @return 0
0233  */
0234 GIT_EXTERN(int) git_submodule_dup(git_submodule **out, git_submodule *source);
0235 
0236 /**
0237  * Release a submodule
0238  *
0239  * @param submodule Submodule object
0240  */
0241 GIT_EXTERN(void) git_submodule_free(git_submodule *submodule);
0242 
0243 /**
0244  * Iterate over all tracked submodules of a repository.
0245  *
0246  * See the note on `git_submodule` above.  This iterates over the tracked
0247  * submodules as described therein.
0248  *
0249  * If you are concerned about items in the working directory that look like
0250  * submodules but are not tracked, the diff API will generate a diff record
0251  * for workdir items that look like submodules but are not tracked, showing
0252  * them as added in the workdir.  Also, the status API will treat the entire
0253  * subdirectory of a contained git repo as a single GIT_STATUS_WT_NEW item.
0254  *
0255  * @param repo The repository
0256  * @param callback Function to be called with the name of each submodule.
0257  *        Return a non-zero value to terminate the iteration.
0258  * @param payload Extra data to pass to callback
0259  * @return 0 on success, -1 on error, or non-zero return value of callback
0260  */
0261 GIT_EXTERN(int) git_submodule_foreach(
0262     git_repository *repo,
0263     git_submodule_cb callback,
0264     void *payload);
0265 
0266 /**
0267  * Set up a new git submodule for checkout.
0268  *
0269  * This does "git submodule add" up to the fetch and checkout of the
0270  * submodule contents.  It preps a new submodule, creates an entry in
0271  * .gitmodules and creates an empty initialized repository either at the
0272  * given path in the working directory or in .git/modules with a gitlink
0273  * from the working directory to the new repo.
0274  *
0275  * To fully emulate "git submodule add" call this function, then open the
0276  * submodule repo and perform the clone step as needed (if you don't need
0277  * anything custom see `git_submodule_add_clone()`). Lastly, call
0278  * `git_submodule_add_finalize()` to wrap up adding the new submodule and
0279  * .gitmodules to the index to be ready to commit.
0280  *
0281  * You must call `git_submodule_free` on the submodule object when done.
0282  *
0283  * @param out The newly created submodule ready to open for clone
0284  * @param repo The repository in which you want to create the submodule
0285  * @param url URL for the submodule's remote
0286  * @param path Path at which the submodule should be created
0287  * @param use_gitlink Should workdir contain a gitlink to the repo in
0288  *        .git/modules vs. repo directly in workdir.
0289  * @return 0 on success, GIT_EEXISTS if submodule already exists,
0290  *         -1 on other errors.
0291  */
0292 GIT_EXTERN(int) git_submodule_add_setup(
0293     git_submodule **out,
0294     git_repository *repo,
0295     const char *url,
0296     const char *path,
0297     int use_gitlink);
0298 
0299 /**
0300  * Perform the clone step for a newly created submodule.
0301  *
0302  * This performs the necessary `git_clone` to setup a newly-created submodule.
0303  *
0304  * @param out The newly created repository object. Optional.
0305  * @param submodule The submodule currently waiting for its clone.
0306  * @param opts The options to use.
0307  *
0308  * @return 0 on success, -1 on other errors (see git_clone).
0309  */
0310 GIT_EXTERN(int) git_submodule_clone(
0311     git_repository **out,
0312     git_submodule *submodule,
0313     const git_submodule_update_options *opts);
0314 
0315 /**
0316  * Resolve the setup of a new git submodule.
0317  *
0318  * This should be called on a submodule once you have called add setup
0319  * and done the clone of the submodule.  This adds the .gitmodules file
0320  * and the newly cloned submodule to the index to be ready to be committed
0321  * (but doesn't actually do the commit).
0322  *
0323  * @param submodule The submodule to finish adding.
0324  * @return 0 or an error code.
0325  */
0326 GIT_EXTERN(int) git_submodule_add_finalize(git_submodule *submodule);
0327 
0328 /**
0329  * Add current submodule HEAD commit to index of superproject.
0330  *
0331  * @param submodule The submodule to add to the index
0332  * @param write_index Boolean if this should immediately write the index
0333  *            file.  If you pass this as false, you will have to get the
0334  *            git_index and explicitly call `git_index_write()` on it to
0335  *            save the change.
0336  * @return 0 on success, <0 on failure
0337  */
0338 GIT_EXTERN(int) git_submodule_add_to_index(
0339     git_submodule *submodule,
0340     int write_index);
0341 
0342 /**
0343  * Get the containing repository for a submodule.
0344  *
0345  * This returns a pointer to the repository that contains the submodule.
0346  * This is a just a reference to the repository that was passed to the
0347  * original `git_submodule_lookup()` call, so if that repository has been
0348  * freed, then this may be a dangling reference.
0349  *
0350  * @param submodule Pointer to submodule object
0351  * @return Pointer to `git_repository`
0352  */
0353 GIT_EXTERN(git_repository *) git_submodule_owner(git_submodule *submodule);
0354 
0355 /**
0356  * Get the name of submodule.
0357  *
0358  * @param submodule Pointer to submodule object
0359  * @return Pointer to the submodule name
0360  */
0361 GIT_EXTERN(const char *) git_submodule_name(git_submodule *submodule);
0362 
0363 /**
0364  * Get the path to the submodule.
0365  *
0366  * The path is almost always the same as the submodule name, but the
0367  * two are actually not required to match.
0368  *
0369  * @param submodule Pointer to submodule object
0370  * @return Pointer to the submodule path
0371  */
0372 GIT_EXTERN(const char *) git_submodule_path(git_submodule *submodule);
0373 
0374 /**
0375  * Get the URL for the submodule.
0376  *
0377  * @param submodule Pointer to submodule object
0378  * @return Pointer to the submodule url
0379  */
0380 GIT_EXTERN(const char *) git_submodule_url(git_submodule *submodule);
0381 
0382 /**
0383  * Resolve a submodule url relative to the given repository.
0384  *
0385  * @param out buffer to store the absolute submodule url in
0386  * @param repo Pointer to repository object
0387  * @param url Relative url
0388  * @return 0 or an error code
0389  */
0390 GIT_EXTERN(int) git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *url);
0391 
0392 /**
0393 * Get the branch for the submodule.
0394 *
0395 * @param submodule Pointer to submodule object
0396 * @return Pointer to the submodule branch
0397 */
0398 GIT_EXTERN(const char *) git_submodule_branch(git_submodule *submodule);
0399 
0400 /**
0401  * Set the branch for the submodule in the configuration
0402  *
0403  * After calling this, you may wish to call `git_submodule_sync()` to
0404  * write the changes to the checked out submodule repository.
0405  *
0406  * @param repo the repository to affect
0407  * @param name the name of the submodule to configure
0408  * @param branch Branch that should be used for the submodule
0409  * @return 0 on success, <0 on failure
0410  */
0411 GIT_EXTERN(int) git_submodule_set_branch(git_repository *repo, const char *name, const char *branch);
0412 
0413 /**
0414  * Set the URL for the submodule in the configuration
0415  *
0416  *
0417  * After calling this, you may wish to call `git_submodule_sync()` to
0418  * write the changes to the checked out submodule repository.
0419  *
0420  * @param repo the repository to affect
0421  * @param name the name of the submodule to configure
0422  * @param url URL that should be used for the submodule
0423  * @return 0 on success, <0 on failure
0424  */
0425 GIT_EXTERN(int) git_submodule_set_url(git_repository *repo, const char *name, const char *url);
0426 
0427 /**
0428  * Get the OID for the submodule in the index.
0429  *
0430  * @param submodule Pointer to submodule object
0431  * @return Pointer to git_oid or NULL if submodule is not in index.
0432  */
0433 GIT_EXTERN(const git_oid *) git_submodule_index_id(git_submodule *submodule);
0434 
0435 /**
0436  * Get the OID for the submodule in the current HEAD tree.
0437  *
0438  * @param submodule Pointer to submodule object
0439  * @return Pointer to git_oid or NULL if submodule is not in the HEAD.
0440  */
0441 GIT_EXTERN(const git_oid *) git_submodule_head_id(git_submodule *submodule);
0442 
0443 /**
0444  * Get the OID for the submodule in the current working directory.
0445  *
0446  * This returns the OID that corresponds to looking up 'HEAD' in the checked
0447  * out submodule.  If there are pending changes in the index or anything
0448  * else, this won't notice that.  You should call `git_submodule_status()`
0449  * for a more complete picture about the state of the working directory.
0450  *
0451  * @param submodule Pointer to submodule object
0452  * @return Pointer to git_oid or NULL if submodule is not checked out.
0453  */
0454 GIT_EXTERN(const git_oid *) git_submodule_wd_id(git_submodule *submodule);
0455 
0456 /**
0457  * Get the ignore rule that will be used for the submodule.
0458  *
0459  * These values control the behavior of `git_submodule_status()` for this
0460  * submodule.  There are four ignore values:
0461  *
0462  *  - **GIT_SUBMODULE_IGNORE_NONE** will consider any change to the contents
0463  *    of the submodule from a clean checkout to be dirty, including the
0464  *    addition of untracked files.  This is the default if unspecified.
0465  *  - **GIT_SUBMODULE_IGNORE_UNTRACKED** examines the contents of the
0466  *    working tree (i.e. call `git_status_foreach()` on the submodule) but
0467  *    UNTRACKED files will not count as making the submodule dirty.
0468  *  - **GIT_SUBMODULE_IGNORE_DIRTY** means to only check if the HEAD of the
0469  *    submodule has moved for status.  This is fast since it does not need to
0470  *    scan the working tree of the submodule at all.
0471  *  - **GIT_SUBMODULE_IGNORE_ALL** means not to open the submodule repo.
0472  *    The working directory will be consider clean so long as there is a
0473  *    checked out version present.
0474  *
0475  * @param submodule The submodule to check
0476  * @return The current git_submodule_ignore_t valyue what will be used for
0477  *         this submodule.
0478  */
0479 GIT_EXTERN(git_submodule_ignore_t) git_submodule_ignore(
0480     git_submodule *submodule);
0481 
0482 /**
0483  * Set the ignore rule for the submodule in the configuration
0484  *
0485  * This does not affect any currently-loaded instances.
0486  *
0487  * @param repo the repository to affect
0488  * @param name the name of the submdule
0489  * @param ignore The new value for the ignore rule
0490  * @return 0 or an error code
0491  */
0492 GIT_EXTERN(int) git_submodule_set_ignore(
0493     git_repository *repo,
0494     const char *name,
0495     git_submodule_ignore_t ignore);
0496 
0497 /**
0498  * Get the update rule that will be used for the submodule.
0499  *
0500  * This value controls the behavior of the `git submodule update` command.
0501  * There are four useful values documented with `git_submodule_update_t`.
0502  *
0503  * @param submodule The submodule to check
0504  * @return The current git_submodule_update_t value that will be used
0505  *         for this submodule.
0506  */
0507 GIT_EXTERN(git_submodule_update_t) git_submodule_update_strategy(
0508     git_submodule *submodule);
0509 
0510 /**
0511  * Set the update rule for the submodule in the configuration
0512  *
0513  * This setting won't affect any existing instances.
0514  *
0515  * @param repo the repository to affect
0516  * @param name the name of the submodule to configure
0517  * @param update The new value to use
0518  * @return 0 or an error code
0519  */
0520 GIT_EXTERN(int) git_submodule_set_update(
0521     git_repository *repo,
0522     const char *name,
0523     git_submodule_update_t update);
0524 
0525 /**
0526  * Read the fetchRecurseSubmodules rule for a submodule.
0527  *
0528  * This accesses the submodule.<name>.fetchRecurseSubmodules value for
0529  * the submodule that controls fetching behavior for the submodule.
0530  *
0531  * Note that at this time, libgit2 does not honor this setting and the
0532  * fetch functionality current ignores submodules.
0533  *
0534  * @return 0 if fetchRecurseSubmodules is false, 1 if true
0535  */
0536 GIT_EXTERN(git_submodule_recurse_t) git_submodule_fetch_recurse_submodules(
0537     git_submodule *submodule);
0538 
0539 /**
0540  * Set the fetchRecurseSubmodules rule for a submodule in the configuration
0541  *
0542  * This setting won't affect any existing instances.
0543  *
0544  * @param repo the repository to affect
0545  * @param name the submodule to configure
0546  * @param fetch_recurse_submodules Boolean value
0547  * @return old value for fetchRecurseSubmodules
0548  */
0549 GIT_EXTERN(int) git_submodule_set_fetch_recurse_submodules(
0550     git_repository *repo,
0551     const char *name,
0552     git_submodule_recurse_t fetch_recurse_submodules);
0553 
0554 /**
0555  * Copy submodule info into ".git/config" file.
0556  *
0557  * Just like "git submodule init", this copies information about the
0558  * submodule into ".git/config".  You can use the accessor functions
0559  * above to alter the in-memory git_submodule object and control what
0560  * is written to the config, overriding what is in .gitmodules.
0561  *
0562  * @param submodule The submodule to write into the superproject config
0563  * @param overwrite By default, existing entries will not be overwritten,
0564  *                  but setting this to true forces them to be updated.
0565  * @return 0 on success, <0 on failure.
0566  */
0567 GIT_EXTERN(int) git_submodule_init(git_submodule *submodule, int overwrite);
0568 
0569 /**
0570  * Set up the subrepository for a submodule in preparation for clone.
0571  *
0572  * This function can be called to init and set up a submodule
0573  * repository from a submodule in preparation to clone it from
0574  * its remote.
0575  *
0576  * @param out Output pointer to the created git repository.
0577  * @param sm The submodule to create a new subrepository from.
0578  * @param use_gitlink Should the workdir contain a gitlink to
0579  *        the repo in .git/modules vs. repo directly in workdir.
0580  * @return 0 on success, <0 on failure.
0581  */
0582 GIT_EXTERN(int) git_submodule_repo_init(
0583     git_repository **out,
0584     const git_submodule *sm,
0585     int use_gitlink);
0586 
0587 /**
0588  * Copy submodule remote info into submodule repo.
0589  *
0590  * This copies the information about the submodules URL into the checked out
0591  * submodule config, acting like "git submodule sync".  This is useful if
0592  * you have altered the URL for the submodule (or it has been altered by a
0593  * fetch of upstream changes) and you need to update your local repo.
0594  *
0595  * @param submodule The submodule to copy.
0596  * @return 0 or an error code.
0597  */
0598 GIT_EXTERN(int) git_submodule_sync(git_submodule *submodule);
0599 
0600 /**
0601  * Open the repository for a submodule.
0602  *
0603  * This is a newly opened repository object.  The caller is responsible for
0604  * calling `git_repository_free()` on it when done.  Multiple calls to this
0605  * function will return distinct `git_repository` objects.  This will only
0606  * work if the submodule is checked out into the working directory.
0607  *
0608  * @param repo Pointer to the submodule repo which was opened
0609  * @param submodule Submodule to be opened
0610  * @return 0 on success, <0 if submodule repo could not be opened.
0611  */
0612 GIT_EXTERN(int) git_submodule_open(
0613     git_repository **repo,
0614     git_submodule *submodule);
0615 
0616 /**
0617  * Reread submodule info from config, index, and HEAD.
0618  *
0619  * Call this to reread cached submodule information for this submodule if
0620  * you have reason to believe that it has changed.
0621  *
0622  * @param submodule The submodule to reload
0623  * @param force Force reload even if the data doesn't seem out of date
0624  * @return 0 on success, <0 on error
0625  */
0626 GIT_EXTERN(int) git_submodule_reload(git_submodule *submodule, int force);
0627 
0628 /**
0629  * Get the status for a submodule.
0630  *
0631  * This looks at a submodule and tries to determine the status.  It
0632  * will return a combination of the `GIT_SUBMODULE_STATUS` values above.
0633  * How deeply it examines the working directory to do this will depend
0634  * on the `git_submodule_ignore_t` value for the submodule.
0635  *
0636  * @param status Combination of `GIT_SUBMODULE_STATUS` flags
0637  * @param repo the repository in which to look
0638  * @param name name of the submodule
0639  * @param ignore the ignore rules to follow
0640  * @return 0 on success, <0 on error
0641  */
0642 GIT_EXTERN(int) git_submodule_status(
0643     unsigned int *status,
0644     git_repository *repo,
0645     const char *name,
0646     git_submodule_ignore_t ignore);
0647 
0648 /**
0649  * Get the locations of submodule information.
0650  *
0651  * This is a bit like a very lightweight version of `git_submodule_status`.
0652  * It just returns a made of the first four submodule status values (i.e.
0653  * the ones like GIT_SUBMODULE_STATUS_IN_HEAD, etc) that tell you where the
0654  * submodule data comes from (i.e. the HEAD commit, gitmodules file, etc.).
0655  * This can be useful if you want to know if the submodule is present in the
0656  * working directory at this point in time, etc.
0657  *
0658  * @param location_status Combination of first four `GIT_SUBMODULE_STATUS` flags
0659  * @param submodule Submodule for which to get status
0660  * @return 0 on success, <0 on error
0661  */
0662 GIT_EXTERN(int) git_submodule_location(
0663     unsigned int *location_status,
0664     git_submodule *submodule);
0665 
0666 /** @} */
0667 GIT_END_DECL
0668 #endif