Commit 18b2d560d376da8bcb601603346b871c05958772

Ben Straub 2012-12-14T13:03:59

Deploy git_clone_options; remove git_clone_bare

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
diff --git a/include/git2/clone.h b/include/git2/clone.h
index 5dcfeeb..92fcf7f 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -32,7 +32,9 @@ GIT_BEGIN_DECL
  *
  * - `out` is a pointer that receives the resulting repository object
  * - `origin_remote` is a remote which will act as the initial fetch source
- * - `workdir_path` is local directory to clone to
+ * - `local_path` is local directory to clone into
+ * - `bare` should be set to zero to create a standard repo, non-zero for
+ *   a bare repo
  * - `fetch_progress_cb` is optional callback for fetch progress. Be aware that
  *   this is called inline with network and indexing operations, so performance
  *   may be affected.
@@ -46,10 +48,11 @@ typedef struct git_clone_options {
 
 	git_repository **out;
 	git_remote *origin_remote;
-	const char *workdir_path;
-	git_checkout_opts *checkout_opts;
+	const char *local_path;
+	int bare;
 	git_transfer_progress_callback fetch_progress_cb;
 	void *fetch_progress_payload;
+	git_checkout_opts *checkout_opts;
 } git_clone_options;
 
 #define GIT_CLONE_OPTIONS_VERSION 1
@@ -59,44 +62,11 @@ typedef struct git_clone_options {
  * Clone a remote repository, and checkout the branch pointed to by the remote
  * HEAD.
  *
- * @param out pointer that will receive the resulting repository object
- * @param origin_remote a remote which will act as the initial fetch source
- * @param workdir_path local directory to clone to
- * @param fetch_progress_cb optional callback for fetch progress. Be aware that
- * this is called inline with network and indexing operations, so performance
- * may be affected.
- * @param fetch_progress_payload payload for fetch_progress_cb
- * @param checkout_opts options for the checkout step. If NULL, no checkout
- * is performed
+ * @param options configuration options for the clone
  * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
  * about the error)
  */
-GIT_EXTERN(int) git_clone(
-		git_repository **out,
-		git_remote *origin_remote,
-		const char *workdir_path,
-		git_checkout_opts *checkout_opts,
-		git_transfer_progress_callback fetch_progress_cb,
-		void *fetch_progress_payload);
-
-/**
- * Create a bare clone of a remote repository.
- *
- * @param out pointer that will receive the resulting repository object
- * @param origin_remote a remote which will act as the initial fetch source
- * @param dest_path local directory to clone to
- * @param fetch_progress_cb optional callback for fetch progress. Be aware that
- * this is called inline with network and indexing operations, so performance
- * may be affected.
- * @param fetch_progress_payload payload for fetch_progress_cb
- * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information about the error)
- */
-GIT_EXTERN(int) git_clone_bare(
-		git_repository **out,
-		git_remote *origin_remote,
-		const char *dest_path,
-		git_transfer_progress_callback fetch_progress_cb,
-		void *fetch_progress_payload);
+GIT_EXTERN(int) git_clone(git_clone_options *options);
 
 /** @} */
 GIT_END_DECL
diff --git a/src/clone.c b/src/clone.c
index aa6c43f..ab22d9e 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -355,42 +355,18 @@ static int clone_internal(
 	return retcode;
 }
 
-int git_clone_bare(
-		git_repository **out,
-		git_remote *origin_remote,
-		const char *dest_path,
-		git_transfer_progress_callback fetch_progress_cb,
-		void *fetch_progress_payload)
+int git_clone(git_clone_options *options)
 {
-	assert(out && origin_remote && dest_path);
+	assert(options && options->out && options->origin_remote && options->local_path);
 
-	return clone_internal(
-		out,
-		origin_remote,
-		dest_path,
-		fetch_progress_cb,
-		fetch_progress_payload,
-		NULL,
-		1);
-}
-
-
-int git_clone(
-		git_repository **out,
-		git_remote *origin_remote,
-		const char *workdir_path,
-		git_checkout_opts *checkout_opts,
-		git_transfer_progress_callback fetch_progress_cb,
-		void *fetch_progress_payload)
-{
-	assert(out && origin_remote && workdir_path);
+	GITERR_CHECK_VERSION(options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options");
 
 	return clone_internal(
-		out,
-		origin_remote,
-		workdir_path,
-		fetch_progress_cb,
-		fetch_progress_payload,
-		checkout_opts,
-		0);
+		options->out,
+		options->origin_remote,
+		options->local_path,
+		options->fetch_progress_cb,
+		options->fetch_progress_payload,
+		options->checkout_opts,
+		options->bare ? 1 : 0);
 }
