Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test git worktree list' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'setup' ' |
| 8 | test_commit init |
| 9 | ' |
| 10 | |
Johannes Schindelin | 098aa86 | 2017-02-17 17:59:06 +0100 | [diff] [blame] | 11 | test_expect_success 'rev-parse --git-common-dir on main worktree' ' |
Nguyễn Thái Ngọc Duy | 17f1365 | 2016-02-12 11:31:45 +0700 | [diff] [blame] | 12 | git rev-parse --git-common-dir >actual && |
| 13 | echo .git >expected && |
| 14 | test_cmp expected actual && |
| 15 | mkdir sub && |
| 16 | git -C sub rev-parse --git-common-dir >actual2 && |
Michael Rappazzo | 5de8a54 | 2017-02-17 17:59:02 +0100 | [diff] [blame] | 17 | echo ../.git >expected2 && |
Nguyễn Thái Ngọc Duy | 17f1365 | 2016-02-12 11:31:45 +0700 | [diff] [blame] | 18 | test_cmp expected2 actual2 |
| 19 | ' |
| 20 | |
Johannes Schindelin | 098aa86 | 2017-02-17 17:59:06 +0100 | [diff] [blame] | 21 | test_expect_success 'rev-parse --git-path objects linked worktree' ' |
Michael Rappazzo | 5de8a54 | 2017-02-17 17:59:02 +0100 | [diff] [blame] | 22 | echo "$(git rev-parse --show-toplevel)/.git/objects" >expect && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 23 | test_when_finished "rm -rf linked-tree actual expect && git worktree prune" && |
Michael Rappazzo | 5de8a54 | 2017-02-17 17:59:02 +0100 | [diff] [blame] | 24 | git worktree add --detach linked-tree master && |
| 25 | git -C linked-tree rev-parse --git-path objects >actual && |
| 26 | test_cmp expect actual |
| 27 | ' |
| 28 | |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 29 | test_expect_success '"list" all worktrees from main' ' |
| 30 | echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 31 | test_when_finished "rm -rf here out actual expect && git worktree prune" && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 32 | git worktree add --detach here master && |
| 33 | echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 34 | git worktree list >out && |
| 35 | sed "s/ */ /g" <out >actual && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 36 | test_cmp expect actual |
| 37 | ' |
| 38 | |
| 39 | test_expect_success '"list" all worktrees from linked' ' |
| 40 | echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 41 | test_when_finished "rm -rf here out actual expect && git worktree prune" && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 42 | git worktree add --detach here master && |
| 43 | echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 44 | git -C here worktree list >out && |
| 45 | sed "s/ */ /g" <out >actual && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 46 | test_cmp expect actual |
| 47 | ' |
| 48 | |
| 49 | test_expect_success '"list" all worktrees --porcelain' ' |
| 50 | echo "worktree $(git rev-parse --show-toplevel)" >expect && |
| 51 | echo "HEAD $(git rev-parse HEAD)" >>expect && |
| 52 | echo "branch $(git symbolic-ref HEAD)" >>expect && |
| 53 | echo >>expect && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 54 | test_when_finished "rm -rf here actual expect && git worktree prune" && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 55 | git worktree add --detach here master && |
| 56 | echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect && |
| 57 | echo "HEAD $(git rev-parse HEAD)" >>expect && |
| 58 | echo "detached" >>expect && |
| 59 | echo >>expect && |
| 60 | git worktree list --porcelain >actual && |
| 61 | test_cmp expect actual |
| 62 | ' |
| 63 | |
| 64 | test_expect_success 'bare repo setup' ' |
| 65 | git init --bare bare1 && |
| 66 | echo "data" >file1 && |
| 67 | git add file1 && |
| 68 | git commit -m"File1: add data" && |
| 69 | git push bare1 master && |
| 70 | git reset --hard HEAD^ |
| 71 | ' |
| 72 | |
| 73 | test_expect_success '"list" all worktrees from bare main' ' |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 74 | test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 75 | git -C bare1 worktree add --detach ../there master && |
| 76 | echo "$(pwd)/bare1 (bare)" >expect && |
| 77 | echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 78 | git -C bare1 worktree list >out && |
| 79 | sed "s/ */ /g" <out >actual && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 80 | test_cmp expect actual |
| 81 | ' |
| 82 | |
| 83 | test_expect_success '"list" all worktrees --porcelain from bare main' ' |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 84 | test_when_finished "rm -rf there actual expect && git -C bare1 worktree prune" && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 85 | git -C bare1 worktree add --detach ../there master && |
| 86 | echo "worktree $(pwd)/bare1" >expect && |
| 87 | echo "bare" >>expect && |
| 88 | echo >>expect && |
| 89 | echo "worktree $(git -C there rev-parse --show-toplevel)" >>expect && |
| 90 | echo "HEAD $(git -C there rev-parse HEAD)" >>expect && |
| 91 | echo "detached" >>expect && |
| 92 | echo >>expect && |
| 93 | git -C bare1 worktree list --porcelain >actual && |
| 94 | test_cmp expect actual |
| 95 | ' |
| 96 | |
| 97 | test_expect_success '"list" all worktrees from linked with a bare main' ' |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 98 | test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 99 | git -C bare1 worktree add --detach ../there master && |
| 100 | echo "$(pwd)/bare1 (bare)" >expect && |
| 101 | echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 102 | git -C there worktree list >out && |
| 103 | sed "s/ */ /g" <out >actual && |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 104 | test_cmp expect actual |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'bare repo cleanup' ' |
| 108 | rm -rf bare1 |
| 109 | ' |
| 110 | |
Nguyễn Thái Ngọc Duy | a234563 | 2016-11-28 16:36:54 +0700 | [diff] [blame] | 111 | test_expect_success 'broken main worktree still at the top' ' |
| 112 | git init broken-main && |
| 113 | ( |
| 114 | cd broken-main && |
| 115 | test_commit new && |
| 116 | git worktree add linked && |
| 117 | cat >expected <<-EOF && |
| 118 | worktree $(pwd) |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 119 | HEAD $ZERO_OID |
Nguyễn Thái Ngọc Duy | a234563 | 2016-11-28 16:36:54 +0700 | [diff] [blame] | 120 | |
| 121 | EOF |
| 122 | cd linked && |
| 123 | echo "worktree $(pwd)" >expected && |
| 124 | echo "ref: .broken" >../.git/HEAD && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 125 | git worktree list --porcelain >out && |
| 126 | head -n 3 out >actual && |
Nguyễn Thái Ngọc Duy | a234563 | 2016-11-28 16:36:54 +0700 | [diff] [blame] | 127 | test_cmp ../expected actual && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 128 | git worktree list >out && |
| 129 | head -n 1 out >actual.2 && |
Nguyễn Thái Ngọc Duy | a234563 | 2016-11-28 16:36:54 +0700 | [diff] [blame] | 130 | grep -F "(error)" actual.2 |
| 131 | ) |
| 132 | ' |
| 133 | |
Nguyễn Thái Ngọc Duy | 4df1d4d | 2016-11-28 16:36:56 +0700 | [diff] [blame] | 134 | test_expect_success 'linked worktrees are sorted' ' |
| 135 | mkdir sorted && |
| 136 | git init sorted/main && |
| 137 | ( |
| 138 | cd sorted/main && |
| 139 | test_tick && |
| 140 | test_commit new && |
| 141 | git worktree add ../first && |
| 142 | git worktree add ../second && |
Prathamesh Chavan | 210e5db | 2017-04-04 03:05:57 +0530 | [diff] [blame] | 143 | git worktree list --porcelain >out && |
| 144 | grep ^worktree out >actual |
Nguyễn Thái Ngọc Duy | 4df1d4d | 2016-11-28 16:36:56 +0700 | [diff] [blame] | 145 | ) && |
| 146 | cat >expected <<-EOF && |
| 147 | worktree $(pwd)/sorted/main |
| 148 | worktree $(pwd)/sorted/first |
| 149 | worktree $(pwd)/sorted/second |
| 150 | EOF |
| 151 | test_cmp expected sorted/main/actual |
| 152 | ' |
| 153 | |
Michael Rappazzo | bb9c03b | 2015-10-08 13:01:05 -0400 | [diff] [blame] | 154 | test_done |