1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 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. 6 */ 7 module libgit2_d.clone; 8 9 10 private static import libgit2_d.checkout; 11 private static import libgit2_d.remote; 12 private static import libgit2_d.types; 13 14 /** 15 * @file git2/clone.h 16 * @brief Git cloning routines 17 * @defgroup git_clone Git cloning routines 18 * @ingroup Git 19 * @{ 20 */ 21 extern (C): 22 nothrow @nogc: 23 public: 24 25 /** 26 * Options for bypassing the git-aware transport on clone. Bypassing 27 * it means that instead of a fetch, libgit2 will copy the object 28 * database directory instead of figuring out what it needs, which is 29 * faster. If possible, it will hardlink the files to save space. 30 */ 31 enum git_clone_local_t 32 { 33 /** 34 * Auto-detect (default), libgit2 will bypass the git-aware 35 * transport for local paths, but use a normal fetch for 36 * `file://` urls. 37 */ 38 GIT_CLONE_LOCAL_AUTO, 39 40 /** 41 * Bypass the git-aware transport even for a `file://` url. 42 */ 43 GIT_CLONE_LOCAL, 44 45 /** 46 * Do no bypass the git-aware transport 47 */ 48 GIT_CLONE_NO_LOCAL, 49 50 /** 51 * Bypass the git-aware transport, but do not try to use 52 * hardlinks. 53 */ 54 GIT_CLONE_LOCAL_NO_LINKS, 55 } 56 57 //Declaration name in C language 58 enum 59 { 60 GIT_CLONE_LOCAL_AUTO = .git_clone_local_t.GIT_CLONE_LOCAL_AUTO, 61 GIT_CLONE_LOCAL = .git_clone_local_t.GIT_CLONE_LOCAL, 62 GIT_CLONE_NO_LOCAL = .git_clone_local_t.GIT_CLONE_NO_LOCAL, 63 GIT_CLONE_LOCAL_NO_LINKS = .git_clone_local_t.GIT_CLONE_LOCAL_NO_LINKS, 64 } 65 66 /** 67 * The signature of a function matching git_remote_create, with an additional 68 * void* as a callback payload. 69 * 70 * Callers of git_clone may provide a function matching this signature to 71 * override the remote creation and customization process during a clone 72 * operation. 73 * 74 * Params: 75 * out_ = the resulting remote 76 * repo = the repository in which to create the remote 77 * name = the remote's name 78 * url = the remote's url 79 * payload = an opaque payload 80 * 81 * Returns: 0, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EEXISTS or an error code 82 */ 83 alias git_remote_create_cb = int function(libgit2_d.types.git_remote** out_, libgit2_d.types.git_repository* repo, const (char)* name, const (char)* url, void* payload); 84 85 /** 86 * The signature of a function matchin git_repository_init, with an 87 * aditional void * as callback payload. 88 * 89 * Callers of git_clone my provide a function matching this signature 90 * to override the repository creation and customization process 91 * during a clone operation. 92 * 93 * Params: 94 * out_ = the resulting repository 95 * path = path in which to create the repository 96 * bare = whether the repository is bare. This is the value from the clone options 97 * payload = payload specified by the options 98 * 99 * Returns: 0, or a negative value to indicate error 100 */ 101 alias git_repository_create_cb = int function(libgit2_d.types.git_repository** out_, const (char)* path, int bare, void* payload); 102 103 /** 104 * Clone options structure 105 * 106 * Initialize with `GIT_CLONE_OPTIONS_INIT`. Alternatively, you can 107 * use `git_clone_options_init`. 108 */ 109 struct git_clone_options 110 { 111 uint version_; 112 113 /** 114 * These options are passed to the checkout step. To disable 115 * checkout, set the `checkout_strategy` to 116 * `git_checkout_strategy_t.GIT_CHECKOUT_NONE`. 117 */ 118 libgit2_d.checkout.git_checkout_options checkout_opts; 119 120 /** 121 * Options which control the fetch, including callbacks. 122 * 123 * The callbacks are used for reporting fetch progress, and for acquiring 124 * credentials in the event they are needed. 125 */ 126 libgit2_d.remote.git_fetch_options fetch_opts; 127 128 /** 129 * Set to zero (false) to create a standard repo, or non-zero 130 * for a bare repo 131 */ 132 int bare; 133 134 /** 135 * Whether to use a fetch or copy the object database. 136 */ 137 .git_clone_local_t local; 138 139 /** 140 * The name of the branch to checkout. null means use the 141 * remote's default branch. 142 */ 143 const (char)* checkout_branch; 144 145 /** 146 * A callback used to create the new repository into which to 147 * clone. If null, the 'bare' field will be used to determine 148 * whether to create a bare repository. 149 */ 150 .git_repository_create_cb repository_cb; 151 152 /** 153 * An opaque payload to pass to the libgit2_d.types.git_repository creation callback. 154 * This parameter is ignored unless repository_cb is non-null. 155 */ 156 void* repository_cb_payload; 157 158 /** 159 * A callback used to create the git_remote, prior to its being 160 * used to perform the clone operation. See the documentation for 161 * git_remote_create_cb for details. This parameter may be null, 162 * indicating that git_clone should provide default behavior. 163 */ 164 .git_remote_create_cb remote_cb; 165 166 /** 167 * An opaque payload to pass to the git_remote creation callback. 168 * This parameter is ignored unless remote_cb is non-null. 169 */ 170 void* remote_cb_payload; 171 } 172 173 enum GIT_CLONE_OPTIONS_VERSION = 1; 174 175 pragma(inline, true) 176 pure nothrow @safe @nogc 177 .git_clone_options GIT_CLONE_OPTIONS_INIT() 178 179 do 180 { 181 libgit2_d.checkout.git_checkout_options CHECKOUT_OPTION = 182 { 183 version_: libgit2_d.checkout.GIT_CHECKOUT_OPTIONS_VERSION, 184 checkout_strategy: libgit2_d.checkout.git_checkout_strategy_t.GIT_CHECKOUT_SAFE, 185 }; 186 187 .git_clone_options OUTPUT = 188 { 189 version_: .GIT_CLONE_OPTIONS_VERSION, 190 checkout_opts: CHECKOUT_OPTION, 191 fetch_opts: libgit2_d.remote.GIT_FETCH_OPTIONS_INIT(), 192 }; 193 194 return OUTPUT; 195 } 196 197 /** 198 * Initialize git_clone_options structure 199 * 200 * Initializes a `git_clone_options` with default values. Equivalent to creating 201 * an instance with GIT_CLONE_OPTIONS_INIT. 202 * 203 * Params: 204 * opts = The `git_clone_options` struct to initialize. 205 * version = The struct version; pass `GIT_CLONE_OPTIONS_VERSION`. 206 * 207 * Returns: Zero on success; -1 on failure. 208 */ 209 //GIT_EXTERN 210 int git_clone_options_init(.git_clone_options* opts, uint version_); 211 212 /** 213 * Clone a remote repository. 214 * 215 * By default this creates its repository and initial remote to match 216 * git's defaults. You can use the options in the callback to 217 * customize how these are created. 218 * 219 * Params: 220 * out_ = pointer that will receive the resulting repository object 221 * url = the remote repository to clone 222 * local_path = local directory to clone to 223 * options = configuration options for the clone. If null, the function works as though GIT_OPTIONS_INIT were passed. 224 * 225 * Returns: 0 on success, any non-zero return value from a callback function, or a negative value to indicate an error (use `git_error_last` for a detailed error message) 226 */ 227 //GIT_EXTERN 228 int git_clone(libgit2_d.types.git_repository** out_, const (char)* url, const (char)* local_path, const (.git_clone_options)* options); 229 230 /** @} */