diff --git a/tests-clar/clone/network.c b/tests-clar/clone/network.c
index 15ad95b..49b57bb 100644
--- a/tests-clar/clone/network.c
+++ b/tests-clar/clone/network.c
@@ -9,18 +9,22 @@ CL_IN_CATEGORY("network")
 #define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
 
 static git_repository *g_repo;
-static git_remote *g_origin;
+static git_clone_options g_options;
 
 void test_clone_network__initialize(void)
 {
 	g_repo = NULL;
-	cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH));
+
+	memset(&g_options, 0, sizeof(git_clone_options));
+	g_options.version = GIT_CLONE_OPTIONS_VERSION;
+	g_options.out = &g_repo;
+	g_options.local_path = "./foo";
+	cl_git_pass(git_remote_new(&g_options.origin_remote, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH));
 }
 
 void test_clone_network__cleanup(void)
 {
-	git_remote_free(g_origin);
-	g_origin = NULL;
+	git_remote_free(g_options.origin_remote);
 }
 
 static void cleanup_repository(void *path)
@@ -37,9 +41,9 @@ void test_clone_network__network_full(void)
 {
 	git_remote *origin;
 
-	cl_set_cleanup(&cleanup_repository, "./test2");
+	cl_set_cleanup(&cleanup_repository, "./foo");
 
-	cl_git_pass(git_clone(&g_repo, g_origin, "./test2", NULL, NULL, NULL));
+	cl_git_pass(git_clone(&g_options));
 	cl_assert(!git_repository_is_bare(g_repo));
 	cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
 
@@ -51,9 +55,10 @@ void test_clone_network__network_bare(void)
 {
 	git_remote *origin;
 
-	cl_set_cleanup(&cleanup_repository, "./test");
+	cl_set_cleanup(&cleanup_repository, "./foo");
+	g_options.bare = true;
 
-	cl_git_pass(git_clone_bare(&g_repo, g_origin, "./test", NULL, NULL));
+	cl_git_pass(git_clone(&g_options));
 	cl_assert(git_repository_is_bare(g_repo));
 	cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
 
@@ -65,7 +70,7 @@ void test_clone_network__cope_with_already_existing_directory(void)
 	cl_set_cleanup(&cleanup_repository, "./foo");
 
 	p_mkdir("./foo", GIT_DIR_MODE);
-	cl_git_pass(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL));
+	cl_git_pass(git_clone(&g_options));
 	git_repository_free(g_repo); g_repo = NULL;
 }
 
@@ -73,12 +78,12 @@ void test_clone_network__empty_repository(void)
 {
 	git_reference *head;
 
-	cl_set_cleanup(&cleanup_repository, "./empty");
+	cl_set_cleanup(&cleanup_repository, "./foo");
 
-	git_remote_free(g_origin);
-	cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_EMPTYREPO_URL, GIT_REMOTE_DEFAULT_FETCH));
+	git_remote_free(g_options.origin_remote);
+	cl_git_pass(git_remote_new(&g_options.origin_remote, NULL, "origin", LIVE_EMPTYREPO_URL, GIT_REMOTE_DEFAULT_FETCH));
 
-	cl_git_pass(git_clone(&g_repo, g_origin, "./empty", NULL, NULL, NULL));
+	cl_git_pass(git_clone(&g_options));
 
 	cl_assert_equal_i(true, git_repository_is_empty(g_repo));
 	cl_assert_equal_i(true, git_repository_head_orphan(g_repo));
@@ -93,10 +98,9 @@ void test_clone_network__empty_repository(void)
 void test_clone_network__can_prevent_the_checkout_of_a_standard_repo(void)
 {
 	git_buf path = GIT_BUF_INIT;
+	cl_set_cleanup(&cleanup_repository, "./foo");
 
-	cl_set_cleanup(&cleanup_repository, "./no-checkout");
-
-	cl_git_pass(git_clone(&g_repo, g_origin, "./no-checkout", NULL, NULL, NULL));
+	cl_git_pass(git_clone(&g_options));
 
 	cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
 	cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&path)));
