| 1105 | } |
| 1106 | |
| 1107 | static const char *setup_explicit_git_dir(struct repository *repo, |
| 1108 | const char *gitdirenv, |
| 1109 | struct strbuf *cwd, |
| 1110 | struct repository_format *repo_fmt, |
| 1111 | int *nongit_ok) |
| 1112 | { |
| 1113 | const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT); |
| 1114 | const char *worktree; |
| 1115 | char *gitfile; |
| 1116 | int offset; |
| 1117 | |
| 1118 | if (PATH_MAX - 40 < strlen(gitdirenv)) |
| 1119 | die(_("'$%s' too big"), GIT_DIR_ENVIRONMENT); |
| 1120 | |
| 1121 | gitfile = (char*)read_gitfile(gitdirenv); |
| 1122 | if (gitfile) { |
| 1123 | gitfile = xstrdup(gitfile); |
| 1124 | gitdirenv = gitfile; |
| 1125 | } |
| 1126 | |
| 1127 | if (!is_git_directory(gitdirenv)) { |
| 1128 | if (nongit_ok) { |
| 1129 | *nongit_ok = 1; |
| 1130 | free(gitfile); |
| 1131 | return NULL; |
| 1132 | } |
| 1133 | die(_("not a git repository: '%s'"), gitdirenv); |
| 1134 | } |
| 1135 | |
| 1136 | if (check_repository_format_gently(gitdirenv, repo_fmt, nongit_ok)) { |
| 1137 | free(gitfile); |
| 1138 | return NULL; |
| 1139 | } |
| 1140 | |
| 1141 | /* #3, #7, #11, #15, #19, #23, #27, #31 (see t1510) */ |
| 1142 | if (work_tree_env) |
| 1143 | set_git_work_tree(repo, work_tree_env); |
| 1144 | else if (is_bare_repository_cfg > 0) { |
| 1145 | if (git_work_tree_cfg) { |
| 1146 | /* #22.2, #30 */ |
| 1147 | warning("core.bare and core.worktree do not make sense"); |
| 1148 | repo->worktree_config_is_bogus = true; |
| 1149 | } |
| 1150 | |
| 1151 | /* #18, #26 */ |
| 1152 | set_git_dir(repo, gitdirenv, 0); |
| 1153 | free(gitfile); |
| 1154 | return NULL; |
| 1155 | } |
| 1156 | else if (git_work_tree_cfg) { /* #6, #14 */ |
| 1157 | if (is_absolute_path(git_work_tree_cfg)) |
| 1158 | set_git_work_tree(repo, git_work_tree_cfg); |
| 1159 | else { |
| 1160 | char *core_worktree; |
| 1161 | if (chdir(gitdirenv)) |
| 1162 | die_errno(_("cannot chdir to '%s'"), gitdirenv); |
| 1163 | if (chdir(git_work_tree_cfg)) |
| 1164 | die_errno(_("cannot chdir to '%s'"), git_work_tree_cfg); |
no test coverage detected