MCPcopy Index your code
hub / github.com/git/git / is_git_directory

Function is_git_directory

setup.c:415–453  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

413 * formatted sha1 object name.
414 */
415int 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;
450done:
451 strbuf_release(&path);
452 return ret;
453}
454
455int is_nonbare_repository_dir(struct strbuf *path)
456{

Callers 14

read_gitfile_gentlyFunction · 0.85
setup_explicit_git_dirFunction · 0.85
enter_repoFunction · 0.85
resolve_gitdir_gentlyFunction · 0.85
is_submodule_modifiedFunction · 0.85
submodule_to_gitdirFunction · 0.85
get_repo_path_1Function · 0.85

Calls 6

strbuf_addstrFunction · 0.85
strbuf_completeFunction · 0.85
validate_headrefFunction · 0.85
get_common_dirFunction · 0.85
strbuf_setlenFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected