| 139 | } |
| 140 | |
| 141 | struct worktree *get_linked_worktree(const char *id, |
| 142 | int skip_reading_head) |
| 143 | { |
| 144 | struct worktree *worktree = NULL; |
| 145 | struct strbuf path = STRBUF_INIT; |
| 146 | struct strbuf worktree_path = STRBUF_INIT; |
| 147 | |
| 148 | if (!id) |
| 149 | die("Missing linked worktree name"); |
| 150 | |
| 151 | repo_common_path_append(the_repository, &path, "worktrees/%s/gitdir", id); |
| 152 | if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0) |
| 153 | /* invalid gitdir file */ |
| 154 | goto done; |
| 155 | strbuf_rtrim(&worktree_path); |
| 156 | strbuf_strip_suffix(&worktree_path, "/.git"); |
| 157 | |
| 158 | if (!is_absolute_path(worktree_path.buf)) { |
| 159 | strbuf_strip_suffix(&path, "gitdir"); |
| 160 | strbuf_addbuf(&path, &worktree_path); |
| 161 | strbuf_realpath_forgiving(&worktree_path, path.buf, 0); |
| 162 | } |
| 163 | |
| 164 | CALLOC_ARRAY(worktree, 1); |
| 165 | worktree->repo = the_repository; |
| 166 | worktree->path = strbuf_detach(&worktree_path, NULL); |
| 167 | worktree->id = xstrdup(id); |
| 168 | worktree->is_current = is_current_worktree(worktree); |
| 169 | if (!skip_reading_head) |
| 170 | add_head_info(worktree); |
| 171 | |
| 172 | done: |
| 173 | strbuf_release(&path); |
| 174 | strbuf_release(&worktree_path); |
| 175 | return worktree; |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * NEEDSWORK: This function exists so that we can look up metadata of a |
no test coverage detected