]>
Commit | Line | Data |
---|---|---|
23af91d1 NTND |
1 | #!/bin/sh |
2 | ||
3 | test_description='prune $GIT_DIR/worktrees' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
562bc080 MK |
7 | test_expect_success initialize ' |
8 | git commit --allow-empty -m init | |
9 | ' | |
10 | ||
df0b6cfb NTND |
11 | test_expect_success 'worktree prune on normal repo' ' |
12 | git worktree prune && | |
13 | test_must_fail git worktree prune abc | |
23af91d1 NTND |
14 | ' |
15 | ||
16 | test_expect_success 'prune files inside $GIT_DIR/worktrees' ' | |
17 | mkdir .git/worktrees && | |
18 | : >.git/worktrees/abc && | |
df0b6cfb | 19 | git worktree prune --verbose >actual && |
23af91d1 NTND |
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 | |
26 | ' | |
27 | ||
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 | |
df0b6cfb | 34 | git worktree prune --verbose >actual && |
23af91d1 NTND |
35 | test_i18ncmp expect actual && |
36 | ! test -d .git/worktrees/def && | |
37 | ! test -d .git/worktrees | |
38 | ' | |
39 | ||
ecf2ff6a | 40 | test_expect_success SANITY 'prune directories with unreadable gitdir' ' |
23af91d1 NTND |
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 && | |
df0b6cfb | 45 | git worktree prune --verbose >actual && |
23af91d1 NTND |
46 | test_i18ngrep "Removing worktrees/def: unable to read gitdir file" actual && |
47 | ! test -d .git/worktrees/def && | |
48 | ! test -d .git/worktrees | |
49 | ' | |
50 | ||
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 && | |
df0b6cfb | 55 | git worktree prune --verbose >actual && |
23af91d1 NTND |
56 | test_i18ngrep "Removing worktrees/def: invalid gitdir file" actual && |
57 | ! test -d .git/worktrees/def && | |
58 | ! test -d .git/worktrees | |
59 | ' | |
60 | ||
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 && | |
df0b6cfb | 65 | git worktree prune --verbose >actual && |
23af91d1 NTND |
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 | |
69 | ' | |
70 | ||
71 | test_expect_success 'not prune locked checkout' ' | |
807e3cac | 72 | test_when_finished rm -r .git/worktrees && |
23af91d1 NTND |
73 | mkdir -p .git/worktrees/ghi && |
74 | : >.git/worktrees/ghi/locked && | |
df0b6cfb | 75 | git worktree prune && |
23af91d1 NTND |
76 | test -d .git/worktrees/ghi |
77 | ' | |
78 | ||
79 | test_expect_success 'not prune recent checkouts' ' | |
807e3cac | 80 | test_when_finished rm -r .git/worktrees && |
327864aa NTND |
81 | git worktree add jlm HEAD && |
82 | test -d .git/worktrees/jlm && | |
83 | rm -rf jlm && | |
df0b6cfb | 84 | git worktree prune --verbose --expire=2.days.ago && |
23af91d1 NTND |
85 | test -d .git/worktrees/jlm |
86 | ' | |
87 | ||
562bc080 MK |
88 | test_expect_success 'not prune proper checkouts' ' |
89 | test_when_finished rm -r .git/worktrees && | |
f194b1ef | 90 | git worktree add --detach "$PWD/nop" master && |
df0b6cfb | 91 | git worktree prune && |
562bc080 MK |
92 | test -d .git/worktrees/nop |
93 | ' | |
94 | ||
23af91d1 | 95 | test_done |