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