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 /** 58 * The signature of a function matching git_remote_create, with an additional 59 * void* as a callback payload. 60 * 61 * Callers of git_clone may provide a function matching this signature to 62 * override the remote creation and customization process during a clone 63 * operation. 64 * 65 * @param out_ the resulting remote 66 * @param repo the repository in which to create the remote 67 * @param name the remote's name 68 * @param url the remote's url 69 * @param payload an opaque payload 70 * @return 0, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EEXISTS or an error code 71 */ 72 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); 73 74 /** 75 * The signature of a function matchin git_repository_init, with an 76 * aditional void * as callback payload. 77 * 78 * Callers of git_clone my provide a function matching this signature 79 * to override the repository creation and customization process 80 * during a clone operation. 81 * 82 * @param out_ the resulting repository 83 * @param path path in which to create the repository 84 * @param bare whether the repository is bare. This is the value from the clone 85 * options 86 * @param payload payload specified by the options 87 * @return 0, or a negative value to indicate error 88 */ 89 alias git_repository_create_cb = int function(libgit2_d.types.git_repository** out_, const (char)* path, int bare, void* payload); 90 91 /** 92 * Clone options structure 93 * 94 * Initialize with `GIT_CLONE_OPTIONS_INIT`. Alternatively, you can 95 * use `git_clone_options_init`. 96 */ 97 struct git_clone_options 98 { 99 uint version_; 100 101 /** 102 * These options are passed to the checkout step. To disable 103 * checkout, set the `checkout_strategy` to 104 * `git_checkout_strategy_t.GIT_CHECKOUT_NONE`. 105 */ 106 libgit2_d.checkout.git_checkout_options checkout_opts; 107 108 /** 109 * Options which control the fetch, including callbacks. 110 * 111 * The callbacks are used for reporting fetch progress, and for acquiring 112 * credentials in the event they are needed. 113 */ 114 libgit2_d.remote.git_fetch_options fetch_opts; 115 116 /** 117 * Set to zero (false) to create a standard repo, or non-zero 118 * for a bare repo 119 */ 120 int bare; 121 122 /** 123 * Whether to use a fetch or copy the object database. 124 */ 125 .git_clone_local_t local; 126 127 /** 128 * The name of the branch to checkout. null means use the 129 * remote's default branch. 130 */ 131 const (char)* checkout_branch; 132 133 /** 134 * A callback used to create the new repository into which to 135 * clone. If null, the 'bare' field will be used to determine 136 * whether to create a bare repository. 137 */ 138 .git_repository_create_cb repository_cb; 139 140 /** 141 * An opaque payload to pass to the libgit2_d.types.git_repository creation callback. 142 * This parameter is ignored unless repository_cb is non-null. 143 */ 144 void* repository_cb_payload; 145 146 /** 147 * A callback used to create the git_remote, prior to its being 148 * used to perform the clone operation. See the documentation for 149 * git_remote_create_cb for details. This parameter may be null, 150 * indicating that git_clone should provide default behavior. 151 */ 152 .git_remote_create_cb remote_cb; 153 154 /** 155 * An opaque payload to pass to the git_remote creation callback. 156 * This parameter is ignored unless remote_cb is non-null. 157 */ 158 void* remote_cb_payload; 159 } 160 161 enum GIT_CLONE_OPTIONS_VERSION = 1; 162 163 pragma(inline, true) 164 pure nothrow @safe @nogc 165 .git_clone_options GIT_CLONE_OPTIONS_INIT() 166 167 do 168 { 169 libgit2_d.checkout.git_checkout_options CHECKOUT_OPTION = 170 { 171 version_: libgit2_d.checkout.GIT_CHECKOUT_OPTIONS_VERSION, 172 checkout_strategy: libgit2_d.checkout.git_checkout_strategy_t.GIT_CHECKOUT_SAFE, 173 }; 174 175 .git_clone_options OUTPUT = 176 { 177 version_: .GIT_CLONE_OPTIONS_VERSION, 178 checkout_opts: CHECKOUT_OPTION, 179 fetch_opts: libgit2_d.remote.GIT_FETCH_OPTIONS_INIT(), 180 }; 181 182 return OUTPUT; 183 } 184 185 /** 186 * Initialize git_clone_options structure 187 * 188 * Initializes a `git_clone_options` with default values. Equivalent to creating 189 * an instance with GIT_CLONE_OPTIONS_INIT. 190 * 191 * @param opts The `git_clone_options` struct to initialize. 192 * @param version The struct version; pass `GIT_CLONE_OPTIONS_VERSION`. 193 * @return Zero on success; -1 on failure. 194 */ 195 //GIT_EXTERN 196 int git_clone_options_init(.git_clone_options* opts, uint version_); 197 198 /** 199 * Clone a remote repository. 200 * 201 * By default this creates its repository and initial remote to match 202 * git's defaults. You can use the options in the callback to 203 * customize how these are created. 204 * 205 * @param out_ pointer that will receive the resulting repository object 206 * @param url the remote repository to clone 207 * @param local_path local directory to clone to 208 * @param options configuration options for the clone. If null, the 209 * function works as though GIT_OPTIONS_INIT were passed. 210 * @return 0 on success, any non-zero return value from a callback 211 * function, or a negative value to indicate an error (use 212 * `git_error_last` for a detailed error message) 213 */ 214 //GIT_EXTERN 215 int git_clone(libgit2_d.types.git_repository** out_, const (char)* url, const (char)* local_path, const (.git_clone_options)* options); 216 217 /** @} */