Jeff King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Junio C Hamano | 25487bd | 2007-11-11 18:44:16 -0800 | [diff] [blame] | 3 | test_description='git add -u |
Jeff King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 4 | |
| 5 | This 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 Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 11 | and issues a git add -u with path limiting on "dir" to add |
Junio C Hamano | 25487bd | 2007-11-11 18:44:16 -0800 | [diff] [blame] | 12 | only the updates to dir/sub. |
| 13 | |
| 14 | Also tested are "git add -u" without limiting, and "git add -u" |
Junio C Hamano | 4cc8d6c | 2009-01-28 14:24:53 -0800 | [diff] [blame] | 15 | without contents changes, and other conditions' |
Jeff King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 16 | |
| 17 | . ./test-lib.sh |
| 18 | |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 19 | test_expect_success setup ' |
| 20 | echo initial >check && |
| 21 | echo initial >top && |
Benoit Sigoure | 43b98ac | 2007-09-14 10:29:04 +0200 | [diff] [blame] | 22 | echo initial >foo && |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 23 | mkdir dir1 dir2 && |
| 24 | echo initial >dir1/sub1 && |
| 25 | echo initial >dir1/sub2 && |
| 26 | echo initial >dir2/sub3 && |
Benoit Sigoure | 43b98ac | 2007-09-14 10:29:04 +0200 | [diff] [blame] | 27 | git add check dir1 dir2 top foo && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 28 | test_tick && |
Nanako Shiraishi | 0cb0e14 | 2008-09-03 17:59:27 +0900 | [diff] [blame] | 29 | git commit -m initial && |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 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 King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 36 | ' |
| 37 | |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 38 | test_expect_success update ' |
| 39 | git add -u dir1 dir2 |
| 40 | ' |
Jeff King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 41 | |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 42 | test_expect_success 'update noticed a removal' ' |
Nanako Shiraishi | 0cb0e14 | 2008-09-03 17:59:27 +0900 | [diff] [blame] | 43 | test "$(git ls-files dir1/sub1)" = "" |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 44 | ' |
Jeff King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 45 | |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 46 | test_expect_success 'update touched correct path' ' |
Nanako Shiraishi | 0cb0e14 | 2008-09-03 17:59:27 +0900 | [diff] [blame] | 47 | test "$(git diff-files --name-status dir2/sub3)" = "" |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 48 | ' |
Jeff King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 49 | |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 50 | test_expect_success 'update did not touch other tracked files' ' |
Nanako Shiraishi | 0cb0e14 | 2008-09-03 17:59:27 +0900 | [diff] [blame] | 51 | test "$(git diff-files --name-status check)" = "M check" && |
| 52 | test "$(git diff-files --name-status top)" = "M top" |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 53 | ' |
| 54 | |
| 55 | test_expect_success 'update did not touch untracked files' ' |
Nanako Shiraishi | 0cb0e14 | 2008-09-03 17:59:27 +0900 | [diff] [blame] | 56 | test "$(git ls-files dir2/other)" = "" |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 57 | ' |
| 58 | |
| 59 | test_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 && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 65 | test_cmp expect current |
Junio C Hamano | a4882c2 | 2007-08-15 14:12:14 -0700 | [diff] [blame] | 66 | |
| 67 | ' |
Jeff King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 68 | |
Salikh Zakirov | 2ed2c22 | 2007-08-16 02:01:43 +0900 | [diff] [blame] | 69 | test_expect_success 'update from a subdirectory' ' |
| 70 | ( |
| 71 | cd dir1 && |
| 72 | echo more >sub2 && |
| 73 | git add -u sub2 |
| 74 | ) |
| 75 | ' |
| 76 | |
| 77 | test_expect_success 'change gets noticed' ' |
| 78 | |
| 79 | test "$(git diff-files --name-status dir1)" = "" |
| 80 | |
| 81 | ' |
Jeff King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 82 | |
Junio C Hamano | 808d3d7 | 2013-03-19 15:53:17 -0700 | [diff] [blame] | 83 | test_expect_success 'non-qualified update in subdir updates from the root' ' |
Jeff King | 7bf7a92 | 2013-03-14 02:44:04 -0400 | [diff] [blame] | 84 | ( |
| 85 | cd dir1 && |
| 86 | echo even more >>sub2 && |
Junio C Hamano | 29abb33 | 2015-10-24 19:31:11 -0700 | [diff] [blame] | 87 | git --literal-pathspecs add -u && |
| 88 | echo even more >>sub2 && |
Jeff King | 7bf7a92 | 2013-03-14 02:44:04 -0400 | [diff] [blame] | 89 | git add -u |
| 90 | ) && |
Junio C Hamano | 808d3d7 | 2013-03-19 15:53:17 -0700 | [diff] [blame] | 91 | : >expect && |
Jeff King | 7bf7a92 | 2013-03-14 02:44:04 -0400 | [diff] [blame] | 92 | git diff-files --name-only >actual && |
| 93 | test_cmp expect actual |
| 94 | ' |
| 95 | |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 96 | test_expect_success 'replace a file with a symlink' ' |
Benoit Sigoure | 43b98ac | 2007-09-14 10:29:04 +0200 | [diff] [blame] | 97 | |
| 98 | rm foo && |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 99 | test_ln_s_add top foo |
Benoit Sigoure | 43b98ac | 2007-09-14 10:29:04 +0200 | [diff] [blame] | 100 | |
| 101 | ' |
| 102 | |
Junio C Hamano | 25487bd | 2007-11-11 18:44:16 -0800 | [diff] [blame] | 103 | test_expect_success 'add everything changed' ' |
| 104 | |
| 105 | git add -u && |
| 106 | test -z "$(git diff-files)" |
| 107 | |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'touch and then add -u' ' |
| 111 | |
| 112 | touch check && |
| 113 | git add -u && |
| 114 | test -z "$(git diff-files)" |
| 115 | |
| 116 | ' |
| 117 | |
| 118 | test_expect_success 'touch and then add explicitly' ' |
| 119 | |
| 120 | touch check && |
| 121 | git add check && |
| 122 | test -z "$(git diff-files)" |
| 123 | |
| 124 | ' |
| 125 | |
Junio C Hamano | c36f941 | 2011-04-12 15:50:55 -0700 | [diff] [blame] | 126 | test_expect_success 'add -n -u should not add but just report' ' |
Junio C Hamano | 38ed1d8 | 2008-05-21 12:04:34 -0700 | [diff] [blame] | 127 | |
| 128 | ( |
| 129 | echo "add '\''check'\''" && |
| 130 | echo "remove '\''top'\''" |
| 131 | ) >expect && |
| 132 | before=$(git ls-files -s check top) && |
| 133 | echo changed >>check && |
| 134 | rm -f top && |
| 135 | git add -n -u >actual && |
| 136 | after=$(git ls-files -s check top) && |
| 137 | |
| 138 | test "$before" = "$after" && |
Junio C Hamano | c36f941 | 2011-04-12 15:50:55 -0700 | [diff] [blame] | 139 | test_i18ncmp expect actual |
Junio C Hamano | 38ed1d8 | 2008-05-21 12:04:34 -0700 | [diff] [blame] | 140 | |
| 141 | ' |
| 142 | |
Junio C Hamano | 4cc8d6c | 2009-01-28 14:24:53 -0800 | [diff] [blame] | 143 | test_expect_success 'add -u resolves unmerged paths' ' |
| 144 | git reset --hard && |
| 145 | one=$(echo 1 | git hash-object -w --stdin) && |
| 146 | two=$(echo 2 | git hash-object -w --stdin) && |
| 147 | three=$(echo 3 | git hash-object -w --stdin) && |
| 148 | { |
| 149 | for path in path1 path2 |
| 150 | do |
| 151 | echo "100644 $one 1 $path" |
| 152 | echo "100644 $two 2 $path" |
| 153 | echo "100644 $three 3 $path" |
| 154 | done |
| 155 | echo "100644 $one 1 path3" |
| 156 | echo "100644 $one 1 path4" |
| 157 | echo "100644 $one 3 path5" |
| 158 | echo "100644 $one 3 path6" |
| 159 | } | |
| 160 | git update-index --index-info && |
| 161 | echo 3 >path1 && |
| 162 | echo 2 >path3 && |
| 163 | echo 2 >path5 && |
Junio C Hamano | 75973b2 | 2011-04-20 18:11:19 -0700 | [diff] [blame] | 164 | |
Junio C Hamano | 45c45e3 | 2011-04-19 12:18:20 -0700 | [diff] [blame] | 165 | # Fail to explicitly resolve removed paths with "git add" |
| 166 | test_must_fail git add --no-all path4 && |
| 167 | test_must_fail git add --no-all path6 && |
Junio C Hamano | 75973b2 | 2011-04-20 18:11:19 -0700 | [diff] [blame] | 168 | |
| 169 | # "add -u" should notice removals no matter what stages |
| 170 | # the index entries are in. |
Junio C Hamano | 4cc8d6c | 2009-01-28 14:24:53 -0800 | [diff] [blame] | 171 | git add -u && |
Johannes Sixt | 0aaaef7 | 2009-02-09 10:24:51 +0100 | [diff] [blame] | 172 | git ls-files -s path1 path2 path3 path4 path5 path6 >actual && |
Junio C Hamano | 4cc8d6c | 2009-01-28 14:24:53 -0800 | [diff] [blame] | 173 | { |
| 174 | echo "100644 $three 0 path1" |
Junio C Hamano | 4cc8d6c | 2009-01-28 14:24:53 -0800 | [diff] [blame] | 175 | echo "100644 $two 0 path3" |
| 176 | echo "100644 $two 0 path5" |
Junio C Hamano | 75973b2 | 2011-04-20 18:11:19 -0700 | [diff] [blame] | 177 | } >expect && |
| 178 | test_cmp expect actual |
Junio C Hamano | 4cc8d6c | 2009-01-28 14:24:53 -0800 | [diff] [blame] | 179 | ' |
| 180 | |
Chris Packham | 1e7ef74 | 2010-02-09 17:30:48 -0500 | [diff] [blame] | 181 | test_expect_success '"add -u non-existent" should fail' ' |
| 182 | test_must_fail git add -u non-existent && |
| 183 | ! (git ls-files | grep "non-existent") |
| 184 | ' |
| 185 | |
Jeff King | 93c44d4 | 2007-05-12 02:42:00 -0400 | [diff] [blame] | 186 | test_done |