@@ -129,11 +133,13 @@ void test_clone_network__can_checkout_a_cloned_repo(void)
 	opts.checkout_strategy = GIT_CHECKOUT_SAFE;
 	opts.progress_cb = &checkout_progress;
 	opts.progress_payload = &checkout_progress_cb_was_called;
+	g_options.checkout_opts = &opts;
+	g_options.fetch_progress_cb = &fetch_progress;
+	g_options.fetch_progress_payload = &fetch_progress_cb_was_called;
 
-	cl_set_cleanup(&cleanup_repository, "./default-checkout");
+	cl_set_cleanup(&cleanup_repository, "./foo");
 
-	cl_git_pass(git_clone(&g_repo, g_origin, "./default-checkout", &opts,
-				&fetch_progress, &fetch_progress_cb_was_called));
+	cl_git_pass(git_clone(&g_options));
 
 	cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
 	cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&path)));
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
index 983f9fb..3626c54 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -5,19 +5,23 @@
 
 #define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
 
+static git_clone_options g_options;
 static git_repository *g_repo;
-static git_remote *g_origin = NULL;
 
 void test_clone_nonetwork__initialize(void)
 {
 	g_repo = NULL;
-	cl_git_pass(git_remote_new(&g_origin, NULL, "origin", cl_git_fixture_url("testrepo.git"), GIT_REMOTE_DEFAULT_FETCH));
+
+	memset(&g_options, 0, sizeof(git_clone_options));
+	g_options.version = GIT_CLONE_OPTIONS_VERSION;
+	g_options.out = &g_repo;
+	g_options.local_path = "./foo";
+	cl_git_pass(git_remote_new(&g_options.origin_remote, NULL, "origin", cl_git_fixture_url("testrepo.git"), GIT_REMOTE_DEFAULT_FETCH));
 }
 
 void test_clone_nonetwork__cleanup(void)
 {
-	git_remote_free(g_origin);
-	g_origin = NULL;
+	git_remote_free(g_options.origin_remote);
 }
 
 static void cleanup_repository(void *path)
@@ -33,38 +37,38 @@ static void cleanup_repository(void *path)
 void test_clone_nonetwork__bad_url(void)
 {
 	/* Clone should clean up the mess if the URL isn't a git repository */
-	git_remote_free(g_origin);
-	cl_git_pass(git_remote_new(&g_origin, NULL, "origin", "not_a_repo", GIT_REMOTE_DEFAULT_FETCH));
+	git_remote_free(g_options.origin_remote);
+	cl_git_pass(git_remote_new(&g_options.origin_remote, NULL, "origin", "not_a_repo", GIT_REMOTE_DEFAULT_FETCH));
 
-	cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL));
+	cl_git_fail(git_clone(&g_options));
+	cl_assert(!git_path_exists("./foo"));
+	g_options.bare = true;
+	cl_git_fail(git_clone(&g_options));
 	cl_assert(!git_path_exists("./foo"));
-	cl_git_fail(git_clone_bare(&g_repo, g_origin, "./foo.git", NULL, NULL));
-	cl_assert(!git_path_exists("./foo.git"));
 }
 
 void test_clone_nonetwork__local(void)
 {
-	cl_set_cleanup(&cleanup_repository, "./local");
-
-	cl_git_pass(git_clone(&g_repo, g_origin, "./local", NULL, NULL, NULL));
+	cl_set_cleanup(&cleanup_repository, "./foo");
+	cl_git_pass(git_clone(&g_options));
 }
 
 void test_clone_nonetwork__local_absolute_path(void)
 {
 	const char *local_src = cl_fixture("testrepo.git");
-	git_remote *local = NULL;
-	cl_set_cleanup(&cleanup_repository, "./local");
+	git_remote_free(g_options.origin_remote);
+	cl_git_pass(git_remote_new(&g_options.origin_remote, NULL, "origin", local_src, GIT_REMOTE_DEFAULT_FETCH));
 
-	cl_git_pass(git_remote_new(&local, NULL, "origin", local_src, GIT_REMOTE_DEFAULT_FETCH));
-	cl_git_pass(git_clone(&g_repo, local, "./local", NULL, NULL, NULL));
-	git_remote_free(local);
+	cl_set_cleanup(&cleanup_repository, "./foo");
+
+	cl_git_pass(git_clone(&g_options));
 }
 
 void test_clone_nonetwork__local_bare(void)
 {
-	cl_set_cleanup(&cleanup_repository, "./local.git");
-
-	cl_git_pass(git_clone_bare(&g_repo, g_origin, "./local.git", NULL, NULL));
+	cl_set_cleanup(&cleanup_repository, "./foo");
+	g_options.bare = true;
+	cl_git_pass(git_clone(&g_options));
 }
 
 void test_clone_nonetwork__fail_when_the_target_is_a_file(void)
