Blame include/git2/clone.h

Packit ae9e2a
/*
Packit ae9e2a
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit ae9e2a
 *
Packit ae9e2a
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit ae9e2a
 * a Linking Exception. For full terms see the included COPYING file.
Packit ae9e2a
 */
Packit ae9e2a
#ifndef INCLUDE_git_clone_h__
Packit ae9e2a
#define INCLUDE_git_clone_h__
Packit ae9e2a
Packit ae9e2a
#include "common.h"
Packit ae9e2a
#include "types.h"
Packit ae9e2a
#include "indexer.h"
Packit ae9e2a
#include "checkout.h"
Packit ae9e2a
#include "remote.h"
Packit ae9e2a
#include "transport.h"
Packit ae9e2a
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * @file git2/clone.h
Packit ae9e2a
 * @brief Git cloning routines
Packit ae9e2a
 * @defgroup git_clone Git cloning routines
Packit ae9e2a
 * @ingroup Git
Packit ae9e2a
 * @{
Packit ae9e2a
 */
Packit ae9e2a
GIT_BEGIN_DECL
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Options for bypassing the git-aware transport on clone. Bypassing
Packit ae9e2a
 * it means that instead of a fetch, libgit2 will copy the object
Packit ae9e2a
 * database directory instead of figuring out what it needs, which is
Packit ae9e2a
 * faster. If possible, it will hardlink the files to save space.
Packit ae9e2a
 */
Packit ae9e2a
typedef enum {
Packit ae9e2a
	/**
Packit ae9e2a
	 * Auto-detect (default), libgit2 will bypass the git-aware
Packit ae9e2a
	 * transport for local paths, but use a normal fetch for
Packit ae9e2a
	 * `file://` urls.
Packit ae9e2a
	 */
Packit ae9e2a
	GIT_CLONE_LOCAL_AUTO,
Packit ae9e2a
	/**
Packit ae9e2a
	 * Bypass the git-aware transport even for a `file://` url.
Packit ae9e2a
	 */
Packit ae9e2a
	GIT_CLONE_LOCAL,
Packit ae9e2a
	/**
Packit ae9e2a
	 * Do no bypass the git-aware transport
Packit ae9e2a
	 */
Packit ae9e2a
	GIT_CLONE_NO_LOCAL,
Packit ae9e2a
	/**
Packit ae9e2a
	 * Bypass the git-aware transport, but do not try to use
Packit ae9e2a
	 * hardlinks.
Packit ae9e2a
	 */
Packit ae9e2a
	GIT_CLONE_LOCAL_NO_LINKS,
Packit ae9e2a
} git_clone_local_t;
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * The signature of a function matching git_remote_create, with an additional
Packit ae9e2a
 * void* as a callback payload.
Packit ae9e2a
 *
Packit ae9e2a
 * Callers of git_clone may provide a function matching this signature to override
Packit ae9e2a
 * the remote creation and customization process during a clone operation.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out the resulting remote
Packit ae9e2a
 * @param repo the repository in which to create the remote
Packit ae9e2a
 * @param name the remote's name
Packit ae9e2a
 * @param url the remote's url
Packit ae9e2a
 * @param payload an opaque payload
Packit ae9e2a
 * @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
Packit ae9e2a
 */
Packit ae9e2a
typedef int (*git_remote_create_cb)(
Packit ae9e2a
	git_remote **out,
Packit ae9e2a
	git_repository *repo,
Packit ae9e2a
	const char *name,
Packit ae9e2a
	const char *url,
Packit ae9e2a
	void *payload);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * The signature of a function matchin git_repository_init, with an
Packit ae9e2a
 * aditional void * as callback payload.
Packit ae9e2a
 *
Packit ae9e2a
 * Callers of git_clone my provide a function matching this signature
Packit ae9e2a
 * to override the repository creation and customization process
Packit ae9e2a
 * during a clone operation.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out the resulting repository
Packit ae9e2a
 * @param path path in which to create the repository
Packit ae9e2a
 * @param bare whether the repository is bare. This is the value from the clone options
Packit ae9e2a
 * @param payload payload specified by the options
Packit ae9e2a
 * @return 0, or a negative value to indicate error
Packit ae9e2a
 */
Packit ae9e2a
typedef int (*git_repository_create_cb)(
Packit ae9e2a
	git_repository **out,
Packit ae9e2a
	const char *path,
Packit ae9e2a
	int bare,
Packit ae9e2a
	void *payload);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Clone options structure
Packit ae9e2a
 *
Packit ae9e2a
 * Use the GIT_CLONE_OPTIONS_INIT to get the default settings, like this:
Packit ae9e2a
 *
Packit ae9e2a
 *		git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
Packit ae9e2a
 */
Packit ae9e2a
typedef struct git_clone_options {
Packit ae9e2a
	unsigned int version;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * These options are passed to the checkout step. To disable
Packit ae9e2a
	 * checkout, set the `checkout_strategy` to
Packit ae9e2a
	 * `GIT_CHECKOUT_NONE`.
Packit ae9e2a
	 */
Packit ae9e2a
	git_checkout_options checkout_opts;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * Options which control the fetch, including callbacks.
Packit ae9e2a
	 *
Packit ae9e2a
	 * The callbacks are used for reporting fetch progress, and for acquiring
Packit ae9e2a
	 * credentials in the event they are needed.
Packit ae9e2a
	 */
Packit ae9e2a
	git_fetch_options fetch_opts;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * Set to zero (false) to create a standard repo, or non-zero
Packit ae9e2a
	 * for a bare repo
Packit ae9e2a
	 */
Packit ae9e2a
	int bare;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * Whether to use a fetch or copy the object database.
Packit ae9e2a
	 */
Packit ae9e2a
	git_clone_local_t local;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * The name of the branch to checkout. NULL means use the
Packit ae9e2a
	 * remote's default branch.
Packit ae9e2a
	 */
Packit ae9e2a
	const char* checkout_branch;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * A callback used to create the new repository into which to
Packit ae9e2a
	 * clone. If NULL, the 'bare' field will be used to determine
Packit ae9e2a
	 * whether to create a bare repository.
Packit ae9e2a
	 */
Packit ae9e2a
	git_repository_create_cb repository_cb;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * An opaque payload to pass to the git_repository creation callback.
Packit ae9e2a
	 * This parameter is ignored unless repository_cb is non-NULL.
Packit ae9e2a
	 */
Packit ae9e2a
	void *repository_cb_payload;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * A callback used to create the git_remote, prior to its being
Packit ae9e2a
	 * used to perform the clone operation. See the documentation for
Packit ae9e2a
	 * git_remote_create_cb for details. This parameter may be NULL,
Packit ae9e2a
	 * indicating that git_clone should provide default behavior.
Packit ae9e2a
	 */
Packit ae9e2a
	git_remote_create_cb remote_cb;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * An opaque payload to pass to the git_remote creation callback.
Packit ae9e2a
	 * This parameter is ignored unless remote_cb is non-NULL.
Packit ae9e2a
	 */
Packit ae9e2a
	void *remote_cb_payload;
Packit ae9e2a
} git_clone_options;
Packit ae9e2a
Packit ae9e2a
#define GIT_CLONE_OPTIONS_VERSION 1
Packit ae9e2a
#define GIT_CLONE_OPTIONS_INIT { GIT_CLONE_OPTIONS_VERSION, \
Packit ae9e2a
	{ GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
Packit ae9e2a
	GIT_FETCH_OPTIONS_INIT }
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Initializes a `git_clone_options` with default values. Equivalent to
Packit ae9e2a
 * creating an instance with GIT_CLONE_OPTIONS_INIT.
Packit ae9e2a
 *
Packit ae9e2a
 * @param opts The `git_clone_options` struct to initialize
Packit ae9e2a
 * @param version Version of struct; pass `GIT_CLONE_OPTIONS_VERSION`
Packit ae9e2a
 * @return Zero on success; -1 on failure.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_clone_init_options(
Packit ae9e2a
	git_clone_options *opts,
Packit ae9e2a
	unsigned int version);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Clone a remote repository.
Packit ae9e2a
 *
Packit ae9e2a
 * By default this creates its repository and initial remote to match
Packit ae9e2a
 * git's defaults. You can use the options in the callback to
Packit ae9e2a
 * customize how these are created.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer that will receive the resulting repository object
Packit ae9e2a
 * @param url the remote repository to clone
Packit ae9e2a
 * @param local_path local directory to clone to
Packit ae9e2a
 * @param options configuration options for the clone.  If NULL, the
Packit ae9e2a
 *        function works as though GIT_OPTIONS_INIT were passed.
Packit ae9e2a
 * @return 0 on success, any non-zero return value from a callback
Packit ae9e2a
 *         function, or a negative value to indicate an error (use
Packit ae9e2a
 *         `giterr_last` for a detailed error message)
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_clone(
Packit ae9e2a
	git_repository **out,
Packit ae9e2a
	const char *url,
Packit ae9e2a
	const char *local_path,
Packit ae9e2a
	const git_clone_options *options);
Packit ae9e2a
Packit ae9e2a
/** @} */
Packit ae9e2a
GIT_END_DECL
Packit ae9e2a
#endif