| 1542 | } |
| 1543 | |
| 1544 | static int do_git_config_sequence(const struct config_options *opts, |
| 1545 | const struct repository *repo, |
| 1546 | config_fn_t fn, void *data) |
| 1547 | { |
| 1548 | int ret = 0; |
| 1549 | char *system_config = git_system_config(); |
| 1550 | char *xdg_config = NULL; |
| 1551 | char *user_config = NULL; |
| 1552 | char *repo_config; |
| 1553 | char *worktree_config; |
| 1554 | |
| 1555 | /* |
| 1556 | * Ensure that either: |
| 1557 | * - the git_dir and commondir are both set, or |
| 1558 | * - the git_dir and commondir are both NULL |
| 1559 | */ |
| 1560 | if (!opts->git_dir != !opts->commondir) |
| 1561 | BUG("only one of commondir and git_dir is non-NULL"); |
| 1562 | |
| 1563 | if (opts->commondir) { |
| 1564 | repo_config = mkpathdup("%s/config", opts->commondir); |
| 1565 | worktree_config = mkpathdup("%s/config.worktree", opts->git_dir); |
| 1566 | } else { |
| 1567 | repo_config = NULL; |
| 1568 | worktree_config = NULL; |
| 1569 | } |
| 1570 | |
| 1571 | if (git_config_system() && system_config && |
| 1572 | !access_or_die(system_config, R_OK, |
| 1573 | opts->system_gently ? ACCESS_EACCES_OK : 0)) |
| 1574 | ret += git_config_from_file_with_options(fn, system_config, |
| 1575 | data, CONFIG_SCOPE_SYSTEM, |
| 1576 | NULL); |
| 1577 | |
| 1578 | git_global_config_paths(&user_config, &xdg_config); |
| 1579 | |
| 1580 | if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK)) |
| 1581 | ret += git_config_from_file_with_options(fn, xdg_config, data, |
| 1582 | CONFIG_SCOPE_GLOBAL, NULL); |
| 1583 | |
| 1584 | if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK)) |
| 1585 | ret += git_config_from_file_with_options(fn, user_config, data, |
| 1586 | CONFIG_SCOPE_GLOBAL, NULL); |
| 1587 | |
| 1588 | if (!opts->ignore_repo && repo_config && |
| 1589 | !access_or_die(repo_config, R_OK, 0)) |
| 1590 | ret += git_config_from_file_with_options(fn, repo_config, data, |
| 1591 | CONFIG_SCOPE_LOCAL, NULL); |
| 1592 | |
| 1593 | if (!opts->ignore_worktree && worktree_config && |
| 1594 | repo && repo->repository_format_worktree_config && |
| 1595 | !access_or_die(worktree_config, R_OK, 0)) { |
| 1596 | ret += git_config_from_file_with_options(fn, worktree_config, data, |
| 1597 | CONFIG_SCOPE_WORKTREE, |
| 1598 | NULL); |
| 1599 | } |
| 1600 | |
| 1601 | if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0) |
no test coverage detected