Blame include/git2/submodule.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_git_submodule_h__
Packit Service 20376f
#define INCLUDE_git_submodule_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
#include "oid.h"
Packit Service 20376f
#include "remote.h"
Packit Service 20376f
#include "checkout.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/submodule.h
Packit Service 20376f
 * @brief Git submodule management utilities
Packit Service 20376f
 *
Packit Service 20376f
 * Submodule support in libgit2 builds a list of known submodules and keeps
Packit Service 20376f
 * it in the repository.  The list is built from the .gitmodules file, the
Packit Service 20376f
 * .git/config file, the index, and the HEAD tree.  Items in the working
Packit Service 20376f
 * directory that look like submodules (i.e. a git repo) but are not
Packit Service 20376f
 * mentioned in those places won't be tracked.
Packit Service 20376f
 *
Packit Service 20376f
 * @defgroup git_submodule Git submodule management routines
Packit Service 20376f
 * @ingroup Git
Packit Service 20376f
 * @{
Packit Service 20376f
 */
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Return codes for submodule status.
Packit Service 20376f
 *
Packit Service 20376f
 * A combination of these flags will be returned to describe the status of a
Packit Service 20376f
 * submodule.  Depending on the "ignore" property of the submodule, some of
Packit Service 20376f
 * the flags may never be returned because they indicate changes that are
Packit Service 20376f
 * supposed to be ignored.
Packit Service 20376f
 *
Packit Service 20376f
 * Submodule info is contained in 4 places: the HEAD tree, the index, config
Packit Service 20376f
 * files (both .git/config and .gitmodules), and the working directory.  Any
Packit Service 20376f
 * or all of those places might be missing information about the submodule
Packit Service 20376f
 * depending on what state the repo is in.  We consider all four places to
Packit Service 20376f
 * build the combination of status flags.
Packit Service 20376f
 *
Packit Service 20376f
 * There are four values that are not really status, but give basic info
Packit Service 20376f
 * about what sources of submodule data are available.  These will be
Packit Service 20376f
 * returned even if ignore is set to "ALL".
Packit Service 20376f
 *
Packit Service 20376f
 * * IN_HEAD   - superproject head contains submodule
Packit Service 20376f
 * * IN_INDEX  - superproject index contains submodule
Packit Service 20376f
 * * IN_CONFIG - superproject gitmodules has submodule
Packit Service 20376f
 * * IN_WD     - superproject workdir has submodule
Packit Service 20376f
 *
Packit Service 20376f
 * The following values will be returned so long as ignore is not "ALL".
Packit Service 20376f
 *
Packit Service 20376f
 * * INDEX_ADDED       - in index, not in head
Packit Service 20376f
 * * INDEX_DELETED     - in head, not in index
Packit Service 20376f
 * * INDEX_MODIFIED    - index and head don't match
Packit Service 20376f
 * * WD_UNINITIALIZED  - workdir contains empty directory
Packit Service 20376f
 * * WD_ADDED          - in workdir, not index
Packit Service 20376f
 * * WD_DELETED        - in index, not workdir
Packit Service 20376f
 * * WD_MODIFIED       - index and workdir head don't match
Packit Service 20376f
 *
Packit Service 20376f
 * The following can only be returned if ignore is "NONE" or "UNTRACKED".
Packit Service 20376f
 *
Packit Service 20376f
 * * WD_INDEX_MODIFIED - submodule workdir index is dirty
Packit Service 20376f
 * * WD_WD_MODIFIED    - submodule workdir has modified files
Packit Service 20376f
 *
Packit Service 20376f
 * Lastly, the following will only be returned for ignore "NONE".
Packit Service 20376f
 *
Packit Service 20376f
 * * WD_UNTRACKED      - wd contains untracked files
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	GIT_SUBMODULE_STATUS_IN_HEAD           = (1u << 0),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_IN_INDEX          = (1u << 1),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_IN_CONFIG         = (1u << 2),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_IN_WD             = (1u << 3),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_INDEX_ADDED       = (1u << 4),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_INDEX_DELETED     = (1u << 5),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_INDEX_MODIFIED    = (1u << 6),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_WD_UNINITIALIZED  = (1u << 7),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_WD_ADDED          = (1u << 8),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_WD_DELETED        = (1u << 9),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_WD_MODIFIED       = (1u << 10),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_WD_WD_MODIFIED    = (1u << 12),
Packit Service 20376f
	GIT_SUBMODULE_STATUS_WD_UNTRACKED      = (1u << 13),
Packit Service 20376f
} git_submodule_status_t;
Packit Service 20376f
Packit Service 20376f
#define GIT_SUBMODULE_STATUS__IN_FLAGS		0x000Fu
Packit Service 20376f
#define GIT_SUBMODULE_STATUS__INDEX_FLAGS	0x0070u
Packit Service 20376f
#define GIT_SUBMODULE_STATUS__WD_FLAGS		0x3F80u
Packit Service 20376f
Packit Service 20376f
#define GIT_SUBMODULE_STATUS_IS_UNMODIFIED(S) \
Packit Service 20376f
	(((S) & ~GIT_SUBMODULE_STATUS__IN_FLAGS) == 0)
