Test commit
[cogito/jonas.git] / t / t9400-clean.sh
blob98801c578e12f1cc8c983ff95d6d4db1e7e7b4de
1 #!/usr/bin/env bash
3 # Copyright (c) 2005 Pvel Roskin
5 test_description="Tests basic cg-clean functionality
7 Create files and directories and check that cg-clean removes them
8 (and keeps files and directories it should keep)."
10 . ./test-lib.sh
12 # Use spaces in names to make sure they are handled properly.
13 echo "repo file 1" >"repo file 1"
14 mkdir "repo dir"
15 echo "repo file 2" >"repo dir/repo file 2"
16 echo "*.ign" >".gitignore"
17 echo "*.ign1" >"repo dir/.gitignore"
19 test_expect_success 'initialize repo' \
20 "(cg-add -r * .gitignore && \
21 cg-commit -C -m\"Initial commit\")"
23 echo "extra file 1" >"extra file 1"
24 mkdir "extra dir 1"
25 echo "extra file 2" >"repo dir/extra file 2"
26 mkdir "repo dir/extra dir 2"
27 echo "extra file 3" >"extra dir 1/extra file 3"
28 echo "ign file 1" >"ign file 1.ign"
29 echo "ign file 2" >"ign file 2.ign1"
30 echo "ign file 3" >"repo dir/ign file 3.ign"
31 echo "ign file 4" >"repo dir/ign file 4.ign1"
33 # Create file lists under .git/temp, exclude .git/ from listings.
34 # Compare lists before and after cg-clean and check if only the expected
35 # files were removed.
36 topdir="`pwd`"
37 mkdir .git/temp
38 list="$topdir/.git/temp/list"
40 mklist()
42 cd "$topdir"
43 find . 2>/dev/null | sed -n "/^.\/.git\//d;s/^..//p" |
44 sort > "$list-$1"
47 check_loss()
49 mklist new
50 echo "$loss" | cat - "$list-new" |
51 grep -v ^$ | sort >"$list-combined"
52 diff -u "$list-init" "$list-combined" > "$list.diff" &&
53 cp -f "$list-new" "$list-init"
56 mklist init
57 loss=''
58 test_expect_success 'cg-clean -n in top-level dir' \
59 "(cg-clean -n && check_loss)"
61 test_expect_success 'cg-clean -Ddxqn in top-level dir' \
62 "(cg-clean -Ddxqn && check_loss)"
64 test_expect_success 'cg-clean -n in subdir' \
65 "(cd 'repo dir' && cg-clean -n && check_loss)"
67 loss='repo dir/extra file 2'
68 test_expect_success 'cg-clean in subdir' \
69 "(cd 'repo dir' && cg-clean && check_loss)"
71 loss='repo dir/extra dir 2'
72 test_expect_success 'cg-clean -d in subdir' \
73 "(cd 'repo dir' && cg-clean -d && check_loss)"
75 loss='repo dir/ign file 3.ign
76 repo dir/ign file 4.ign1'
77 test_expect_success 'cg-clean -x in subdir' \
78 "(cd 'repo dir' && cg-clean -x && check_loss)"
80 # Restore extra files in "repo dir"
81 echo "extra file 2" >"repo dir/extra file 2"
82 mkdir "repo dir/extra dir 2"
83 echo "ign file 3" >"repo dir/ign file 3.ign"
84 echo "ign file 4" >"repo dir/ign file 4.ign1"
85 mklist init
87 loss='extra file 1
88 ign file 2.ign1
89 repo dir/extra file 2'
90 test_expect_success 'cg-clean in top-level dir' \
91 "(cg-clean && check_loss)"
93 loss='ign file 1.ign
94 repo dir/ign file 3.ign
95 repo dir/ign file 4.ign1'
96 test_expect_success 'cg-clean -x in top-level dir' \
97 "(cg-clean -x && check_loss)"
99 loss='extra dir 1
100 extra dir 1/extra file 3
101 repo dir/extra dir 2'
102 test_expect_success 'cg-clean -d in top-level dir' \
103 "(cg-clean -d && check_loss)"
105 mkdir "extra dir 3"
106 chmod 000 "extra dir 3"
107 mklist init
108 loss='extra dir 3'
109 test_expect_success 'cg-clean -D in top-level dir' \
110 "(cg-clean -D && check_loss)"
112 test_done