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