]>
Commit | Line | Data |
---|---|---|
d288a700 | 1 | #include "cache.h" |
e90fdc39 JS |
2 | #include "dir.h" |
3 | ||
4 | static int inside_git_dir = -1; | |
5 | static int inside_work_tree = -1; | |
d288a700 | 6 | |
d089ebaa | 7 | static int sanitary_path_copy(char *dst, const char *src) |
f332726e | 8 | { |
25fe217b | 9 | char *dst0; |
d089ebaa | 10 | |
25fe217b JS |
11 | if (has_dos_drive_prefix(src)) { |
12 | *dst++ = *src++; | |
13 | *dst++ = *src++; | |
14 | } | |
15 | dst0 = dst; | |
16 | ||
17 | if (is_dir_sep(*src)) { | |
d089ebaa | 18 | *dst++ = '/'; |
25fe217b | 19 | while (is_dir_sep(*src)) |
d089ebaa JH |
20 | src++; |
21 | } | |
22 | ||
f332726e | 23 | for (;;) { |
d089ebaa JH |
24 | char c = *src; |
25 | ||
26 | /* | |
27 | * A path component that begins with . could be | |
28 | * special: | |
29 | * (1) "." and ends -- ignore and terminate. | |
30 | * (2) "./" -- ignore them, eat slash and continue. | |
31 | * (3) ".." and ends -- strip one and terminate. | |
32 | * (4) "../" -- strip one, eat slash and continue. | |
33 | */ | |
34 | if (c == '.') { | |
4cd148d8 | 35 | if (!src[1]) { |
d089ebaa JH |
36 | /* (1) */ |
37 | src++; | |
25fe217b | 38 | } else if (is_dir_sep(src[1])) { |
d089ebaa JH |
39 | /* (2) */ |
40 | src += 2; | |
25fe217b | 41 | while (is_dir_sep(*src)) |
d089ebaa JH |
42 | src++; |
43 | continue; | |
4cd148d8 JS |
44 | } else if (src[1] == '.') { |
45 | if (!src[2]) { | |
d089ebaa JH |
46 | /* (3) */ |
47 | src += 2; | |
48 | goto up_one; | |
25fe217b | 49 | } else if (is_dir_sep(src[2])) { |
d089ebaa JH |
50 | /* (4) */ |
51 | src += 3; | |
25fe217b | 52 | while (is_dir_sep(*src)) |
d089ebaa JH |
53 | src++; |
54 | goto up_one; | |
55 | } | |
56 | } | |
f332726e | 57 | } |
d089ebaa JH |
58 | |
59 | /* copy up to the next '/', and eat all '/' */ | |
25fe217b | 60 | while ((c = *src++) != '\0' && !is_dir_sep(c)) |
d089ebaa | 61 | *dst++ = c; |
25fe217b JS |
62 | if (is_dir_sep(c)) { |
63 | *dst++ = '/'; | |
64 | while (is_dir_sep(c)) | |
d089ebaa JH |
65 | c = *src++; |
66 | src--; | |
67 | } else if (!c) | |
f332726e | 68 | break; |
f332726e | 69 | continue; |
d089ebaa JH |
70 | |
71 | up_one: | |
72 | /* | |
73 | * dst0..dst is prefix portion, and dst[-1] is '/'; | |
74 | * go up one level. | |
75 | */ | |
76 | dst -= 2; /* go past trailing '/' if any */ | |
77 | if (dst < dst0) | |
78 | return -1; | |
79 | while (1) { | |
80 | if (dst <= dst0) | |
81 | break; | |
82 | c = *dst--; | |
25fe217b | 83 | if (c == '/') { /* MinGW: cannot be '\\' anymore */ |
d089ebaa JH |
84 | dst += 2; |
85 | break; | |
86 | } | |
87 | } | |
f332726e | 88 | } |
d089ebaa JH |
89 | *dst = '\0'; |
90 | return 0; | |
91 | } | |
a6080a0a | 92 | |
d089ebaa JH |
93 | const char *prefix_path(const char *prefix, int len, const char *path) |
94 | { | |
95 | const char *orig = path; | |
96 | char *sanitized = xmalloc(len + strlen(path) + 1); | |
9a13ba1b | 97 | if (is_absolute_path(orig)) |
d089ebaa JH |
98 | strcpy(sanitized, path); |
99 | else { | |
100 | if (len) | |
101 | memcpy(sanitized, prefix, len); | |
102 | strcpy(sanitized + len, path); | |
f332726e | 103 | } |
d089ebaa JH |
104 | if (sanitary_path_copy(sanitized, sanitized)) |
105 | goto error_out; | |
9a13ba1b | 106 | if (is_absolute_path(orig)) { |
d089ebaa JH |
107 | const char *work_tree = get_git_work_tree(); |
108 | size_t len = strlen(work_tree); | |
109 | size_t total = strlen(sanitized) + 1; | |
110 | if (strncmp(sanitized, work_tree, len) || | |
111 | (sanitized[len] != '\0' && sanitized[len] != '/')) { | |
112 | error_out: | |
113 | error("'%s' is outside repository", orig); | |
114 | free(sanitized); | |
115 | return NULL; | |
116 | } | |
117 | if (sanitized[len] == '/') | |
118 | len++; | |
119 | memmove(sanitized, sanitized + len, total - len); | |
120 | } | |
121 | return sanitized; | |
f332726e LT |
122 | } |
123 | ||
a6080a0a | 124 | /* |
4ca06608 JH |
125 | * Unlike prefix_path, this should be used if the named file does |
126 | * not have to interact with index entry; i.e. name of a random file | |
127 | * on the filesystem. | |
128 | */ | |
129 | const char *prefix_filename(const char *pfx, int pfx_len, const char *arg) | |
130 | { | |
131 | static char path[PATH_MAX]; | |
25fe217b | 132 | #ifndef __MINGW32__ |
ecf4831d | 133 | if (!pfx || !*pfx || is_absolute_path(arg)) |
4ca06608 JH |
134 | return arg; |
135 | memcpy(path, pfx, pfx_len); | |
136 | strcpy(path + pfx_len, arg); | |
25fe217b JS |
137 | #else |
138 | char *p; | |
139 | /* don't add prefix to absolute paths, but still replace '\' by '/' */ | |
140 | if (is_absolute_path(arg)) | |
141 | pfx_len = 0; | |
142 | else | |
143 | memcpy(path, pfx, pfx_len); | |
144 | strcpy(path + pfx_len, arg); | |
145 | for (p = path + pfx_len; *p; p++) | |
146 | if (*p == '\\') | |
147 | *p = '/'; | |
148 | #endif | |
4ca06608 JH |
149 | return path; |
150 | } | |
151 | ||
e23d0b4a LT |
152 | /* |
153 | * Verify a filename that we got as an argument for a pathspec | |
154 | * entry. Note that a filename that begins with "-" never verifies | |
155 | * as true, because even if such a filename were to exist, we want | |
156 | * it to be preceded by the "--" marker (or we want the user to | |
157 | * use a format like "./-filename") | |
158 | */ | |
159 | void verify_filename(const char *prefix, const char *arg) | |
160 | { | |
161 | const char *name; | |
162 | struct stat st; | |
163 | ||
164 | if (*arg == '-') | |
165 | die("bad flag '%s' used after filename", arg); | |
166 | name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg; | |
167 | if (!lstat(name, &st)) | |
168 | return; | |
169 | if (errno == ENOENT) | |
ea92f41f JH |
170 | die("ambiguous argument '%s': unknown revision or path not in the working tree.\n" |
171 | "Use '--' to separate paths from revisions", arg); | |
e23d0b4a LT |
172 | die("'%s': %s", arg, strerror(errno)); |
173 | } | |
174 | ||
ea92f41f JH |
175 | /* |
176 | * Opposite of the above: the command line did not have -- marker | |
177 | * and we parsed the arg as a refname. It should not be interpretable | |
178 | * as a filename. | |
179 | */ | |
180 | void verify_non_filename(const char *prefix, const char *arg) | |
181 | { | |
182 | const char *name; | |
183 | struct stat st; | |
184 | ||
7ae3df8c | 185 | if (!is_inside_work_tree() || is_inside_git_dir()) |
68025633 | 186 | return; |
ea92f41f JH |
187 | if (*arg == '-') |
188 | return; /* flag */ | |
189 | name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg; | |
190 | if (!lstat(name, &st)) | |
191 | die("ambiguous argument '%s': both revision and filename\n" | |
192 | "Use '--' to separate filenames from revisions", arg); | |
33a798c8 | 193 | if (errno != ENOENT && errno != ENOTDIR) |
ea92f41f JH |
194 | die("'%s': %s", arg, strerror(errno)); |
195 | } | |
196 | ||
6b5ee137 | 197 | const char **get_pathspec(const char *prefix, const char **pathspec) |
d288a700 | 198 | { |
6b5ee137 | 199 | const char *entry = *pathspec; |
d089ebaa | 200 | const char **src, **dst; |
d288a700 LT |
201 | int prefixlen; |
202 | ||
f332726e LT |
203 | if (!prefix && !entry) |
204 | return NULL; | |
d288a700 LT |
205 | |
206 | if (!entry) { | |
207 | static const char *spec[2]; | |
208 | spec[0] = prefix; | |
209 | spec[1] = NULL; | |
210 | return spec; | |
211 | } | |
212 | ||
213 | /* Otherwise we have to re-write the entries.. */ | |
d089ebaa JH |
214 | src = pathspec; |
215 | dst = pathspec; | |
f332726e | 216 | prefixlen = prefix ? strlen(prefix) : 0; |
d089ebaa JH |
217 | while (*src) { |
218 | const char *p = prefix_path(prefix, prefixlen, *src); | |
219 | if (p) | |
220 | *(dst++) = p; | |
3296766e JH |
221 | else |
222 | exit(128); /* error message already given */ | |
d089ebaa JH |
223 | src++; |
224 | } | |
225 | *dst = NULL; | |
226 | if (!*pathspec) | |
227 | return NULL; | |
228 | return pathspec; | |
d288a700 LT |
229 | } |
230 | ||
5f5608bc | 231 | /* |
ad1a382f | 232 | * Test if it looks like we're at a git directory. |
5e7bfe25 | 233 | * We want to see: |
5f5608bc | 234 | * |
790296fd | 235 | * - either an objects/ directory _or_ the proper |
5f5608bc | 236 | * GIT_OBJECT_DIRECTORY environment variable |
ad1a382f | 237 | * - a refs/ directory |
8098a178 | 238 | * - either a HEAD symlink or a HEAD file that is formatted as |
c847f537 JH |
239 | * a proper "ref:", or a regular file HEAD that has a properly |
240 | * formatted sha1 object name. | |
5f5608bc | 241 | */ |
ad1a382f | 242 | static int is_git_directory(const char *suspect) |
5f5608bc | 243 | { |
ad1a382f SP |
244 | char path[PATH_MAX]; |
245 | size_t len = strlen(suspect); | |
246 | ||
247 | strcpy(path, suspect); | |
248 | if (getenv(DB_ENVIRONMENT)) { | |
249 | if (access(getenv(DB_ENVIRONMENT), X_OK)) | |
250 | return 0; | |
251 | } | |
252 | else { | |
253 | strcpy(path + len, "/objects"); | |
254 | if (access(path, X_OK)) | |
255 | return 0; | |
256 | } | |
257 | ||
258 | strcpy(path + len, "/refs"); | |
259 | if (access(path, X_OK)) | |
8098a178 | 260 | return 0; |
ad1a382f SP |
261 | |
262 | strcpy(path + len, "/HEAD"); | |
c847f537 | 263 | if (validate_headref(path)) |
ad1a382f SP |
264 | return 0; |
265 | ||
8098a178 | 266 | return 1; |
5f5608bc LT |
267 | } |
268 | ||
68025633 JS |
269 | int is_inside_git_dir(void) |
270 | { | |
e90fdc39 JS |
271 | if (inside_git_dir < 0) |
272 | inside_git_dir = is_inside_dir(get_git_dir()); | |
273 | return inside_git_dir; | |
892c41b9 ML |
274 | } |
275 | ||
892c41b9 ML |
276 | int is_inside_work_tree(void) |
277 | { | |
e90fdc39 JS |
278 | if (inside_work_tree < 0) |
279 | inside_work_tree = is_inside_dir(get_git_work_tree()); | |
280 | return inside_work_tree; | |
892c41b9 ML |
281 | } |
282 | ||
e90fdc39 | 283 | /* |
7efeb8f0 JS |
284 | * set_work_tree() is only ever called if you set GIT_DIR explicitely. |
285 | * The old behaviour (which we retain here) is to set the work tree root | |
286 | * to the cwd, unless overridden by the config, the command line, or | |
287 | * GIT_WORK_TREE. | |
e90fdc39 | 288 | */ |
7efeb8f0 | 289 | static const char *set_work_tree(const char *dir) |
892c41b9 | 290 | { |
7efeb8f0 | 291 | char buffer[PATH_MAX + 1]; |
e90fdc39 | 292 | |
7efeb8f0 JS |
293 | if (!getcwd(buffer, sizeof(buffer))) |
294 | die ("Could not get the current working directory"); | |
295 | git_work_tree_cfg = xstrdup(buffer); | |
e90fdc39 JS |
296 | inside_work_tree = 1; |
297 | ||
7efeb8f0 | 298 | return NULL; |
68025633 JS |
299 | } |
300 | ||
f3fa1838 JH |
301 | void setup_work_tree(void) |
302 | { | |
354e6534 JS |
303 | const char *work_tree, *git_dir; |
304 | static int initialized = 0; | |
305 | ||
306 | if (initialized) | |
307 | return; | |
308 | work_tree = get_git_work_tree(); | |
309 | git_dir = get_git_dir(); | |
59f0f2f3 MH |
310 | if (!is_absolute_path(git_dir)) |
311 | set_git_dir(make_absolute_path(git_dir)); | |
312 | if (!work_tree || chdir(work_tree)) | |
313 | die("This operation must be run in a work tree"); | |
354e6534 | 314 | initialized = 1; |
59f0f2f3 MH |
315 | } |
316 | ||
9459aa77 NTND |
317 | static int check_repository_format_gently(int *nongit_ok) |
318 | { | |
ef90d6d4 | 319 | git_config(check_repository_format_version, NULL); |
9459aa77 NTND |
320 | if (GIT_REPO_VERSION < repository_format_version) { |
321 | if (!nongit_ok) | |
322 | die ("Expected git repo version <= %d, found %d", | |
323 | GIT_REPO_VERSION, repository_format_version); | |
324 | warning("Expected git repo version <= %d, found %d", | |
325 | GIT_REPO_VERSION, repository_format_version); | |
326 | warning("Please upgrade Git"); | |
327 | *nongit_ok = -1; | |
328 | return -1; | |
329 | } | |
330 | return 0; | |
331 | } | |
332 | ||
b44ebb19 LH |
333 | /* |
334 | * Try to read the location of the git directory from the .git file, | |
335 | * return path to git directory if found. | |
336 | */ | |
337 | const char *read_gitfile_gently(const char *path) | |
338 | { | |
339 | char *buf; | |
340 | struct stat st; | |
341 | int fd; | |
342 | size_t len; | |
343 | ||
344 | if (stat(path, &st)) | |
345 | return NULL; | |
346 | if (!S_ISREG(st.st_mode)) | |
347 | return NULL; | |
348 | fd = open(path, O_RDONLY); | |
349 | if (fd < 0) | |
350 | die("Error opening %s: %s", path, strerror(errno)); | |
351 | buf = xmalloc(st.st_size + 1); | |
352 | len = read_in_full(fd, buf, st.st_size); | |
353 | close(fd); | |
354 | if (len != st.st_size) | |
355 | die("Error reading %s", path); | |
356 | buf[len] = '\0'; | |
357 | if (prefixcmp(buf, "gitdir: ")) | |
358 | die("Invalid gitfile format: %s", path); | |
359 | while (buf[len - 1] == '\n' || buf[len - 1] == '\r') | |
360 | len--; | |
361 | if (len < 9) | |
362 | die("No path in gitfile: %s", path); | |
363 | buf[len] = '\0'; | |
364 | if (!is_git_directory(buf + 8)) | |
365 | die("Not a git repository: %s", buf + 8); | |
366 | path = make_absolute_path(buf + 8); | |
367 | free(buf); | |
368 | return path; | |
369 | } | |
370 | ||
e90fdc39 JS |
371 | /* |
372 | * We cannot decide in this function whether we are in the work tree or | |
373 | * not, since the config can only be read _after_ this function was called. | |
374 | */ | |
4ca06608 | 375 | const char *setup_git_directory_gently(int *nongit_ok) |
d288a700 | 376 | { |
e90fdc39 | 377 | const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT); |
d288a700 | 378 | static char cwd[PATH_MAX+1]; |
e90fdc39 | 379 | const char *gitdirenv; |
b44ebb19 | 380 | const char *gitfile_dir; |
e90fdc39 | 381 | int len, offset; |
25fe217b | 382 | int minoffset = 0; |
d288a700 | 383 | |
af05d679 SG |
384 | /* |
385 | * Let's assume that we are in a git repository. | |
386 | * If it turns out later that we are somewhere else, the value will be | |
387 | * updated accordingly. | |
388 | */ | |
389 | if (nongit_ok) | |
390 | *nongit_ok = 0; | |
391 | ||
e90fdc39 JS |
392 | /* |
393 | * If GIT_DIR is set explicitly, we're not going | |
394 | * to do any discovery, but we still do repository | |
395 | * validation. | |
396 | */ | |
ad1a382f | 397 | gitdirenv = getenv(GIT_DIR_ENVIRONMENT); |
e90fdc39 JS |
398 | if (gitdirenv) { |
399 | if (PATH_MAX - 40 < strlen(gitdirenv)) | |
400 | die("'$%s' too big", GIT_DIR_ENVIRONMENT); | |
401 | if (is_git_directory(gitdirenv)) { | |
dd5c8af1 JS |
402 | static char buffer[1024 + 1]; |
403 | const char *retval; | |
404 | ||
138dd1e9 NTND |
405 | if (!work_tree_env) { |
406 | retval = set_work_tree(gitdirenv); | |
9459aa77 NTND |
407 | /* config may override worktree */ |
408 | if (check_repository_format_gently(nongit_ok)) | |
409 | return NULL; | |
138dd1e9 NTND |
410 | return retval; |
411 | } | |
9459aa77 NTND |
412 | if (check_repository_format_gently(nongit_ok)) |
413 | return NULL; | |
dd5c8af1 JS |
414 | retval = get_relative_cwd(buffer, sizeof(buffer) - 1, |
415 | get_git_work_tree()); | |
416 | if (!retval || !*retval) | |
417 | return NULL; | |
418 | set_git_dir(make_absolute_path(gitdirenv)); | |
419 | if (chdir(work_tree_env) < 0) | |
420 | die ("Could not chdir to %s", work_tree_env); | |
421 | strcat(buffer, "/"); | |
422 | return retval; | |
892c41b9 | 423 | } |
3a3c3fc4 | 424 | if (nongit_ok) { |
41e95f69 ML |
425 | *nongit_ok = 1; |
426 | return NULL; | |
427 | } | |
ad1a382f | 428 | die("Not a git repository: '%s'", gitdirenv); |
5e7bfe25 | 429 | } |
d288a700 | 430 | |
f66a4d68 | 431 | if (!getcwd(cwd, sizeof(cwd)-1)) |
d288a700 | 432 | die("Unable to read current working directory"); |
25fe217b JS |
433 | if (has_dos_drive_prefix(cwd)) |
434 | minoffset = 2; | |
d288a700 | 435 | |
892c41b9 | 436 | /* |
e90fdc39 | 437 | * Test in the following order (relative to the cwd): |
b44ebb19 | 438 | * - .git (file containing "gitdir: <path>") |
e90fdc39 JS |
439 | * - .git/ |
440 | * - ./ (bare) | |
b44ebb19 | 441 | * - ../.git |
e90fdc39 JS |
442 | * - ../.git/ |
443 | * - ../ (bare) | |
444 | * - ../../.git/ | |
445 | * etc. | |
892c41b9 | 446 | */ |
e90fdc39 JS |
447 | offset = len = strlen(cwd); |
448 | for (;;) { | |
b44ebb19 LH |
449 | gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT); |
450 | if (gitfile_dir) { | |
451 | if (set_git_dir(gitfile_dir)) | |
452 | die("Repository setup failed"); | |
453 | break; | |
454 | } | |
e90fdc39 JS |
455 | if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT)) |
456 | break; | |
457 | if (is_git_directory(".")) { | |
458 | inside_git_dir = 1; | |
459 | if (!work_tree_env) | |
460 | inside_work_tree = 0; | |
461 | setenv(GIT_DIR_ENVIRONMENT, ".", 1); | |
9459aa77 | 462 | check_repository_format_gently(nongit_ok); |
892c41b9 ML |
463 | return NULL; |
464 | } | |
e90fdc39 JS |
465 | chdir(".."); |
466 | do { | |
25fe217b | 467 | if (offset <= minoffset) { |
e90fdc39 JS |
468 | if (nongit_ok) { |
469 | if (chdir(cwd)) | |
470 | die("Cannot come back to cwd"); | |
471 | *nongit_ok = 1; | |
472 | return NULL; | |
473 | } | |
474 | die("Not a git repository"); | |
475 | } | |
25fe217b | 476 | } while (offset > minoffset && cwd[--offset] != '/'); |
892c41b9 ML |
477 | } |
478 | ||
e90fdc39 JS |
479 | inside_git_dir = 0; |
480 | if (!work_tree_env) | |
481 | inside_work_tree = 1; | |
482 | git_work_tree_cfg = xstrndup(cwd, offset); | |
9459aa77 NTND |
483 | if (check_repository_format_gently(nongit_ok)) |
484 | return NULL; | |
e90fdc39 | 485 | if (offset == len) |
d288a700 LT |
486 | return NULL; |
487 | ||
e90fdc39 JS |
488 | /* Make "offset" point to past the '/', and add a '/' at the end */ |
489 | offset++; | |
490 | cwd[len++] = '/'; | |
491 | cwd[len] = 0; | |
492 | return cwd + offset; | |
d288a700 | 493 | } |
5e7bfe25 | 494 | |
94df2506 JH |
495 | int git_config_perm(const char *var, const char *value) |
496 | { | |
06cbe855 HO |
497 | int i; |
498 | char *endptr; | |
499 | ||
500 | if (value == NULL) | |
501 | return PERM_GROUP; | |
502 | ||
503 | if (!strcmp(value, "umask")) | |
504 | return PERM_UMASK; | |
505 | if (!strcmp(value, "group")) | |
506 | return PERM_GROUP; | |
507 | if (!strcmp(value, "all") || | |
508 | !strcmp(value, "world") || | |
509 | !strcmp(value, "everybody")) | |
510 | return PERM_EVERYBODY; | |
511 | ||
512 | /* Parse octal numbers */ | |
513 | i = strtol(value, &endptr, 8); | |
514 | ||
515 | /* If not an octal number, maybe true/false? */ | |
516 | if (*endptr != 0) | |
517 | return git_config_bool(var, value) ? PERM_GROUP : PERM_UMASK; | |
518 | ||
519 | /* | |
520 | * Treat values 0, 1 and 2 as compatibility cases, otherwise it is | |
521 | * a chmod value. | |
522 | */ | |
523 | switch (i) { | |
524 | case PERM_UMASK: /* 0 */ | |
525 | return PERM_UMASK; | |
526 | case OLD_PERM_GROUP: /* 1 */ | |
527 | return PERM_GROUP; | |
528 | case OLD_PERM_EVERYBODY: /* 2 */ | |
529 | return PERM_EVERYBODY; | |
94df2506 | 530 | } |
06cbe855 HO |
531 | |
532 | /* A filemode value was given: 0xxx */ | |
533 | ||
534 | if ((i & 0600) != 0600) | |
535 | die("Problem with core.sharedRepository filemode value " | |
536 | "(0%.3o).\nThe owner of files must always have " | |
537 | "read and write permissions.", i); | |
538 | ||
539 | /* | |
540 | * Mask filemode value. Others can not get write permission. | |
541 | * x flags for directories are handled separately. | |
542 | */ | |
543 | return i & 0666; | |
94df2506 JH |
544 | } |
545 | ||
ef90d6d4 | 546 | int check_repository_format_version(const char *var, const char *value, void *cb) |
ab9cb76f | 547 | { |
299726d5 JS |
548 | if (strcmp(var, "core.repositoryformatversion") == 0) |
549 | repository_format_version = git_config_int(var, value); | |
457f06d6 | 550 | else if (strcmp(var, "core.sharedrepository") == 0) |
94df2506 | 551 | shared_repository = git_config_perm(var, value); |
e90fdc39 JS |
552 | else if (strcmp(var, "core.bare") == 0) { |
553 | is_bare_repository_cfg = git_config_bool(var, value); | |
554 | if (is_bare_repository_cfg == 1) | |
555 | inside_work_tree = -1; | |
556 | } else if (strcmp(var, "core.worktree") == 0) { | |
180483c5 JH |
557 | if (!value) |
558 | return config_error_nonbool(var); | |
8e0f7003 | 559 | free(git_work_tree_cfg); |
e90fdc39 JS |
560 | git_work_tree_cfg = xstrdup(value); |
561 | inside_work_tree = -1; | |
562 | } | |
299726d5 | 563 | return 0; |
ab9cb76f JH |
564 | } |
565 | ||
566 | int check_repository_format(void) | |
567 | { | |
9459aa77 | 568 | return check_repository_format_gently(NULL); |
ab9cb76f JH |
569 | } |
570 | ||
5e7bfe25 JH |
571 | const char *setup_git_directory(void) |
572 | { | |
4ca06608 | 573 | const char *retval = setup_git_directory_gently(NULL); |
e90fdc39 JS |
574 | |
575 | /* If the work tree is not the default one, recompute prefix */ | |
576 | if (inside_work_tree < 0) { | |
577 | static char buffer[PATH_MAX + 1]; | |
578 | char *rel; | |
579 | if (retval && chdir(retval)) | |
580 | die ("Could not jump back into original cwd"); | |
581 | rel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree()); | |
582 | return rel && *rel ? strcat(rel, "/") : NULL; | |
583 | } | |
584 | ||
5e7bfe25 JH |
585 | return retval; |
586 | } |