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__
19 * @brief Git cloning routines
20 * @defgroup git_clone Git cloning routines
27 * Clone options structure
29 * Use the GIT_CLONE_OPTIONS_INIT to get the default settings, like this:
31 * git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
33 * - `checkout_opts` are option passed to the checkout step. To disable
34 * checkout, set the `checkout_strategy` to GIT_CHECKOUT_NONE.
35 * Generally you will want the use GIT_CHECKOUT_SAFE_CREATE to create
36 * all files in the working directory for the newly cloned repository.
37 * - `bare` should be set to zero (false) to create a standard repo,
38 * or non-zero for a bare repo
39 * - `ignore_cert_errors` should be set to 1 if errors validating the
40 * remote host's certificate should be ignored.
42 * ** "origin" remote options: **
44 * - `remote_name` is the name to be given to the "origin" remote. The
45 * default is "origin".
46 * - `checkout_branch` gives the name of the branch to checkout. NULL
47 * means use the remote's HEAD.
48 * - `signature` is the identity used when updating the reflog. NULL means to
49 * use the default signature using the config.
52 typedef struct git_clone_options
{
55 git_checkout_opts checkout_opts
;
56 git_remote_callbacks remote_callbacks
;
59 int ignore_cert_errors
;
60 const char *remote_name
;
61 const char* checkout_branch
;
62 git_signature
*signature
;
65 #define GIT_CLONE_OPTIONS_VERSION 1
66 #define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE_CREATE}, GIT_REMOTE_CALLBACKS_INIT}
69 * Initializes a `git_clone_options` with default values. Equivalent to
70 * creating an instance with GIT_CLONE_OPTIONS_INIT.
72 * @param opts the `git_clone_options` instance to initialize.
73 * @param version the version of the struct; you should pass
74 * `GIT_CLONE_OPTIONS_VERSION` here.
75 * @return Zero on success; -1 on failure.
77 GIT_EXTERN(int) git_clone_init_options(
78 git_clone_options
* opts
,
82 * Clone a remote repository.
84 * This version handles the simple case. If you'd like to create the
85 * repository or remote with non-default settings, you can create and
86 * configure them and then use `git_clone_into()`.
88 * @param out pointer that will receive the resulting repository object
89 * @param url the remote repository to clone
90 * @param local_path local directory to clone to
91 * @param options configuration options for the clone. If NULL, the
92 * function works as though GIT_OPTIONS_INIT were passed.
93 * @return 0 on success, any non-zero return value from a callback
94 * function, or a negative value to indicate an error (use
95 * `giterr_last` for a detailed error message)
97 GIT_EXTERN(int) git_clone(
100 const char *local_path
,
101 const git_clone_options
*options
);
104 * Clone into a repository
106 * After creating the repository and remote and configuring them for
107 * paths and callbacks respectively, you can call this function to
108 * perform the clone operation and optionally checkout files.
110 * @param repo the repository to use
111 * @param remote the remote repository to clone from
112 * @param co_opts options to use during checkout
113 * @param branch the branch to checkout after the clone, pass NULL for the
114 * remote's default branch
115 * @param signature The identity used when updating the reflog.
116 * @return 0 on success, any non-zero return value from a callback
117 * function, or a negative value to indicate an error (use
118 * `giterr_last` for a detailed error message)
120 GIT_EXTERN(int) git_clone_into(
121 git_repository
*repo
,
123 const git_checkout_opts
*co_opts
,
125 const git_signature
*signature
);