blob: 24f892f79386478fd5f1162654cb9b72d940bbe4 [file] [log] [blame]
Jeff King93c44d42007-05-12 02:42:00 -04001#!/bin/sh
2
Junio C Hamano25487bd2007-11-11 18:44:16 -08003test_description='git add -u
Jeff King93c44d42007-05-12 02:42:00 -04004
5This test creates a working tree state with three files:
6
7 top (previously committed, modified)
8 dir/sub (previously committed, modified)
9 dir/other (untracked)
10
Junio C Hamano5be60072007-07-02 22:52:14 -070011and issues a git add -u with path limiting on "dir" to add
Junio C Hamano25487bd2007-11-11 18:44:16 -080012only the updates to dir/sub.
13
14Also tested are "git add -u" without limiting, and "git add -u"
15without contents changes.'
Jeff King93c44d42007-05-12 02:42:00 -040016
17. ./test-lib.sh
18
Junio C Hamanoa4882c22007-08-15 14:12:14 -070019test_expect_success setup '
20 echo initial >check &&
21 echo initial >top &&
Benoit Sigoure43b98ac2007-09-14 10:29:04 +020022 echo initial >foo &&
Junio C Hamanoa4882c22007-08-15 14:12:14 -070023 mkdir dir1 dir2 &&
24 echo initial >dir1/sub1 &&
25 echo initial >dir1/sub2 &&
26 echo initial >dir2/sub3 &&
Benoit Sigoure43b98ac2007-09-14 10:29:04 +020027 git add check dir1 dir2 top foo &&
Junio C Hamanoa4882c22007-08-15 14:12:14 -070028 test_tick
29 git-commit -m initial &&
30
31 echo changed >check &&
32 echo changed >top &&
33 echo changed >dir2/sub3 &&
34 rm -f dir1/sub1 &&
35 echo other >dir2/other
Jeff King93c44d42007-05-12 02:42:00 -040036'
37
Junio C Hamanoa4882c22007-08-15 14:12:14 -070038test_expect_success update '
39 git add -u dir1 dir2
40'
Jeff King93c44d42007-05-12 02:42:00 -040041
Junio C Hamanoa4882c22007-08-15 14:12:14 -070042test_expect_success 'update noticed a removal' '
43 test "$(git-ls-files dir1/sub1)" = ""
44'
Jeff King93c44d42007-05-12 02:42:00 -040045
Junio C Hamanoa4882c22007-08-15 14:12:14 -070046test_expect_success 'update touched correct path' '
47 test "$(git-diff-files --name-status dir2/sub3)" = ""
48'
Jeff King93c44d42007-05-12 02:42:00 -040049
Junio C Hamanoa4882c22007-08-15 14:12:14 -070050test_expect_success 'update did not touch other tracked files' '
51 test "$(git-diff-files --name-status check)" = "M check" &&
52 test "$(git-diff-files --name-status top)" = "M top"
53'
54
55test_expect_success 'update did not touch untracked files' '
56 test "$(git-ls-files dir2/other)" = ""
57'
58
59test_expect_success 'cache tree has not been corrupted' '
60
61 git ls-files -s |
62 sed -e "s/ 0 / /" >expect &&
63 git ls-tree -r $(git write-tree) |
64 sed -e "s/ blob / /" >current &&
65 diff -u expect current
66
67'
Jeff King93c44d42007-05-12 02:42:00 -040068
Salikh Zakirov2ed2c222007-08-16 02:01:43 +090069test_expect_success 'update from a subdirectory' '
70 (
71 cd dir1 &&
72 echo more >sub2 &&
73 git add -u sub2
74 )
75'
76
77test_expect_success 'change gets noticed' '
78
79 test "$(git diff-files --name-status dir1)" = ""
80
81'
Jeff King93c44d42007-05-12 02:42:00 -040082
Benoit Sigoure43b98ac2007-09-14 10:29:04 +020083test_expect_success 'replace a file with a symlink' '
84
85 rm foo &&
86 ln -s top foo &&
87 git add -u -- foo
88
89'
90
Junio C Hamano25487bd2007-11-11 18:44:16 -080091test_expect_success 'add everything changed' '
92
93 git add -u &&
94 test -z "$(git diff-files)"
95
96'
97
98test_expect_success 'touch and then add -u' '
99
100 touch check &&
101 git add -u &&
102 test -z "$(git diff-files)"
103
104'
105
106test_expect_success 'touch and then add explicitly' '
107
108 touch check &&
109 git add check &&
110 test -z "$(git diff-files)"
111
112'
113
Jeff King93c44d42007-05-12 02:42:00 -0400114test_done