Packit Service 20376f
Packit Service 20376f
#define GIT_SUBMODULE_STATUS_IS_INDEX_UNMODIFIED(S) \
Packit Service 20376f
	(((S) & GIT_SUBMODULE_STATUS__INDEX_FLAGS) == 0)
Packit Service 20376f
Packit Service 20376f
#define GIT_SUBMODULE_STATUS_IS_WD_UNMODIFIED(S) \
Packit Service 20376f
	(((S) & (GIT_SUBMODULE_STATUS__WD_FLAGS & \
Packit Service 20376f
	~GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)) == 0)
Packit Service 20376f
Packit Service 20376f
#define GIT_SUBMODULE_STATUS_IS_WD_DIRTY(S) \
Packit Service 20376f
	(((S) & (GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED | \
Packit Service 20376f
	GIT_SUBMODULE_STATUS_WD_WD_MODIFIED | \
Packit Service 20376f
	GIT_SUBMODULE_STATUS_WD_UNTRACKED)) != 0)
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Function pointer to receive each submodule
Packit Service 20376f
 *
Packit Service 20376f
 * @param sm git_submodule currently being visited
Packit Service 20376f
 * @param name name of the submodule
Packit Service 20376f
 * @param payload value you passed to the foreach function as payload
Packit Service 20376f
 * @return 0 on success or error code
Packit Service 20376f
 */
