* Test if it looks like we're at a git directory. * We want to see: * * - either an objects/ directory _or_ the proper * GIT_OBJECT_DIRECTORY environment variable * - a refs/ directory * - either a HEAD symlink or a HEAD file that is formatted as * a proper "ref:", or a regular file HEAD that has a properly * formatted sha1 object name. */
| 413 | * formatted sha1 object name. |
| 414 | */ |
| 415 | int is_git_directory(const char *suspect) |
| 416 | { |
| 417 | struct strbuf path = STRBUF_INIT; |
| 418 | int ret = 0; |
| 419 | size_t len; |
| 420 | |
| 421 | /* Check worktree-related signatures */ |
| 422 | strbuf_addstr(&path, suspect); |
| 423 | strbuf_complete(&path, '/'); |
| 424 | strbuf_addstr(&path, "HEAD"); |
| 425 | if (validate_headref(path.buf)) |
| 426 | goto done; |
| 427 | |
| 428 | strbuf_reset(&path); |
| 429 | get_common_dir(&path, suspect); |
| 430 | len = path.len; |
| 431 | |
| 432 | /* Check non-worktree-related signatures */ |
| 433 | if (getenv(DB_ENVIRONMENT)) { |
| 434 | if (access(getenv(DB_ENVIRONMENT), X_OK)) |
| 435 | goto done; |
| 436 | } |
| 437 | else { |
| 438 | strbuf_setlen(&path, len); |
| 439 | strbuf_addstr(&path, "/objects"); |
| 440 | if (access(path.buf, X_OK)) |
| 441 | goto done; |
| 442 | } |
| 443 | |
| 444 | strbuf_setlen(&path, len); |
| 445 | strbuf_addstr(&path, "/refs"); |
| 446 | if (access(path.buf, X_OK)) |
| 447 | goto done; |
| 448 | |
| 449 | ret = 1; |
| 450 | done: |
| 451 | strbuf_release(&path); |
| 452 | return ret; |
| 453 | } |
| 454 | |
| 455 | int is_nonbare_repository_dir(struct strbuf *path) |
| 456 | { |
no test coverage detected