- if (parse_ref(path.buf, &head_ref, NULL) >= 0) {
- worktree = xmalloc(sizeof(struct worktree));
- worktree->path = strbuf_detach(&worktree_path, NULL);
- worktree->git_dir = strbuf_detach(&gitdir, NULL);
- }
+ if (parse_ref(path.buf, &head_ref, &is_detached) < 0)
+ goto done;
+
+ worktree = xmalloc(sizeof(struct worktree));
+ worktree->path = strbuf_detach(&worktree_path, NULL);
+ worktree->git_dir = strbuf_detach(&gitdir, NULL);
+ worktree->is_bare = is_bare;
+ worktree->head_ref = NULL;
+ worktree->is_detached = is_detached;
+ add_head_info(&head_ref, worktree);
+
+done: