unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t2401-worktree-prune.sh
blob568a47ec4268778052534d93a168361744215efa
1 #!/bin/sh
3 test_description='prune $GIT_DIR/worktrees'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success initialize '
12 git commit --allow-empty -m init
15 test_expect_success 'worktree prune on normal repo' '
16 git worktree prune &&
17 test_must_fail git worktree prune abc
20 test_expect_success 'prune files inside $GIT_DIR/worktrees' '
21 mkdir .git/worktrees &&
22 : >.git/worktrees/abc &&
23 git worktree prune --verbose 2>actual &&
24 cat >expect <<EOF &&
25 Removing worktrees/abc: not a valid directory
26 EOF
27 test_cmp expect actual &&
28 ! test -f .git/worktrees/abc &&
29 ! test -d .git/worktrees
32 test_expect_success 'prune directories without gitdir' '
33 mkdir -p .git/worktrees/def/abc &&
34 : >.git/worktrees/def/def &&
35 cat >expect <<EOF &&
36 Removing worktrees/def: gitdir file does not exist
37 EOF
38 git worktree prune --verbose 2>actual &&
39 test_cmp expect actual &&
40 ! test -d .git/worktrees/def &&
41 ! test -d .git/worktrees
44 test_expect_success SANITY 'prune directories with unreadable gitdir' '
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 &&
49 git worktree prune --verbose 2>actual &&
50 test_i18ngrep "Removing worktrees/def: unable to read gitdir file" actual &&
51 ! test -d .git/worktrees/def &&
52 ! test -d .git/worktrees
55 test_expect_success 'prune directories with invalid gitdir' '
56 mkdir -p .git/worktrees/def/abc &&
57 : >.git/worktrees/def/def &&
58 : >.git/worktrees/def/gitdir &&
59 git worktree prune --verbose 2>actual &&
60 test_i18ngrep "Removing worktrees/def: invalid gitdir file" actual &&
61 ! test -d .git/worktrees/def &&
62 ! test -d .git/worktrees
65 test_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 &&
69 git worktree prune --verbose 2>actual &&
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
75 test_expect_success 'not prune locked checkout' '
76 test_when_finished rm -r .git/worktrees &&
77 mkdir -p .git/worktrees/ghi &&
78 : >.git/worktrees/ghi/locked &&
79 git worktree prune &&
80 test -d .git/worktrees/ghi
83 test_expect_success 'not prune recent checkouts' '
84 test_when_finished rm -r .git/worktrees &&
85 git worktree add jlm HEAD &&
86 test -d .git/worktrees/jlm &&
87 rm -rf jlm &&
88 git worktree prune --verbose --expire=2.days.ago &&
89 test -d .git/worktrees/jlm
92 test_expect_success 'not prune proper checkouts' '
93 test_when_finished rm -r .git/worktrees &&
94 git worktree add --detach "$PWD/nop" main &&
95 git worktree prune &&
96 test -d .git/worktrees/nop
99 test_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 &&
105 git worktree prune --verbose 2>actual &&
106 test_i18ngrep "duplicate entry" actual &&
107 test -d .git/worktrees/w1 &&
108 ! test -d .git/worktrees/w2
111 test_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 &&
118 git -C wt worktree prune --verbose 2>actual &&
119 test_i18ngrep "duplicate entry" actual &&
120 ! test -d .git/worktrees/wt
123 test_done