#!/bin/sh global test_description := ''test git worktree list'' source ./test-lib.sh test_expect_success 'setup' ' test_commit init ' test_expect_success 'rev-parse --git-common-dir on main worktree' ' git rev-parse --git-common-dir >actual && echo .git >expected && test_cmp expected actual && mkdir sub && git -C sub rev-parse --git-common-dir >actual2 && echo sub/.git >expected2 && test_cmp expected2 actual2 ' test_expect_success '"list" all worktrees from main' ' echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && test_when_finished "rm -rf here && git worktree prune" && git worktree add --detach here master && echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect && git worktree list | sed "s/ */ /g" >actual && test_cmp expect actual ' test_expect_success '"list" all worktrees from linked' ' echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && test_when_finished "rm -rf here && git worktree prune" && git worktree add --detach here master && echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect && git -C here worktree list | sed "s/ */ /g" >actual && test_cmp expect actual ' test_expect_success '"list" all worktrees --porcelain' ' echo "worktree $(git rev-parse --show-toplevel)" >expect && echo "HEAD $(git rev-parse HEAD)" >>expect && echo "branch $(git symbolic-ref HEAD)" >>expect && echo >>expect && test_when_finished "rm -rf here && git worktree prune" && git worktree add --detach here master && echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect && echo "HEAD $(git rev-parse HEAD)" >>expect && echo "detached" >>expect && echo >>expect && git worktree list --porcelain >actual && test_cmp expect actual ' test_expect_success 'bare repo setup' ' git init --bare bare1 && echo "data" >file1 && git add file1 && git commit -m"File1: add data" && git push bare1 master && git reset --hard HEAD^ ' test_expect_success '"list" all worktrees from bare main' ' test_when_finished "rm -rf there && git -C bare1 worktree prune" && git -C bare1 worktree add --detach ../there master && echo "$(pwd)/bare1 (bare)" >expect && echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && git -C bare1 worktree list | sed "s/ */ /g" >actual && test_cmp expect actual ' test_expect_success '"list" all worktrees --porcelain from bare main' ' test_when_finished "rm -rf there && git -C bare1 worktree prune" && git -C bare1 worktree add --detach ../there master && echo "worktree $(pwd)/bare1" >expect && echo "bare" >>expect && echo >>expect && echo "worktree $(git -C there rev-parse --show-toplevel)" >>expect && echo "HEAD $(git -C there rev-parse HEAD)" >>expect && echo "detached" >>expect && echo >>expect && git -C bare1 worktree list --porcelain >actual && test_cmp expect actual ' test_expect_success '"list" all worktrees from linked with a bare main' ' test_when_finished "rm -rf there && git -C bare1 worktree prune" && git -C bare1 worktree add --detach ../there master && echo "$(pwd)/bare1 (bare)" >expect && echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && git -C there worktree list | sed "s/ */ /g" >actual && test_cmp expect actual ' test_expect_success 'bare repo cleanup' ' rm -rf bare1 ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"test git worktree list">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} {(SQ <"\n"> <"\ttest_commit init\n">)}) (C {(test_expect_success)} {(SQ <"rev-parse --git-common-dir on main worktree">)} { (SQ <"\n"> <"\tgit rev-parse --git-common-dir >actual &&\n"> <"\techo .git >expected &&\n"> <"\ttest_cmp expected actual &&\n"> <"\tmkdir sub &&\n"> <"\tgit -C sub rev-parse --git-common-dir >actual2 &&\n"> <"\techo sub/.git >expected2 &&\n"> <"\ttest_cmp expected2 actual2\n"> ) } ) (C {(test_expect_success)} {(SQ <"\"list\" all worktrees from main">)} { (SQ <"\n"> < "\techo \"$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]\" >expect &&\n" > <"\ttest_when_finished \"rm -rf here && git worktree prune\" &&\n"> <"\tgit worktree add --detach here master &&\n"> < "\techo \"$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)\" >>expect &&\n" > <"\tgit worktree list | sed \"s/ */ /g\" >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"\"list\" all worktrees from linked">)} { (SQ <"\n"> < "\techo \"$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]\" >expect &&\n" > <"\ttest_when_finished \"rm -rf here && git worktree prune\" &&\n"> <"\tgit worktree add --detach here master &&\n"> < "\techo \"$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)\" >>expect &&\n" > <"\tgit -C here worktree list | sed \"s/ */ /g\" >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"\"list\" all worktrees --porcelain">)} { (SQ <"\n"> <"\techo \"worktree $(git rev-parse --show-toplevel)\" >expect &&\n"> <"\techo \"HEAD $(git rev-parse HEAD)\" >>expect &&\n"> <"\techo \"branch $(git symbolic-ref HEAD)\" >>expect &&\n"> <"\techo >>expect &&\n"> <"\ttest_when_finished \"rm -rf here && git worktree prune\" &&\n"> <"\tgit worktree add --detach here master &&\n"> <"\techo \"worktree $(git -C here rev-parse --show-toplevel)\" >>expect &&\n"> <"\techo \"HEAD $(git rev-parse HEAD)\" >>expect &&\n"> <"\techo \"detached\" >>expect &&\n"> <"\techo >>expect &&\n"> <"\tgit worktree list --porcelain >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"bare repo setup">)} { (SQ <"\n"> <"\tgit init --bare bare1 &&\n"> <"\techo \"data\" >file1 &&\n"> <"\tgit add file1 &&\n"> <"\tgit commit -m\"File1: add data\" &&\n"> <"\tgit push bare1 master &&\n"> <"\tgit reset --hard HEAD^\n"> ) } ) (C {(test_expect_success)} {(SQ <"\"list\" all worktrees from bare main">)} { (SQ <"\n"> <"\ttest_when_finished \"rm -rf there && git -C bare1 worktree prune\" &&\n"> <"\tgit -C bare1 worktree add --detach ../there master &&\n"> <"\techo \"$(pwd)/bare1 (bare)\" >expect &&\n"> < "\techo \"$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)\" >>expect &&\n" > <"\tgit -C bare1 worktree list | sed \"s/ */ /g\" >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"\"list\" all worktrees --porcelain from bare main">)} { (SQ <"\n"> <"\ttest_when_finished \"rm -rf there && git -C bare1 worktree prune\" &&\n"> <"\tgit -C bare1 worktree add --detach ../there master &&\n"> <"\techo \"worktree $(pwd)/bare1\" >expect &&\n"> <"\techo \"bare\" >>expect &&\n"> <"\techo >>expect &&\n"> <"\techo \"worktree $(git -C there rev-parse --show-toplevel)\" >>expect &&\n"> <"\techo \"HEAD $(git -C there rev-parse HEAD)\" >>expect &&\n"> <"\techo \"detached\" >>expect &&\n"> <"\techo >>expect &&\n"> <"\tgit -C bare1 worktree list --porcelain >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"\"list\" all worktrees from linked with a bare main">)} { (SQ <"\n"> <"\ttest_when_finished \"rm -rf there && git -C bare1 worktree prune\" &&\n"> <"\tgit -C bare1 worktree add --detach ../there master &&\n"> <"\techo \"$(pwd)/bare1 (bare)\" >expect &&\n"> < "\techo \"$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)\" >>expect &&\n" > <"\tgit -C there worktree list | sed \"s/ */ /g\" >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"bare repo cleanup">)} {(SQ <"\n"> <"\trm -rf bare1\n">)}) (C {(test_done)}) ] )