@@ -72,7 +76,7 @@ void test_clone_nonetwork__fail_when_the_target_is_a_file(void)
 	cl_set_cleanup(&cleanup_repository, "./foo");
 
 	cl_git_mkfile("./foo", "Bar!");
-	cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL));
+	cl_git_fail(git_clone(&g_options));
 }
 
 void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(void)
@@ -81,5 +85,5 @@ void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(vo
 
 	p_mkdir("./foo", GIT_DIR_MODE);
 	cl_git_mkfile("./foo/bar", "Baz!");
-	cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL));
+	cl_git_fail(git_clone(&g_options));
 }
diff --git a/tests-clar/fetchhead/network.c b/tests-clar/fetchhead/network.c
index aed5b5a..b0d31c5 100644
--- a/tests-clar/fetchhead/network.c
+++ b/tests-clar/fetchhead/network.c
@@ -10,17 +10,22 @@ CL_IN_CATEGORY("network")
 #define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
 
 static git_repository *g_repo;
-static git_remote *g_origin;
+static git_clone_options g_options;
 
 void test_fetchhead_network__initialize(void)
 {
 	g_repo = NULL;
-	cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH));
+
+	memset(&g_options, 0, sizeof(git_clone_options));
+	g_options.version = GIT_CLONE_OPTIONS_VERSION;
+	g_options.out = &g_repo;
+	g_options.local_path = "./foo";
+	cl_git_pass(git_remote_new(&g_options.origin_remote, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH));
 }
 
 void test_fetchhead_network__cleanup(void)
 {
-	g_origin = NULL;
+	git_remote_free(g_options.origin_remote);
 }
 
 static void cleanup_repository(void *path)
@@ -36,9 +41,9 @@ static void cleanup_repository(void *path)
 
 static void fetchhead_test_clone(void)
 {
-	cl_set_cleanup(&cleanup_repository, "./test1");
+	cl_set_cleanup(&cleanup_repository, "./foo");
 
-	cl_git_pass(git_clone(&g_repo, g_origin, "./test1", NULL, NULL, NULL));
+	cl_git_pass(git_clone(&g_options));
 }
 
 static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fetchhead)
diff --git a/tests-clar/network/fetch.c b/tests-clar/network/fetch.c
index 246435b..83c8806 100644
--- a/tests-clar/network/fetch.c
+++ b/tests-clar/network/fetch.c
@@ -86,11 +86,16 @@ static void transferProgressCallback(const git_transfer_progress *stats, void *p
 void test_network_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date(void)
 {
 	git_repository *_repository;
-	git_remote *remote;
 	bool invoked = false;
+	git_remote *remote;
+	git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
+
+	opts.out = &_repository;
+	opts.local_path = "./fetch/lg2";
+	opts.bare = true;
+	cl_git_pass(git_remote_new(&opts.origin_remote, NULL, "origin", "https://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DEFAULT_FETCH));
 
-	cl_git_pass(git_remote_new(&remote, NULL, "origin", "https://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DEFAULT_FETCH));
-	cl_git_pass(git_clone_bare(&_repository, remote, "./fetch/lg2", NULL, NULL));
+	cl_git_pass(git_clone(&opts));
 	git_repository_free(_repository);
 
 	cl_git_pass(git_repository_open(&_repository, "./fetch/lg2"));
@@ -108,5 +113,6 @@ void test_network_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_dat
 	git_remote_disconnect(remote);
 
 	git_remote_free(remote);
+	git_remote_free(opts.origin_remote);
 	git_repository_free(_repository);
 }