Merge branch 'fg/document-commit-message-stripping'
[git/mingw.git] / t / t2026-prune-linked-checkouts.sh
blob1821a480c5ce6fd31416201e3a3dcb0f17b1de91
1 #!/bin/sh
3 test_description='prune $GIT_DIR/worktrees'
5 . ./test-lib.sh
7 test_expect_success initialize '
8 git commit --allow-empty -m init
11 test_expect_success 'prune --worktrees on normal repo' '
12 git prune --worktrees &&
13 test_must_fail git prune --worktrees abc
16 test_expect_success 'prune files inside $GIT_DIR/worktrees' '
17 mkdir .git/worktrees &&
18 : >.git/worktrees/abc &&
19 git prune --worktrees --verbose >actual &&
20 cat >expect <<EOF &&
21 Removing worktrees/abc: not a valid directory
22 EOF
23 test_i18ncmp expect actual &&
24 ! test -f .git/worktrees/abc &&
25 ! test -d .git/worktrees
28 test_expect_success 'prune directories without gitdir' '
29 mkdir -p .git/worktrees/def/abc &&
30 : >.git/worktrees/def/def &&
31 cat >expect <<EOF &&
32 Removing worktrees/def: gitdir file does not exist
33 EOF
34 git prune --worktrees --verbose >actual &&
35 test_i18ncmp expect actual &&
36 ! test -d .git/worktrees/def &&
37 ! test -d .git/worktrees
40 test_expect_success SANITY 'prune directories with unreadable gitdir' '
41 mkdir -p .git/worktrees/def/abc &&
42 : >.git/worktrees/def/def &&
43 : >.git/worktrees/def/gitdir &&
44 chmod u-r .git/worktrees/def/gitdir &&
45 git prune --worktrees --verbose >actual &&
46 test_i18ngrep "Removing worktrees/def: unable to read gitdir file" actual &&
47 ! test -d .git/worktrees/def &&
48 ! test -d .git/worktrees
51 test_expect_success 'prune directories with invalid gitdir' '
52 mkdir -p .git/worktrees/def/abc &&
53 : >.git/worktrees/def/def &&
54 : >.git/worktrees/def/gitdir &&
55 git prune --worktrees --verbose >actual &&
56 test_i18ngrep "Removing worktrees/def: invalid gitdir file" actual &&
57 ! test -d .git/worktrees/def &&
58 ! test -d .git/worktrees
61 test_expect_success 'prune directories with gitdir pointing to nowhere' '
62 mkdir -p .git/worktrees/def/abc &&
63 : >.git/worktrees/def/def &&
64 echo "$(pwd)"/nowhere >.git/worktrees/def/gitdir &&
65 git prune --worktrees --verbose >actual &&
66 test_i18ngrep "Removing worktrees/def: gitdir file points to non-existent location" actual &&
67 ! test -d .git/worktrees/def &&
68 ! test -d .git/worktrees
71 test_expect_success 'not prune locked checkout' '
72 test_when_finished rm -r .git/worktrees &&
73 mkdir -p .git/worktrees/ghi &&
74 : >.git/worktrees/ghi/locked &&
75 git prune --worktrees &&
76 test -d .git/worktrees/ghi
79 test_expect_success 'not prune recent checkouts' '
80 test_when_finished rm -r .git/worktrees &&
81 mkdir zz &&
82 mkdir -p .git/worktrees/jlm &&
83 echo "$(pwd)"/zz >.git/worktrees/jlm/gitdir &&
84 rmdir zz &&
85 git prune --worktrees --verbose --expire=2.days.ago &&
86 test -d .git/worktrees/jlm
89 test_expect_success 'not prune proper checkouts' '
90 test_when_finished rm -r .git/worktrees &&
91 git checkout "--to=$PWD/nop" --detach master &&
92 git prune --worktrees &&
93 test -d .git/worktrees/nop
96 test_done