Blame


1 86c3caaf 2018-03-09 stsp /*
2 86c3caaf 2018-03-09 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 86c3caaf 2018-03-09 stsp *
4 86c3caaf 2018-03-09 stsp * Permission to use, copy, modify, and distribute this software for any
5 86c3caaf 2018-03-09 stsp * purpose with or without fee is hereby granted, provided that the above
6 86c3caaf 2018-03-09 stsp * copyright notice and this permission notice appear in all copies.
7 86c3caaf 2018-03-09 stsp *
8 86c3caaf 2018-03-09 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 86c3caaf 2018-03-09 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 86c3caaf 2018-03-09 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 86c3caaf 2018-03-09 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 86c3caaf 2018-03-09 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 86c3caaf 2018-03-09 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 86c3caaf 2018-03-09 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 86c3caaf 2018-03-09 stsp */
16 86c3caaf 2018-03-09 stsp
17 86c3caaf 2018-03-09 stsp #include <sys/param.h>
18 86c3caaf 2018-03-09 stsp #include <sys/queue.h>
19 86c3caaf 2018-03-09 stsp #include <sys/limits.h>
20 0da17012 2018-03-09 stsp #include <sys/stat.h>
21 86c3caaf 2018-03-09 stsp
22 86c3caaf 2018-03-09 stsp #include <stdarg.h>
23 86c3caaf 2018-03-09 stsp #include <stdio.h>
24 86c3caaf 2018-03-09 stsp #include <stdlib.h>
25 86c3caaf 2018-03-09 stsp #include <string.h>
26 86c3caaf 2018-03-09 stsp #include <unistd.h>
27 0da17012 2018-03-09 stsp #include <errno.h>
28 3962e86a 2018-03-11 stsp #include <util.h>
29 86c3caaf 2018-03-09 stsp
30 86c3caaf 2018-03-09 stsp #include "got_error.h"
31 86c3caaf 2018-03-09 stsp #include "got_object.h"
32 86c3caaf 2018-03-09 stsp #include "got_refs.h"
33 86c3caaf 2018-03-09 stsp #include "got_repository.h"
34 86c3caaf 2018-03-09 stsp #include "got_worktree.h"
35 86c3caaf 2018-03-09 stsp
36 86c3caaf 2018-03-09 stsp #include "got_worktree_priv.h"
37 0da17012 2018-03-09 stsp #include "got_path_priv.h"
38 86c3caaf 2018-03-09 stsp
39 86c3caaf 2018-03-09 stsp #define GOT_REPO_PATH "../../../"
40 86c3caaf 2018-03-09 stsp
41 86c3caaf 2018-03-09 stsp static int verbose;
42 86c3caaf 2018-03-09 stsp
43 86c3caaf 2018-03-09 stsp void
44 86c3caaf 2018-03-09 stsp test_printf(char *fmt, ...)
45 86c3caaf 2018-03-09 stsp {
46 86c3caaf 2018-03-09 stsp va_list ap;
47 86c3caaf 2018-03-09 stsp
48 86c3caaf 2018-03-09 stsp if (!verbose)
49 86c3caaf 2018-03-09 stsp return;
50 86c3caaf 2018-03-09 stsp
51 86c3caaf 2018-03-09 stsp va_start(ap, fmt);
52 86c3caaf 2018-03-09 stsp vprintf(fmt, ap);
53 86c3caaf 2018-03-09 stsp va_end(ap);
54 86c3caaf 2018-03-09 stsp }
55 86c3caaf 2018-03-09 stsp
56 86c3caaf 2018-03-09 stsp static int
57 91c986ef 2018-03-09 stsp remove_got_dir(const char *worktree_path)
58 91c986ef 2018-03-09 stsp {
59 91c986ef 2018-03-09 stsp char *path;
60 91c986ef 2018-03-09 stsp
61 91c986ef 2018-03-09 stsp if (asprintf(&path, "%s/%s", worktree_path, GOT_WORKTREE_GOT_DIR) == -1)
62 91c986ef 2018-03-09 stsp return 0;
63 91c986ef 2018-03-09 stsp rmdir(path);
64 91c986ef 2018-03-09 stsp free(path);
65 91c986ef 2018-03-09 stsp return 1;
66 91c986ef 2018-03-09 stsp }
67 91c986ef 2018-03-09 stsp
68 91c986ef 2018-03-09 stsp static int
69 91c986ef 2018-03-09 stsp remove_meta_file(const char *worktree_path, const char *name)
70 91c986ef 2018-03-09 stsp {
71 91c986ef 2018-03-09 stsp char *path;
72 91c986ef 2018-03-09 stsp
73 91c986ef 2018-03-09 stsp if (asprintf(&path, "%s/%s/%s", worktree_path, GOT_WORKTREE_GOT_DIR,
74 91c986ef 2018-03-09 stsp name) == -1)
75 91c986ef 2018-03-09 stsp return 0;
76 91c986ef 2018-03-09 stsp unlink(path);
77 91c986ef 2018-03-09 stsp free(path);
78 91c986ef 2018-03-09 stsp return 1;
79 91c986ef 2018-03-09 stsp }
80 91c986ef 2018-03-09 stsp
81 45d8e5fd 2018-03-11 stsp static int
82 b18d25df 2018-03-11 stsp remove_worktree(const char *worktree_path)
83 91c986ef 2018-03-09 stsp {
84 fdf001a7 2018-03-11 stsp if (!remove_meta_file(worktree_path, GOT_WORKTREE_HEAD))
85 45d8e5fd 2018-03-11 stsp return 0;
86 45d8e5fd 2018-03-11 stsp if (!remove_meta_file(worktree_path, GOT_WORKTREE_FILE_INDEX))
87 45d8e5fd 2018-03-11 stsp return 0;
88 45d8e5fd 2018-03-11 stsp if (!remove_meta_file(worktree_path, GOT_WORKTREE_REPOSITORY))
89 45d8e5fd 2018-03-11 stsp return 0;
90 45d8e5fd 2018-03-11 stsp if (!remove_meta_file(worktree_path, GOT_WORKTREE_PATH_PREFIX))
91 45d8e5fd 2018-03-11 stsp return 0;
92 e350ead3 2018-03-11 stsp if (!remove_meta_file(worktree_path, GOT_WORKTREE_BASE_COMMIT))
93 e350ead3 2018-03-11 stsp return 0;
94 45d8e5fd 2018-03-11 stsp if (!remove_meta_file(worktree_path, GOT_WORKTREE_LOCK))
95 45d8e5fd 2018-03-11 stsp return 0;
96 45d8e5fd 2018-03-11 stsp if (!remove_meta_file(worktree_path, GOT_WORKTREE_FORMAT))
97 45d8e5fd 2018-03-11 stsp return 0;
98 45d8e5fd 2018-03-11 stsp if (!remove_got_dir(worktree_path))
99 45d8e5fd 2018-03-11 stsp return 0;
100 45d8e5fd 2018-03-11 stsp if (rmdir(worktree_path) == -1)
101 45d8e5fd 2018-03-11 stsp return 0;
102 45d8e5fd 2018-03-11 stsp return 1;
103 3962e86a 2018-03-11 stsp }
104 3962e86a 2018-03-11 stsp
105 3962e86a 2018-03-11 stsp static int
106 3962e86a 2018-03-11 stsp read_meta_file(char **content, const char *path)
107 3962e86a 2018-03-11 stsp {
108 3962e86a 2018-03-11 stsp FILE *f;
109 3962e86a 2018-03-11 stsp size_t n;
110 3962e86a 2018-03-11 stsp size_t len;
111 3962e86a 2018-03-11 stsp const char delim[3] = {'\0', '\0', '\0'};
112 3962e86a 2018-03-11 stsp int ret = 0;
113 3962e86a 2018-03-11 stsp
114 3962e86a 2018-03-11 stsp f = fopen(path, "r");
115 3962e86a 2018-03-11 stsp if (f == NULL)
116 3962e86a 2018-03-11 stsp return errno;
117 3962e86a 2018-03-11 stsp
118 3962e86a 2018-03-11 stsp *content = fparseln(f, &len, NULL, delim, 0);
119 3962e86a 2018-03-11 stsp if (*content == NULL)
120 3962e86a 2018-03-11 stsp ret = errno;
121 3962e86a 2018-03-11 stsp fclose(f);
122 3962e86a 2018-03-11 stsp return ret;
123 91c986ef 2018-03-09 stsp }
124 91c986ef 2018-03-09 stsp
125 91c986ef 2018-03-09 stsp static int
126 86c3caaf 2018-03-09 stsp check_meta_file_exists(const char *worktree_path, const char *name)
127 86c3caaf 2018-03-09 stsp {
128 07a7f8ad 2018-03-11 stsp struct stat sb;
129 86c3caaf 2018-03-09 stsp char *path;
130 5de261fe 2018-03-11 stsp int ret = 0;
131 86c3caaf 2018-03-09 stsp
132 86c3caaf 2018-03-09 stsp if (asprintf(&path, "%s/%s/%s", worktree_path, GOT_WORKTREE_GOT_DIR,
133 86c3caaf 2018-03-09 stsp name) == -1)
134 86c3caaf 2018-03-09 stsp return 0;
135 5de261fe 2018-03-11 stsp if (stat(path, &sb) == 0)
136 5de261fe 2018-03-11 stsp ret = 1;
137 3962e86a 2018-03-11 stsp if (verbose) {
138 3962e86a 2018-03-11 stsp char *content;
139 3962e86a 2018-03-11 stsp if (read_meta_file(&content, path) == 0) {
140 3962e86a 2018-03-11 stsp test_printf("%s:\t%s\n", name, content);
141 3962e86a 2018-03-11 stsp free(content);
142 3962e86a 2018-03-11 stsp }
143 3962e86a 2018-03-11 stsp }
144 5de261fe 2018-03-11 stsp free(path);
145 5de261fe 2018-03-11 stsp return ret;
146 86c3caaf 2018-03-09 stsp }
147 86c3caaf 2018-03-09 stsp
148 86c3caaf 2018-03-09 stsp static int
149 86c3caaf 2018-03-09 stsp worktree_init(const char *repo_path)
150 86c3caaf 2018-03-09 stsp {
151 86c3caaf 2018-03-09 stsp const struct got_error *err;
152 86c3caaf 2018-03-09 stsp struct got_repository *repo = NULL;
153 86c3caaf 2018-03-09 stsp struct got_reference *head_ref = NULL;
154 86c3caaf 2018-03-09 stsp char worktree_path[PATH_MAX];
155 86c3caaf 2018-03-09 stsp int ok = 0;
156 86c3caaf 2018-03-09 stsp
157 86c3caaf 2018-03-09 stsp err = got_repo_open(&repo, repo_path);
158 86c3caaf 2018-03-09 stsp if (err != NULL || repo == NULL)
159 86c3caaf 2018-03-09 stsp goto done;
160 86c3caaf 2018-03-09 stsp err = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
161 86c3caaf 2018-03-09 stsp if (err != NULL || head_ref == NULL)
162 86c3caaf 2018-03-09 stsp goto done;
163 86c3caaf 2018-03-09 stsp
164 86c3caaf 2018-03-09 stsp strlcpy(worktree_path, "worktree-XXXXXX", sizeof(worktree_path));
165 86c3caaf 2018-03-09 stsp if (mkdtemp(worktree_path) == NULL)
166 86c3caaf 2018-03-09 stsp goto done;
167 86c3caaf 2018-03-09 stsp
168 577ec78f 2018-03-11 stsp err = got_worktree_init(worktree_path, head_ref, "/", repo);
169 86c3caaf 2018-03-09 stsp if (err != NULL)
170 86c3caaf 2018-03-09 stsp goto done;
171 86c3caaf 2018-03-09 stsp
172 86c3caaf 2018-03-09 stsp /* Ensure required files were created. */
173 fdf001a7 2018-03-11 stsp if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_HEAD))
174 86c3caaf 2018-03-09 stsp goto done;
175 056e7441 2018-03-11 stsp if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_LOCK))
176 056e7441 2018-03-11 stsp goto done;
177 e350ead3 2018-03-11 stsp if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_BASE_COMMIT))
178 e350ead3 2018-03-11 stsp goto done;
179 86c3caaf 2018-03-09 stsp if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_FILE_INDEX))
180 86c3caaf 2018-03-09 stsp goto done;
181 86c3caaf 2018-03-09 stsp if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_REPOSITORY))
182 86c3caaf 2018-03-09 stsp goto done;
183 577ec78f 2018-03-11 stsp if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_PATH_PREFIX))
184 577ec78f 2018-03-11 stsp goto done;
185 1451e70d 2018-03-10 stsp if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_FORMAT))
186 1451e70d 2018-03-10 stsp goto done;
187 45d8e5fd 2018-03-11 stsp
188 45d8e5fd 2018-03-11 stsp if (!remove_worktree(worktree_path))
189 45d8e5fd 2018-03-11 stsp goto done;
190 86c3caaf 2018-03-09 stsp ok = 1;
191 86c3caaf 2018-03-09 stsp done:
192 86c3caaf 2018-03-09 stsp if (head_ref)
193 86c3caaf 2018-03-09 stsp got_ref_close(head_ref);
194 86c3caaf 2018-03-09 stsp if (repo)
195 86c3caaf 2018-03-09 stsp got_repo_close(repo);
196 86c3caaf 2018-03-09 stsp return ok;
197 86c3caaf 2018-03-09 stsp }
198 86c3caaf 2018-03-09 stsp
199 0da17012 2018-03-09 stsp static int
200 0da17012 2018-03-09 stsp obstruct_meta_file(char **path, const char *worktree_path, const char *name)
201 0da17012 2018-03-09 stsp {
202 0da17012 2018-03-09 stsp FILE *f;
203 0da17012 2018-03-09 stsp char *s = "This file should not be here\n";
204 6b7476e9 2018-03-11 stsp int ret = 1;
205 0da17012 2018-03-09 stsp
206 0da17012 2018-03-09 stsp if (asprintf(path, "%s/%s/%s", worktree_path, GOT_WORKTREE_GOT_DIR,
207 0da17012 2018-03-09 stsp name) == -1)
208 0da17012 2018-03-09 stsp return 0;
209 0da17012 2018-03-09 stsp f = fopen(*path, "w+");
210 0da17012 2018-03-09 stsp if (f == NULL) {
211 0da17012 2018-03-09 stsp free(*path);
212 0da17012 2018-03-09 stsp return 0;
213 0da17012 2018-03-09 stsp }
214 0da17012 2018-03-09 stsp if (fwrite(s, 1, strlen(s), f) != strlen(s)) {
215 0da17012 2018-03-09 stsp free(*path);
216 6b7476e9 2018-03-11 stsp ret = 0;
217 0da17012 2018-03-09 stsp }
218 0da17012 2018-03-09 stsp fclose(f);
219 6b7476e9 2018-03-11 stsp return ret;
220 0da17012 2018-03-09 stsp }
221 0da17012 2018-03-09 stsp
222 0da17012 2018-03-09 stsp static int
223 8eac252b 2018-03-11 stsp obstruct_meta_file_and_init(int *ok, struct got_repository *repo,
224 8eac252b 2018-03-11 stsp const char *worktree_path, char *name)
225 8eac252b 2018-03-11 stsp {
226 8eac252b 2018-03-11 stsp const struct got_error *err;
227 8eac252b 2018-03-11 stsp char *path;
228 8eac252b 2018-03-11 stsp int ret = 0;
229 8eac252b 2018-03-11 stsp struct got_reference *head_ref = NULL;
230 8eac252b 2018-03-11 stsp
231 8eac252b 2018-03-11 stsp if (!obstruct_meta_file(&path, worktree_path, GOT_WORKTREE_FILE_INDEX))
232 8eac252b 2018-03-11 stsp return 0;
233 8eac252b 2018-03-11 stsp
234 8eac252b 2018-03-11 stsp err = got_ref_open(&head_ref, repo, GOT_REF_HEAD);
235 8eac252b 2018-03-11 stsp if (err != NULL || head_ref == NULL)
236 8eac252b 2018-03-11 stsp return 0;
237 8eac252b 2018-03-11 stsp
238 8eac252b 2018-03-11 stsp err = got_worktree_init(worktree_path, head_ref, "/", repo);
239 8eac252b 2018-03-11 stsp if (err != NULL && err->code == GOT_ERR_ERRNO && errno == EEXIST) {
240 8eac252b 2018-03-11 stsp (*ok)++;
241 8eac252b 2018-03-11 stsp ret = 1;
242 8eac252b 2018-03-11 stsp }
243 8eac252b 2018-03-11 stsp unlink(path);
244 8eac252b 2018-03-11 stsp free(path);
245 8eac252b 2018-03-11 stsp got_ref_close(head_ref);
246 8eac252b 2018-03-11 stsp return ret;
247 8eac252b 2018-03-11 stsp }
248 8eac252b 2018-03-11 stsp
249 8eac252b 2018-03-11 stsp static int
250 0da17012 2018-03-09 stsp worktree_init_exists(const char *repo_path)
251 0da17012 2018-03-09 stsp {
252 0da17012 2018-03-09 stsp const struct got_error *err;
253 0da17012 2018-03-09 stsp struct got_repository *repo = NULL;
254 0da17012 2018-03-09 stsp char worktree_path[PATH_MAX];
255 91c986ef 2018-03-09 stsp char *gotpath = NULL;
256 0da17012 2018-03-09 stsp char *path;
257 0da17012 2018-03-09 stsp int ok = 0;
258 0da17012 2018-03-09 stsp FILE *f;
259 0da17012 2018-03-09 stsp
260 0da17012 2018-03-09 stsp err = got_repo_open(&repo, repo_path);
261 0da17012 2018-03-09 stsp if (err != NULL || repo == NULL)
262 0da17012 2018-03-09 stsp goto done;
263 0da17012 2018-03-09 stsp strlcpy(worktree_path, "worktree-XXXXXX", sizeof(worktree_path));
264 0da17012 2018-03-09 stsp if (mkdtemp(worktree_path) == NULL)
265 0da17012 2018-03-09 stsp goto done;
266 91c986ef 2018-03-09 stsp if (mkdir(worktree_path, GOT_DEFAULT_DIR_MODE) == -1 && errno != EEXIST)
267 91c986ef 2018-03-09 stsp goto done;
268 0da17012 2018-03-09 stsp
269 0da17012 2018-03-09 stsp if (asprintf(&gotpath, "%s/%s", worktree_path, GOT_WORKTREE_GOT_DIR)
270 0da17012 2018-03-09 stsp == -1)
271 0da17012 2018-03-09 stsp goto done;
272 0da17012 2018-03-09 stsp if (mkdir(gotpath, GOT_DEFAULT_DIR_MODE) == -1 && errno != EEXIST)
273 0da17012 2018-03-09 stsp goto done;
274 0da17012 2018-03-09 stsp
275 0da17012 2018-03-09 stsp /* Create files which got_worktree_init() will try to create as well. */
276 8eac252b 2018-03-11 stsp if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
277 fdf001a7 2018-03-11 stsp GOT_WORKTREE_HEAD))
278 0da17012 2018-03-09 stsp goto done;
279 8eac252b 2018-03-11 stsp if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
280 8eac252b 2018-03-11 stsp GOT_WORKTREE_LOCK))
281 056e7441 2018-03-11 stsp goto done;
282 8eac252b 2018-03-11 stsp if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
283 e350ead3 2018-03-11 stsp GOT_WORKTREE_BASE_COMMIT))
284 e350ead3 2018-03-11 stsp goto done;
285 e350ead3 2018-03-11 stsp if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
286 8eac252b 2018-03-11 stsp GOT_WORKTREE_FILE_INDEX))
287 0da17012 2018-03-09 stsp goto done;
288 8eac252b 2018-03-11 stsp if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
289 8eac252b 2018-03-11 stsp GOT_WORKTREE_REPOSITORY))
290 0da17012 2018-03-09 stsp goto done;
291 8eac252b 2018-03-11 stsp if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
292 8eac252b 2018-03-11 stsp GOT_WORKTREE_PATH_PREFIX))
293 577ec78f 2018-03-11 stsp goto done;
294 8eac252b 2018-03-11 stsp if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
295 8eac252b 2018-03-11 stsp GOT_WORKTREE_FORMAT))
296 1451e70d 2018-03-10 stsp goto done;
297 1451e70d 2018-03-10 stsp
298 0da17012 2018-03-09 stsp done:
299 0da17012 2018-03-09 stsp if (repo)
300 0da17012 2018-03-09 stsp got_repo_close(repo);
301 91c986ef 2018-03-09 stsp free(gotpath);
302 e350ead3 2018-03-11 stsp if (ok == 7)
303 b18d25df 2018-03-11 stsp remove_worktree(worktree_path);
304 e350ead3 2018-03-11 stsp return (ok == 7);
305 0da17012 2018-03-09 stsp }
306 0da17012 2018-03-09 stsp
307 86c3caaf 2018-03-09 stsp #define RUN_TEST(expr, name) \
308 86c3caaf 2018-03-09 stsp { test_ok = (expr); \
309 86c3caaf 2018-03-09 stsp printf("test %s %s\n", (name), test_ok ? "ok" : "failed"); \
310 86c3caaf 2018-03-09 stsp failure = (failure || !test_ok); }
311 86c3caaf 2018-03-09 stsp
312 86c3caaf 2018-03-09 stsp
313 86c3caaf 2018-03-09 stsp void
314 86c3caaf 2018-03-09 stsp usage(void)
315 86c3caaf 2018-03-09 stsp {
316 86c3caaf 2018-03-09 stsp fprintf(stderr, "usage: worktree_test [-v] [REPO_PATH]\n");
317 86c3caaf 2018-03-09 stsp }
318 86c3caaf 2018-03-09 stsp
319 86c3caaf 2018-03-09 stsp int
320 86c3caaf 2018-03-09 stsp main(int argc, char *argv[])
321 86c3caaf 2018-03-09 stsp {
322 86c3caaf 2018-03-09 stsp int test_ok = 0, failure = 0;
323 86c3caaf 2018-03-09 stsp const char *repo_path;
324 86c3caaf 2018-03-09 stsp int ch;
325 86c3caaf 2018-03-09 stsp int vflag = 0;
326 86c3caaf 2018-03-09 stsp
327 86c3caaf 2018-03-09 stsp while ((ch = getopt(argc, argv, "v")) != -1) {
328 86c3caaf 2018-03-09 stsp switch (ch) {
329 86c3caaf 2018-03-09 stsp case 'v':
330 86c3caaf 2018-03-09 stsp verbose = 1;
331 86c3caaf 2018-03-09 stsp break;
332 86c3caaf 2018-03-09 stsp default:
333 86c3caaf 2018-03-09 stsp usage();
334 86c3caaf 2018-03-09 stsp return 1;
335 86c3caaf 2018-03-09 stsp }
336 86c3caaf 2018-03-09 stsp }
337 86c3caaf 2018-03-09 stsp argc -= optind;
338 86c3caaf 2018-03-09 stsp argv += optind;
339 86c3caaf 2018-03-09 stsp
340 86c3caaf 2018-03-09 stsp if (argc == 0)
341 86c3caaf 2018-03-09 stsp repo_path = GOT_REPO_PATH;
342 86c3caaf 2018-03-09 stsp else if (argc == 1)
343 86c3caaf 2018-03-09 stsp repo_path = argv[0];
344 86c3caaf 2018-03-09 stsp else {
345 86c3caaf 2018-03-09 stsp usage();
346 86c3caaf 2018-03-09 stsp return 1;
347 86c3caaf 2018-03-09 stsp }
348 86c3caaf 2018-03-09 stsp
349 86c3caaf 2018-03-09 stsp RUN_TEST(worktree_init(repo_path), "init");
350 0da17012 2018-03-09 stsp RUN_TEST(worktree_init_exists(repo_path), "init exists");
351 86c3caaf 2018-03-09 stsp
352 86c3caaf 2018-03-09 stsp return failure ? 1 : 0;
353 86c3caaf 2018-03-09 stsp }