| 1090 | } |
| 1091 | |
| 1092 | void write_worktree_linking_files(const char *dotgit, const char *gitdir, |
| 1093 | int use_relative_paths) |
| 1094 | { |
| 1095 | struct strbuf path = STRBUF_INIT; |
| 1096 | struct strbuf repo = STRBUF_INIT; |
| 1097 | struct strbuf tmp = STRBUF_INIT; |
| 1098 | |
| 1099 | strbuf_addstr(&path, dotgit); |
| 1100 | strbuf_strip_suffix(&path, "/.git"); |
| 1101 | strbuf_realpath(&path, path.buf, 1); |
| 1102 | strbuf_addstr(&repo, gitdir); |
| 1103 | strbuf_strip_suffix(&repo, "/gitdir"); |
| 1104 | strbuf_realpath(&repo, repo.buf, 1); |
| 1105 | |
| 1106 | if (use_relative_paths && !the_repository->repository_format_relative_worktrees) { |
| 1107 | if (upgrade_repository_format(the_repository, 1) < 0) |
| 1108 | die(_("unable to upgrade repository format to support relative worktrees")); |
| 1109 | if (repo_config_set_gently(the_repository, "extensions.relativeWorktrees", "true")) |
| 1110 | die(_("unable to set extensions.relativeWorktrees setting")); |
| 1111 | the_repository->repository_format_relative_worktrees = 1; |
| 1112 | } |
| 1113 | |
| 1114 | if (use_relative_paths) { |
| 1115 | write_file(gitdir, "%s/.git", relative_path(path.buf, repo.buf, &tmp)); |
| 1116 | write_file(dotgit, "gitdir: %s", relative_path(repo.buf, path.buf, &tmp)); |
| 1117 | } else { |
| 1118 | write_file(gitdir, "%s/.git", path.buf); |
| 1119 | write_file(dotgit, "gitdir: %s", repo.buf); |
| 1120 | } |
| 1121 | |
| 1122 | strbuf_release(&path); |
| 1123 | strbuf_release(&repo); |
| 1124 | strbuf_release(&tmp); |
| 1125 | } |
no test coverage detected