MCPcopy Create free account
hub / github.com/git/git / discover_git_directory_reason

Function discover_git_directory_reason

setup.c:1700–1751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1698}
1699
1700enum discovery_result discover_git_directory_reason(struct strbuf *commondir,
1701 struct strbuf *gitdir)
1702{
1703 struct strbuf dir = STRBUF_INIT, err = STRBUF_INIT;
1704 size_t gitdir_offset = gitdir->len, cwd_len;
1705 size_t commondir_offset = commondir->len;
1706 struct repository_format candidate = REPOSITORY_FORMAT_INIT;
1707 enum discovery_result result;
1708
1709 if (strbuf_getcwd(&dir))
1710 return GIT_DIR_CWD_FAILURE;
1711
1712 cwd_len = dir.len;
1713 result = setup_git_directory_gently_1(&dir, gitdir, NULL, 0);
1714 if (result <= 0) {
1715 strbuf_release(&dir);
1716 return result;
1717 }
1718
1719 /*
1720 * The returned gitdir is relative to dir, and if dir does not reflect
1721 * the current working directory, we simply make the gitdir absolute.
1722 */
1723 if (dir.len < cwd_len && !is_absolute_path(gitdir->buf + gitdir_offset)) {
1724 /* Avoid a trailing "/." */
1725 if (!strcmp(".", gitdir->buf + gitdir_offset))
1726 strbuf_setlen(gitdir, gitdir_offset);
1727 else
1728 strbuf_addch(&dir, '/');
1729 strbuf_insert(gitdir, gitdir_offset, dir.buf, dir.len);
1730 }
1731
1732 get_common_dir(commondir, gitdir->buf + gitdir_offset);
1733
1734 strbuf_reset(&dir);
1735 strbuf_addf(&dir, "%s/config", commondir->buf + commondir_offset);
1736 read_repository_format(&candidate, dir.buf);
1737 strbuf_release(&dir);
1738
1739 if (verify_repository_format(&candidate, &err) < 0) {
1740 warning("ignoring git dir '%s': %s",
1741 gitdir->buf + gitdir_offset, err.buf);
1742 strbuf_release(&err);
1743 strbuf_setlen(commondir, commondir_offset);
1744 strbuf_setlen(gitdir, gitdir_offset);
1745 clear_repository_format(&candidate);
1746 return GIT_DIR_INVALID_FORMAT;
1747 }
1748
1749 clear_repository_format(&candidate);
1750 return result;
1751}
1752
1753int apply_repository_format(struct repository *repo,
1754 const struct repository_format *format,

Callers 2

discover_git_directoryFunction · 0.85
cmd_reconfigureFunction · 0.85

Calls 13

strbuf_getcwdFunction · 0.85
strbuf_releaseFunction · 0.85
is_absolute_pathFunction · 0.85
strbuf_setlenFunction · 0.85
strbuf_addchFunction · 0.85
strbuf_insertFunction · 0.85
get_common_dirFunction · 0.85
strbuf_addfFunction · 0.85
read_repository_formatFunction · 0.85
verify_repository_formatFunction · 0.85
warningFunction · 0.85

Tested by

no test coverage detected