1414
1415
void read_early_config(config_fn_t cb, void *data)
1416
{
1417
+ struct strbuf buf = STRBUF_INIT;
1418
+
1419
git_config_with_options(cb, data, NULL, 1);
1420
1421
/*
1420
- * Note that this is a really dirty hack that does the wrong thing in
1421
- * many cases. The crux of the problem is that we cannot run
1422
- * setup_git_directory() early on in git's setup, so we have no idea if
1423
- * we are in a repository or not, and therefore are not sure whether
1424
- * and how to read repository-local config.
1425
- *
1426
- * So if we _aren't_ in a repository (or we are but we would reject its
1427
- * core.repositoryformatversion), we'll read whatever is in .git/config
1428
- * blindly. Similarly, if we _are_ in a repository, but not at the
1429
- * root, we'll fail to find .git/config (because it's really
1430
- * ../.git/config, etc), unless setup_git_directory() was already called.
1431
- * See t7006 for a complete set of failures.
1432
- *
1433
- * However, we have historically provided this hack because it does
1434
- * work some of the time (namely when you are at the top-level of a
1435
- * valid repository), and would rarely make things worse (i.e., you do
1436
- * not generally have a .git/config file sitting around).
1422
+ * When setup_git_directory() was not yet asked to discover the
1423
+ * GIT_DIR, we ask discover_git_directory() to figure out whether there
1424
+ * is any repository config we should use (but unlike
1425
+ * setup_git_directory_gently(), no global state is changed, most
1426
+ * notably, the current working directory is still the same after the
1427
+ * call).
1428
*/
1438
- if (!have_git_dir()) {
1429
+ if (!have_git_dir() && discover_git_directory(&buf)) {
1430
struct git_config_source repo_config;
1431
1432
memset(&repo_config, 0, sizeof(repo_config));
1442
- repo_config.file = ".git/config";
1433
+ strbuf_addstr(&buf, "/config");
1434
+ repo_config.file = buf.buf;
1435
git_config_with_options(cb, data, &repo_config, 1);
1436
}
1437
+ strbuf_release(&buf);
1438
}
1439
1440
static void git_config_check_init(void);