2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_git_clone_h__
8 #define INCLUDE_git_clone_h__
15 #include "transport.h"
20 * @brief Git cloning routines
21 * @defgroup git_clone Git cloning routines
28 * Options for bypassing the git-aware transport on clone. Bypassing
29 * it means that instead of a fetch, libgit2 will copy the object
30 * database directory instead of figuring out what it needs, which is
31 * faster. If possible, it will hardlink the files to save space.
35 * Auto-detect (default), libgit2 will bypass the git-aware
36 * transport for local paths, but use a normal fetch for
41 * Bypass the git-aware transport even for a `file://` url.
45 * Do no bypass the git-aware transport
49 * Bypass the git-aware transport, but do not try to use
52 GIT_CLONE_LOCAL_NO_LINKS
,
56 * The signature of a function matching git_remote_create, with an additional
57 * void* as a callback payload.
59 * Callers of git_clone may provide a function matching this signature to override
60 * the remote creation and customization process during a clone operation.
62 * @param out the resulting remote
63 * @param repo the repository in which to create the remote
64 * @param name the remote's name
65 * @param url the remote's url
66 * @param payload an opaque payload
67 * @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
69 typedef int (*git_remote_create_cb
)(
77 * Clone options structure
79 * Use the GIT_CLONE_OPTIONS_INIT to get the default settings, like this:
81 * git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
84 typedef struct git_clone_options
{
88 * These options are passed to the checkout step. To disable
89 * checkout, set the `checkout_strategy` to
90 * `GIT_CHECKOUT_NONE`. Generally you will want the use
91 * GIT_CHECKOUT_SAFE_CREATE to create all files in the working
92 * directory for the newly cloned repository.
94 git_checkout_options checkout_opts
;
97 * Callbacks to use for reporting fetch progress, and for acquiring
98 * credentials in the event they are needed. This parameter is ignored if
99 * the remote_cb parameter is set; if you provide a remote creation
100 * callback, then you have the opportunity to configure remote callbacks in
103 git_remote_callbacks remote_callbacks
;
106 * Set to zero (false) to create a standard repo, or non-zero
112 * Whether to use a fetch or copy the object database.
114 git_clone_local_t local
;
117 * The name of the branch to checkout. NULL means use the
118 * remote's default branch.
120 const char* checkout_branch
;
123 * The identity used when updating the reflog. NULL means to
124 * use the default signature using the config.
126 git_signature
*signature
;
129 * A callback used to create the git_remote, prior to its being
130 * used to perform the clone operation. See the documentation for
131 * git_remote_create_cb for details. This parameter may be NULL,
132 * indicating that git_clone should provide default behavior.
134 git_remote_create_cb remote_cb
;
137 * An opaque payload to pass to the git_remote creation callback.
138 * This parameter is ignored unless remote_cb is non-NULL.
140 void *remote_cb_payload
;
143 #define GIT_CLONE_OPTIONS_VERSION 1
144 #define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE_CREATE}, GIT_REMOTE_CALLBACKS_INIT}
147 * Initializes a `git_clone_options` with default values. Equivalent to
148 * creating an instance with GIT_CLONE_OPTIONS_INIT.
150 * @param opts The `git_clone_options` struct to initialize
151 * @param version Version of struct; pass `GIT_CLONE_OPTIONS_VERSION`
152 * @return Zero on success; -1 on failure.
154 GIT_EXTERN(int) git_clone_init_options(
155 git_clone_options
*opts
,
156 unsigned int version
);
159 * Clone a remote repository.
161 * This version handles the simple case. If you'd like to create the
162 * repository or remote with non-default settings, you can create and
163 * configure them and then use `git_clone_into()`.
165 * @param out pointer that will receive the resulting repository object
166 * @param url the remote repository to clone
167 * @param local_path local directory to clone to
168 * @param options configuration options for the clone. If NULL, the
169 * function works as though GIT_OPTIONS_INIT were passed.
170 * @return 0 on success, any non-zero return value from a callback
171 * function, or a negative value to indicate an error (use
172 * `giterr_last` for a detailed error message)
174 GIT_EXTERN(int) git_clone(
175 git_repository
**out
,
177 const char *local_path
,
178 const git_clone_options
*options
);
181 * Clone into a repository
183 * After creating the repository and remote and configuring them for
184 * paths and callbacks respectively, you can call this function to
185 * perform the clone operation and optionally checkout files.
187 * @param repo the repository to use
188 * @param remote the remote repository to clone from
189 * @param co_opts options to use during checkout
190 * @param branch the branch to checkout after the clone, pass NULL for the
191 * remote's default branch
192 * @param signature The identity used when updating the reflog.
193 * @return 0 on success, any non-zero return value from a callback
194 * function, or a negative value to indicate an error (use
195 * `giterr_last` for a detailed error message)
197 GIT_EXTERN(int) git_clone_into(
198 git_repository
*repo
,
200 const git_checkout_options
*co_opts
,
202 const git_signature
*signature
);
205 * Perform a local clone into a repository
207 * A "local clone" bypasses any git-aware protocols and simply copies
208 * over the object database from the source repository. It is often
209 * faster than a git-aware clone, but no verification of the data is
210 * performed, and can copy over too much data.
212 * @param repo the repository to use
213 * @param remote the remote repository to clone from
214 * @param co_opts options to use during checkout
215 * @param branch the branch to checkout after the clone, pass NULL for the
216 * remote's default branch
217 * @param link wether to use hardlinks instead of copying
218 * objects. This is only possible if both repositories are on the same
220 * @param signature the identity used when updating the reflog
221 * @return 0 on success, any non-zero return value from a callback
222 * function, or a negative value to indicate an error (use
223 * `giterr_last` for a detailed error message)
225 GIT_EXTERN(int) git_clone_local_into(
226 git_repository
*repo
,
228 const git_checkout_options
*co_opts
,
231 const git_signature
*signature
);