}
struct worktree_display {
+ char *path;
int width;
};
struct strbuf sb = STRBUF_INIT;
const char *reason;
- strbuf_addf(&sb, "%s%*s", wt->path, 1 + path_maxwidth - display->width, "");
+ strbuf_addf(&sb, "%s%*s", display->path, 1 + path_maxwidth - display->width, "");
if (wt->is_bare)
strbuf_addstr(&sb, "(bare)");
else {
{
int i, display_alloc = 0;
struct worktree_display *display = NULL;
+ struct strbuf buf = STRBUF_INIT;
for (i = 0; wt[i]; i++) {
int sha1_len;
ALLOC_GROW(display, i + 1, display_alloc);
- display[i].width = utf8_strwidth(wt[i]->path);
+ quote_path(wt[i]->path, NULL, &buf, 0);
+ display[i].width = utf8_strwidth(buf.buf);
+ display[i].path = strbuf_detach(&buf, NULL);
if (display[i].width > *maxwidth)
*maxwidth = display[i].width;
show_worktree(worktrees[i],
&display[i], path_maxwidth, abbrev);
}
+ for (i = 0; display && worktrees[i]; i++)
+ free(display[i].path);
free(display);
free_worktrees(worktrees);
}
test_cmp expect actual
'
-test_expect_success '"list" all worktrees from main' '
+test_expect_success '"list" all worktrees from main core.quotepath=false' '
+ test_config core.quotepath false &&
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
test_when_finished "rm -rf áááá out actual expect && git worktree prune" &&
git worktree add --detach áááá main &&
test_cmp expect actual
'
+test_expect_success '"list" all worktrees from main core.quotepath=true' '
+ test_config core.quotepath true &&
+ echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
+ test_when_finished "rm -rf á out actual expect && git worktree prune" &&
+ git worktree add --detach á main &&
+ echo "\"$(git -C á rev-parse --show-toplevel)\" $(git rev-parse --short HEAD) (detached HEAD)" |
+ sed s/á/\\\\303\\\\241/g >>expect &&
+ git worktree list >actual &&
+ test_cmp expect actual
+'
+
test_expect_success '"list" all worktrees from linked' '
+ test_config core.quotepath false &&
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
test_when_finished "rm -rf áááá out actual expect && git worktree prune" &&
git worktree add --detach áááá main &&