]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2401-worktree-prune.sh
test framework: further deprecate test_i18ngrep
[thirdparty/git.git] / t / t2401-worktree-prune.sh
CommitLineData
23af91d1
NTND
1#!/bin/sh
2
3test_description='prune $GIT_DIR/worktrees'
4
883b98ef 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
9f24f3c7 8TEST_PASSES_SANITIZE_LEAK=true
23af91d1
NTND
9. ./test-lib.sh
10
562bc080
MK
11test_expect_success initialize '
12 git commit --allow-empty -m init
13'
14
df0b6cfb
NTND
15test_expect_success 'worktree prune on normal repo' '
16 git worktree prune &&
17 test_must_fail git worktree prune abc
23af91d1
NTND
18'
19
20test_expect_success 'prune files inside $GIT_DIR/worktrees' '
21 mkdir .git/worktrees &&
22 : >.git/worktrees/abc &&
da8fb6be 23 git worktree prune --verbose 2>actual &&
23af91d1
NTND
24 cat >expect <<EOF &&
25Removing worktrees/abc: not a valid directory
26EOF
1108cea7 27 test_cmp expect actual &&
23af91d1
NTND
28 ! test -f .git/worktrees/abc &&
29 ! test -d .git/worktrees
30'
31
32test_expect_success 'prune directories without gitdir' '
33 mkdir -p .git/worktrees/def/abc &&
34 : >.git/worktrees/def/def &&
35 cat >expect <<EOF &&
36Removing worktrees/def: gitdir file does not exist
37EOF
da8fb6be 38 git worktree prune --verbose 2>actual &&
1108cea7 39 test_cmp expect actual &&
23af91d1
NTND
40 ! test -d .git/worktrees/def &&
41 ! test -d .git/worktrees
42'
43
ecf2ff6a 44test_expect_success SANITY 'prune directories with unreadable gitdir' '
23af91d1
NTND
45 mkdir -p .git/worktrees/def/abc &&
46 : >.git/worktrees/def/def &&
47 : >.git/worktrees/def/gitdir &&
48 chmod u-r .git/worktrees/def/gitdir &&
da8fb6be 49 git worktree prune --verbose 2>actual &&
23af91d1
NTND
50 test_i18ngrep "Removing worktrees/def: unable to read gitdir file" actual &&
51 ! test -d .git/worktrees/def &&
52 ! test -d .git/worktrees
53'
54
55test_expect_success 'prune directories with invalid gitdir' '
56 mkdir -p .git/worktrees/def/abc &&
57 : >.git/worktrees/def/def &&
58 : >.git/worktrees/def/gitdir &&
da8fb6be 59 git worktree prune --verbose 2>actual &&
23af91d1
NTND
60 test_i18ngrep "Removing worktrees/def: invalid gitdir file" actual &&
61 ! test -d .git/worktrees/def &&
62 ! test -d .git/worktrees
63'
64
65test_expect_success 'prune directories with gitdir pointing to nowhere' '
66 mkdir -p .git/worktrees/def/abc &&
67 : >.git/worktrees/def/def &&
68 echo "$(pwd)"/nowhere >.git/worktrees/def/gitdir &&
da8fb6be 69 git worktree prune --verbose 2>actual &&
23af91d1
NTND
70 test_i18ngrep "Removing worktrees/def: gitdir file points to non-existent location" actual &&
71 ! test -d .git/worktrees/def &&
72 ! test -d .git/worktrees
73'
74
75test_expect_success 'not prune locked checkout' '
807e3cac 76 test_when_finished rm -r .git/worktrees &&
23af91d1
NTND
77 mkdir -p .git/worktrees/ghi &&
78 : >.git/worktrees/ghi/locked &&
df0b6cfb 79 git worktree prune &&
23af91d1
NTND
80 test -d .git/worktrees/ghi
81'
82
83test_expect_success 'not prune recent checkouts' '
807e3cac 84 test_when_finished rm -r .git/worktrees &&
327864aa
NTND
85 git worktree add jlm HEAD &&
86 test -d .git/worktrees/jlm &&
87 rm -rf jlm &&
df0b6cfb 88 git worktree prune --verbose --expire=2.days.ago &&
23af91d1
NTND
89 test -d .git/worktrees/jlm
90'
91
562bc080
MK
92test_expect_success 'not prune proper checkouts' '
93 test_when_finished rm -r .git/worktrees &&
883b98ef 94 git worktree add --detach "$PWD/nop" main &&
df0b6cfb 95 git worktree prune &&
562bc080
MK
96 test -d .git/worktrees/nop
97'
98
4a3ce479
ES
99test_expect_success 'prune duplicate (linked/linked)' '
100 test_when_finished rm -fr .git/worktrees w1 w2 &&
101 git worktree add --detach w1 &&
102 git worktree add --detach w2 &&
103 sed "s/w2/w1/" .git/worktrees/w2/gitdir >.git/worktrees/w2/gitdir.new &&
104 mv .git/worktrees/w2/gitdir.new .git/worktrees/w2/gitdir &&
da8fb6be 105 git worktree prune --verbose 2>actual &&
4a3ce479
ES
106 test_i18ngrep "duplicate entry" actual &&
107 test -d .git/worktrees/w1 &&
108 ! test -d .git/worktrees/w2
109'
110
916133ef
ES
111test_expect_success 'prune duplicate (main/linked)' '
112 test_when_finished rm -fr repo wt &&
113 test_create_repo repo &&
114 test_commit -C repo x &&
115 git -C repo worktree add --detach ../wt &&
116 rm -fr wt &&
117 mv repo wt &&
da8fb6be 118 git -C wt worktree prune --verbose 2>actual &&
916133ef
ES
119 test_i18ngrep "duplicate entry" actual &&
120 ! test -d .git/worktrees/wt
121'
122
23af91d1 123test_done