]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2101-update-index-reupdate.sh
Merge branch 'gc/branch-recurse-submodules'
[thirdparty/git.git] / t / t2101-update-index-reupdate.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Junio C Hamano
4 #
5
6 test_description='git update-index --again test.
7 '
8
9 TEST_PASSES_SANITIZE_LEAK=true
10 . ./test-lib.sh
11
12 test_expect_success 'update-index --add' '
13 echo hello world >file1 &&
14 echo goodbye people >file2 &&
15 git update-index --add file1 file2 &&
16 git ls-files -s >current &&
17 cat >expected <<-EOF &&
18 100644 $(git hash-object file1) 0 file1
19 100644 $(git hash-object file2) 0 file2
20 EOF
21 cmp current expected
22 '
23
24 test_expect_success 'update-index --again' '
25 rm -f file1 &&
26 echo hello everybody >file2 &&
27 if git update-index --again
28 then
29 echo should have refused to remove file1
30 exit 1
31 else
32 echo happy - failed as expected
33 fi &&
34 git ls-files -s >current &&
35 cmp current expected
36 '
37
38 test_expect_success 'update-index --remove --again' '
39 git update-index --remove --again &&
40 git ls-files -s >current &&
41 cat >expected <<-EOF &&
42 100644 $(git hash-object file2) 0 file2
43 EOF
44 cmp current expected
45 '
46
47 test_expect_success 'first commit' 'git commit -m initial'
48
49 test_expect_success 'update-index again' '
50 mkdir -p dir1 &&
51 echo hello world >dir1/file3 &&
52 echo goodbye people >file2 &&
53 git update-index --add file2 dir1/file3 &&
54 echo hello everybody >file2 &&
55 echo happy >dir1/file3 &&
56 git update-index --again &&
57 git ls-files -s >current &&
58 cat >expected <<-EOF &&
59 100644 $(git hash-object dir1/file3) 0 dir1/file3
60 100644 $(git hash-object file2) 0 file2
61 EOF
62 cmp current expected
63 '
64
65 file2=$(git hash-object file2)
66 test_expect_success 'update-index --update from subdir' '
67 echo not so happy >file2 &&
68 (cd dir1 &&
69 cat ../file2 >file3 &&
70 git update-index --again
71 ) &&
72 git ls-files -s >current &&
73 cat >expected <<-EOF &&
74 100644 $(git hash-object dir1/file3) 0 dir1/file3
75 100644 $file2 0 file2
76 EOF
77 test_cmp expected current
78 '
79
80 test_expect_success 'update-index --update with pathspec' '
81 echo very happy >file2 &&
82 cat file2 >dir1/file3 &&
83 git update-index --again dir1/ &&
84 git ls-files -s >current &&
85 cat >expected <<-EOF &&
86 100644 $(git hash-object dir1/file3) 0 dir1/file3
87 100644 $file2 0 file2
88 EOF
89 cmp current expected
90 '
91
92 test_done