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