Packit Service 20376f
typedef int (*git_submodule_cb)(
Packit Service 20376f
	git_submodule *sm, const char *name, void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Submodule update options structure
Packit Service 20376f
 *
Packit Service 20376f
 * Use the GIT_SUBMODULE_UPDATE_OPTIONS_INIT to get the default settings,
Packit Service 20376f
 * like this:
Packit Service 20376f
 *
Packit Service 20376f
 * git_submodule_update_options opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_submodule_update_options {
Packit Service 20376f
	unsigned int version;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * These options are passed to the checkout step. To disable
Packit Service 20376f
	 * checkout, set the `checkout_strategy` to
Packit Service 20376f
	 * `GIT_CHECKOUT_NONE`. Generally you will want the use
Packit Service 20376f
	 * GIT_CHECKOUT_SAFE to update files in the working
Packit Service 20376f
	 * directory. 
Packit Service 20376f
	 */
Packit Service 20376f
	git_checkout_options checkout_opts;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Options which control the fetch, including callbacks.
Packit Service 20376f
	 *
Packit Service 20376f
	 * The callbacks to use for reporting fetch progress, and for acquiring
Packit Service 20376f
	 * credentials in the event they are needed.
Packit Service 20376f
	 */
Packit Service 20376f
	git_fetch_options fetch_opts;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Allow fetching from the submodule's default remote if the target
Packit Service 20376f
	 * commit isn't found. Enabled by default.
Packit Service 20376f
	 */
Packit Service 20376f
	int allow_fetch;
Packit Service 20376f
} git_submodule_update_options;
Packit Service 20376f
Packit Service 20376f
#define GIT_SUBMODULE_UPDATE_OPTIONS_VERSION 1
Packit Service 20376f
#define GIT_SUBMODULE_UPDATE_OPTIONS_INIT \
Packit Service 20376f
	{ GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, \
Packit Service 20376f
		{ GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
Packit Service 20376f
	GIT_FETCH_OPTIONS_INIT, 1 }
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initializes a `git_submodule_update_options` with default values.
Packit Service 20376f
 * Equivalent to creating an instance with GIT_SUBMODULE_UPDATE_OPTIONS_INIT.
Packit Service 20376f
 *
Packit Service 20376f
 * @param opts The `git_submodule_update_options` instance to initialize.
Packit Service 20376f
 * @param version Version of struct; pass `GIT_SUBMODULE_UPDATE_OPTIONS_VERSION`
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_update_init_options(
Packit Service 20376f
	git_submodule_update_options *opts, unsigned int version);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Update a submodule. This will clone a missing submodule and
Packit Service 20376f
 * checkout the subrepository to the commit specified in the index of
Packit Service 20376f
 * the containing repository. If the submodule repository doesn't contain
Packit Service 20376f
 * the target commit (e.g. because fetchRecurseSubmodules isn't set), then
Packit Service 20376f
 * the submodule is fetched using the fetch options supplied in options.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule Submodule object
Packit Service 20376f
 * @param init If the submodule is not initialized, setting this flag to true
Packit Service 20376f
 *        will initialize the submodule before updating. Otherwise, this will
Packit Service 20376f
 *        return an error if attempting to update an uninitialzed repository.
Packit Service 20376f
 *        but setting this to true forces them to be updated.
Packit Service 20376f
 * @param options configuration options for the update.  If NULL, the
Packit Service 20376f
 *        function works as though GIT_SUBMODULE_UPDATE_OPTIONS_INIT was passed.
Packit Service 20376f
 * @return 0 on success, any non-zero return value from a callback
Packit Service 20376f
 *         function, or a negative value to indicate an error (use
Packit Service 20376f
 *         `giterr_last` for a detailed error message).
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_update(git_submodule *submodule, int init, git_submodule_update_options *options);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Lookup submodule information by name or path.
Packit Service 20376f
 *
Packit Service 20376f
 * Given either the submodule name or path (they are usually the same), this
Packit Service 20376f
 * returns a structure describing the submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * There are two expected error scenarios:
Packit Service 20376f
 *
Packit Service 20376f
 * - The submodule is not mentioned in the HEAD, the index, and the config,
Packit Service 20376f
 *   but does "exist" in the working directory (i.e. there is a subdirectory
Packit Service 20376f
 *   that appears to be a Git repository).  In this case, this function
Packit Service 20376f
 *   returns GIT_EEXISTS to indicate a sub-repository exists but not in a
Packit Service 20376f
 *   state where a git_submodule can be instantiated.
Packit Service 20376f
 * - The submodule is not mentioned in the HEAD, index, or config and the
Packit Service 20376f
 *   working directory doesn't contain a value git repo at that path.
Packit Service 20376f
 *   There may or may not be anything else at that path, but nothing that
Packit Service 20376f
 *   looks like a submodule.  In this case, this returns GIT_ENOTFOUND.
Packit Service 20376f
 *
Packit Service 20376f
 * You must call `git_submodule_free` when done with the submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Output ptr to submodule; pass NULL to just get return code
Packit Service 20376f
 * @param repo The parent repository
Packit Service 20376f
 * @param name The name of or path to the submodule; trailing slashes okay
Packit Service 20376f
 * @return 0 on success, GIT_ENOTFOUND if submodule does not exist,
Packit Service 20376f
 *         GIT_EEXISTS if a repository is found in working directory only,
Packit Service 20376f
 *         -1 on other errors.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_lookup(
Packit Service 20376f
	git_submodule **out,
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *name);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Release a submodule
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule Submodule object
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_submodule_free(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Iterate over all tracked submodules of a repository.
Packit Service 20376f
 *
Packit Service 20376f
 * See the note on `git_submodule` above.  This iterates over the tracked
Packit Service 20376f
 * submodules as described therein.
Packit Service 20376f
 *
Packit Service 20376f
 * If you are concerned about items in the working directory that look like
Packit Service 20376f
 * submodules but are not tracked, the diff API will generate a diff record
Packit Service 20376f
 * for workdir items that look like submodules but are not tracked, showing
Packit Service 20376f
 * them as added in the workdir.  Also, the status API will treat the entire
Packit Service 20376f
 * subdirectory of a contained git repo as a single GIT_STATUS_WT_NEW item.
Packit Service 20376f
 *
Packit Service 20376f
 * @param repo The repository
Packit Service 20376f
 * @param callback Function to be called with the name of each submodule.
Packit Service 20376f
 *        Return a non-zero value to terminate the iteration.
Packit Service 20376f
 * @param payload Extra data to pass to callback
Packit Service 20376f
 * @return 0 on success, -1 on error, or non-zero return value of callback
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_foreach(
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	git_submodule_cb callback,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set up a new git submodule for checkout.
Packit Service 20376f
 *
Packit Service 20376f
 * This does "git submodule add" up to the fetch and checkout of the
Packit Service 20376f
 * submodule contents.  It preps a new submodule, creates an entry in
Packit Service 20376f
 * .gitmodules and creates an empty initialized repository either at the
Packit Service 20376f
 * given path in the working directory or in .git/modules with a gitlink
Packit Service 20376f
 * from the working directory to the new repo.
Packit Service 20376f
 *
Packit Service 20376f
 * To fully emulate "git submodule add" call this function, then open the
Packit Service 20376f
 * submodule repo and perform the clone step as needed.  Lastly, call
Packit Service 20376f
 * `git_submodule_add_finalize()` to wrap up adding the new submodule and
Packit Service 20376f
 * .gitmodules to the index to be ready to commit.
Packit Service 20376f
 *
Packit Service 20376f
 * You must call `git_submodule_free` on the submodule object when done.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out The newly created submodule ready to open for clone
Packit Service 20376f
 * @param repo The repository in which you want to create the submodule
Packit Service 20376f
 * @param url URL for the submodule's remote
Packit Service 20376f
 * @param path Path at which the submodule should be created
Packit Service 20376f
 * @param use_gitlink Should workdir contain a gitlink to the repo in
Packit Service 20376f
 *        .git/modules vs. repo directly in workdir.
Packit Service 20376f
 * @return 0 on success, GIT_EEXISTS if submodule already exists,
Packit Service 20376f
 *         -1 on other errors.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_add_setup(
Packit Service 20376f
	git_submodule **out,
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *url,
Packit Service 20376f
	const char *path,
Packit Service 20376f
	int use_gitlink);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Resolve the setup of a new git submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * This should be called on a submodule once you have called add setup
Packit Service 20376f
 * and done the clone of the submodule.  This adds the .gitmodules file
Packit Service 20376f
 * and the newly cloned submodule to the index to be ready to be committed
Packit Service 20376f
 * (but doesn't actually do the commit).
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule The submodule to finish adding.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_add_finalize(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add current submodule HEAD commit to index of superproject.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule The submodule to add to the index
Packit Service 20376f
 * @param write_index Boolean if this should immediately write the index
Packit Service 20376f
 *            file.  If you pass this as false, you will have to get the
Packit Service 20376f
 *            git_index and explicitly call `git_index_write()` on it to
Packit Service 20376f
 *            save the change.
Packit Service 20376f
 * @return 0 on success, <0 on failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_add_to_index(
Packit Service 20376f
	git_submodule *submodule,
Packit Service 20376f
	int write_index);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the containing repository for a submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * This returns a pointer to the repository that contains the submodule.
Packit Service 20376f
 * This is a just a reference to the repository that was passed to the
Packit Service 20376f
 * original `git_submodule_lookup()` call, so if that repository has been
Packit Service 20376f
 * freed, then this may be a dangling reference.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule Pointer to submodule object
Packit Service 20376f
 * @return Pointer to `git_repository`
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_repository *) git_submodule_owner(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the name of submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule Pointer to submodule object
Packit Service 20376f
 * @return Pointer to the submodule name
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const char *) git_submodule_name(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the path to the submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * The path is almost always the same as the submodule name, but the
Packit Service 20376f
 * two are actually not required to match.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule Pointer to submodule object
Packit Service 20376f
 * @return Pointer to the submodule path
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const char *) git_submodule_path(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the URL for the submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule Pointer to submodule object
Packit Service 20376f
 * @return Pointer to the submodule url
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const char *) git_submodule_url(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Resolve a submodule url relative to the given repository.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out buffer to store the absolute submodule url in
Packit Service 20376f
 * @param repo Pointer to repository object
Packit Service 20376f
 * @param url Relative url
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *url);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
* Get the branch for the submodule.
Packit Service 20376f
*
Packit Service 20376f
* @param submodule Pointer to submodule object
Packit Service 20376f
* @return Pointer to the submodule branch
Packit Service 20376f
*/
Packit Service 20376f
GIT_EXTERN(const char *) git_submodule_branch(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the branch for the submodule in the configuration
Packit Service 20376f
 *
Packit Service 20376f
 * After calling this, you may wish to call `git_submodule_sync()` to
Packit Service 20376f
 * write the changes to the checked out submodule repository.
Packit Service 20376f
 *
Packit Service 20376f
 * @param repo the repository to affect
Packit Service 20376f
 * @param name the name of the submodule to configure
Packit Service 20376f
 * @param branch Branch that should be used for the submodule
Packit Service 20376f
 * @return 0 on success, <0 on failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_set_branch(git_repository *repo, const char *name, const char *branch);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the URL for the submodule in the configuration
Packit Service 20376f
 *
Packit Service 20376f
 *
Packit Service 20376f
 * After calling this, you may wish to call `git_submodule_sync()` to
Packit Service 20376f
 * write the changes to the checked out submodule repository.
Packit Service 20376f
 *
Packit Service 20376f
 * @param repo the repository to affect
Packit Service 20376f
 * @param name the name of the submodule to configure
Packit Service 20376f
 * @param url URL that should be used for the submodule
Packit Service 20376f
 * @return 0 on success, <0 on failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_set_url(git_repository *repo, const char *name, const char *url);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the OID for the submodule in the index.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule Pointer to submodule object
Packit Service 20376f
 * @return Pointer to git_oid or NULL if submodule is not in index.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const git_oid *) git_submodule_index_id(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the OID for the submodule in the current HEAD tree.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule Pointer to submodule object
Packit Service 20376f
 * @return Pointer to git_oid or NULL if submodule is not in the HEAD.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const git_oid *) git_submodule_head_id(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the OID for the submodule in the current working directory.
Packit Service 20376f
 *
Packit Service 20376f
 * This returns the OID that corresponds to looking up 'HEAD' in the checked
Packit Service 20376f
 * out submodule.  If there are pending changes in the index or anything
Packit Service 20376f
 * else, this won't notice that.  You should call `git_submodule_status()`
Packit Service 20376f
 * for a more complete picture about the state of the working directory.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule Pointer to submodule object
Packit Service 20376f
 * @return Pointer to git_oid or NULL if submodule is not checked out.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const git_oid *) git_submodule_wd_id(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the ignore rule that will be used for the submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * These values control the behavior of `git_submodule_status()` for this
Packit Service 20376f
 * submodule.  There are four ignore values:
Packit Service 20376f
 *
Packit Service 20376f
 *  - **GIT_SUBMODULE_IGNORE_NONE** will consider any change to the contents
Packit Service 20376f
 *    of the submodule from a clean checkout to be dirty, including the
Packit Service 20376f
 *    addition of untracked files.  This is the default if unspecified.
Packit Service 20376f
 *  - **GIT_SUBMODULE_IGNORE_UNTRACKED** examines the contents of the
Packit Service 20376f
 *    working tree (i.e. call `git_status_foreach()` on the submodule) but
Packit Service 20376f
 *    UNTRACKED files will not count as making the submodule dirty.
Packit Service 20376f
 *  - **GIT_SUBMODULE_IGNORE_DIRTY** means to only check if the HEAD of the
Packit Service 20376f
 *    submodule has moved for status.  This is fast since it does not need to
Packit Service 20376f
 *    scan the working tree of the submodule at all.
Packit Service 20376f
 *  - **GIT_SUBMODULE_IGNORE_ALL** means not to open the submodule repo.
Packit Service 20376f
 *    The working directory will be consider clean so long as there is a
Packit Service 20376f
 *    checked out version present.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule The submodule to check
Packit Service 20376f
 * @return The current git_submodule_ignore_t valyue what will be used for
Packit Service 20376f
 *         this submodule.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_submodule_ignore_t) git_submodule_ignore(
Packit Service 20376f
	git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the ignore rule for the submodule in the configuration
Packit Service 20376f
 *
Packit Service 20376f
 * This does not affect any currently-loaded instances.
Packit Service 20376f
 *
Packit Service 20376f
 * @param repo the repository to affect
Packit Service 20376f
 * @param name the name of the submdule
Packit Service 20376f
 * @param ignore The new value for the ignore rule
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_set_ignore(
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *name,
Packit Service 20376f
	git_submodule_ignore_t ignore);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the update rule that will be used for the submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * This value controls the behavior of the `git submodule update` command.
Packit Service 20376f
 * There are four useful values documented with `git_submodule_update_t`.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule The submodule to check
Packit Service 20376f
 * @return The current git_submodule_update_t value that will be used
Packit Service 20376f
 *         for this submodule.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_submodule_update_t) git_submodule_update_strategy(
Packit Service 20376f
	git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the update rule for the submodule in the configuration
Packit Service 20376f
 *
Packit Service 20376f
 * This setting won't affect any existing instances.
Packit Service 20376f
 *
Packit Service 20376f
 * @param repo the repository to affect
Packit Service 20376f
 * @param name the name of the submodule to configure
Packit Service 20376f
 * @param update The new value to use
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_set_update(
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *name,
Packit Service 20376f
	git_submodule_update_t update);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Read the fetchRecurseSubmodules rule for a submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * This accesses the submodule.<name>.fetchRecurseSubmodules value for
Packit Service 20376f
 * the submodule that controls fetching behavior for the submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * Note that at this time, libgit2 does not honor this setting and the
Packit Service 20376f
 * fetch functionality current ignores submodules.
Packit Service 20376f
 *
Packit Service 20376f
 * @return 0 if fetchRecurseSubmodules is false, 1 if true
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_submodule_recurse_t) git_submodule_fetch_recurse_submodules(
Packit Service 20376f
	git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set the fetchRecurseSubmodules rule for a submodule in the configuration
Packit Service 20376f
 *
Packit Service 20376f
 * This setting won't affect any existing instances.
Packit Service 20376f
 *
Packit Service 20376f
 * @param repo the repository to affect
Packit Service 20376f
 * @param name the submodule to configure
Packit Service 20376f
 * @param fetch_recurse_submodules Boolean value
Packit Service 20376f
 * @return old value for fetchRecurseSubmodules
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_set_fetch_recurse_submodules(
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *name,
Packit Service 20376f
	git_submodule_recurse_t fetch_recurse_submodules);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Copy submodule info into ".git/config" file.
Packit Service 20376f
 *
Packit Service 20376f
 * Just like "git submodule init", this copies information about the
Packit Service 20376f
 * submodule into ".git/config".  You can use the accessor functions
Packit Service 20376f
 * above to alter the in-memory git_submodule object and control what
Packit Service 20376f
 * is written to the config, overriding what is in .gitmodules.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule The submodule to write into the superproject config
Packit Service 20376f
 * @param overwrite By default, existing entries will not be overwritten,
Packit Service 20376f
 *                  but setting this to true forces them to be updated.
Packit Service 20376f
 * @return 0 on success, <0 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_init(git_submodule *submodule, int overwrite);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Set up the subrepository for a submodule in preparation for clone.
Packit Service 20376f
 *
Packit Service 20376f
 * This function can be called to init and set up a submodule
Packit Service 20376f
 * repository from a submodule in preparation to clone it from
Packit Service 20376f
 * its remote.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Output pointer to the created git repository.
Packit Service 20376f
 * @param sm The submodule to create a new subrepository from.
Packit Service 20376f
 * @param use_gitlink Should the workdir contain a gitlink to
Packit Service 20376f
 *        the repo in .git/modules vs. repo directly in workdir.
Packit Service 20376f
 * @return 0 on success, <0 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_repo_init(
Packit Service 20376f
	git_repository **out,
Packit Service 20376f
	const git_submodule *sm,
Packit Service 20376f
	int use_gitlink);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Copy submodule remote info into submodule repo.
Packit Service 20376f
 *
Packit Service 20376f
 * This copies the information about the submodules URL into the checked out
Packit Service 20376f
 * submodule config, acting like "git submodule sync".  This is useful if
Packit Service 20376f
 * you have altered the URL for the submodule (or it has been altered by a
Packit Service 20376f
 * fetch of upstream changes) and you need to update your local repo.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_sync(git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Open the repository for a submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * This is a newly opened repository object.  The caller is responsible for
Packit Service 20376f
 * calling `git_repository_free()` on it when done.  Multiple calls to this
Packit Service 20376f
 * function will return distinct `git_repository` objects.  This will only
Packit Service 20376f
 * work if the submodule is checked out into the working directory.
Packit Service 20376f
 *
Packit Service 20376f
 * @param repo Pointer to the submodule repo which was opened
Packit Service 20376f
 * @param submodule Submodule to be opened
Packit Service 20376f
 * @return 0 on success, <0 if submodule repo could not be opened.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_open(
Packit Service 20376f
	git_repository **repo,
Packit Service 20376f
	git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Reread submodule info from config, index, and HEAD.
Packit Service 20376f
 *
Packit Service 20376f
 * Call this to reread cached submodule information for this submodule if
Packit Service 20376f
 * you have reason to believe that it has changed.
Packit Service 20376f
 *
Packit Service 20376f
 * @param submodule The submodule to reload
Packit Service 20376f
 * @param force Force reload even if the data doesn't seem out of date
Packit Service 20376f
 * @return 0 on success, <0 on error
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_reload(git_submodule *submodule, int force);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the status for a submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * This looks at a submodule and tries to determine the status.  It
Packit Service 20376f
 * will return a combination of the `GIT_SUBMODULE_STATUS` values above.
Packit Service 20376f
 * How deeply it examines the working directory to do this will depend
Packit Service 20376f
 * on the `git_submodule_ignore_t` value for the submodule.
Packit Service 20376f
 *
Packit Service 20376f
 * @param status Combination of `GIT_SUBMODULE_STATUS` flags
Packit Service 20376f
 * @param repo the repository in which to look
Packit Service 20376f
 * @param name name of the submodule
Packit Service 20376f
 * @param ignore the ignore rules to follow
Packit Service 20376f
 * @return 0 on success, <0 on error
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_status(
Packit Service 20376f
	unsigned int *status,
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *name,
Packit Service 20376f
	git_submodule_ignore_t ignore);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the locations of submodule information.
Packit Service 20376f
 *
Packit Service 20376f
 * This is a bit like a very lightweight version of `git_submodule_status`.
Packit Service 20376f
 * It just returns a made of the first four submodule status values (i.e.
Packit Service 20376f
 * the ones like GIT_SUBMODULE_STATUS_IN_HEAD, etc) that tell you where the
Packit Service 20376f
 * submodule data comes from (i.e. the HEAD commit, gitmodules file, etc.).
Packit Service 20376f
 * This can be useful if you want to know if the submodule is present in the
Packit Service 20376f
 * working directory at this point in time, etc.
Packit Service 20376f
 *
Packit Service 20376f
 * @param location_status Combination of first four `GIT_SUBMODULE_STATUS` flags
Packit Service 20376f
 * @param submodule Submodule for which to get status
Packit Service 20376f
 * @return 0 on success, <0 on error
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_submodule_location(
Packit Service 20376f
	unsigned int *location_status,
Packit Service 20376f
	git_submodule *submodule);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif