Junio C Hamano | 3942581 | 2008-08-21 01:44:53 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Intent to add' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'intent to add' ' |
| 8 | echo hello >file && |
| 9 | echo hello >elif && |
| 10 | git add -N file && |
Junio C Hamano | 78cc1a5 | 2015-06-23 10:27:47 -0700 | [diff] [blame] | 11 | git add elif |
Junio C Hamano | 3942581 | 2008-08-21 01:44:53 -0700 | [diff] [blame] | 12 | ' |
| 13 | |
| 14 | test_expect_success 'check result of "add -N"' ' |
| 15 | git ls-files -s file >actual && |
| 16 | empty=$(git hash-object --stdin </dev/null) && |
| 17 | echo "100644 $empty 0 file" >expect && |
| 18 | test_cmp expect actual |
| 19 | ' |
| 20 | |
| 21 | test_expect_success 'intent to add is just an ordinary empty blob' ' |
| 22 | git add -u && |
| 23 | git ls-files -s file >actual && |
| 24 | git ls-files -s elif | sed -e "s/elif/file/" >expect && |
| 25 | test_cmp expect actual |
| 26 | ' |
| 27 | |
| 28 | test_expect_success 'intent to add does not clobber existing paths' ' |
| 29 | git add -N file elif && |
| 30 | empty=$(git hash-object --stdin </dev/null) && |
| 31 | git ls-files -s >actual && |
| 32 | ! grep "$empty" actual |
| 33 | ' |
| 34 | |
Junio C Hamano | 3f6d56d | 2012-02-07 11:55:48 -0800 | [diff] [blame] | 35 | test_expect_success 'i-t-a entry is simply ignored' ' |
Junio C Hamano | 331fcb5 | 2008-11-28 19:56:34 -0800 | [diff] [blame] | 36 | test_tick && |
| 37 | git commit -a -m initial && |
| 38 | git reset --hard && |
| 39 | |
| 40 | echo xyzzy >rezrov && |
| 41 | echo frotz >nitfol && |
| 42 | git add rezrov && |
| 43 | git add -N nitfol && |
Junio C Hamano | 3f6d56d | 2012-02-07 11:55:48 -0800 | [diff] [blame] | 44 | git commit -m second && |
| 45 | test $(git ls-tree HEAD -- nitfol | wc -l) = 0 && |
Junio C Hamano | 78cc1a5 | 2015-06-23 10:27:47 -0700 | [diff] [blame] | 46 | test $(git diff --name-only HEAD -- nitfol | wc -l) = 1 |
Junio C Hamano | 331fcb5 | 2008-11-28 19:56:34 -0800 | [diff] [blame] | 47 | ' |
| 48 | |
| 49 | test_expect_success 'can commit with an unrelated i-t-a entry in index' ' |
| 50 | git reset --hard && |
Junio C Hamano | 3f6d56d | 2012-02-07 11:55:48 -0800 | [diff] [blame] | 51 | echo bozbar >rezrov && |
Junio C Hamano | 331fcb5 | 2008-11-28 19:56:34 -0800 | [diff] [blame] | 52 | echo frotz >nitfol && |
| 53 | git add rezrov && |
| 54 | git add -N nitfol && |
| 55 | git commit -m partial rezrov |
| 56 | ' |
| 57 | |
| 58 | test_expect_success 'can "commit -a" with an i-t-a entry' ' |
| 59 | git reset --hard && |
| 60 | : >nitfol && |
| 61 | git add -N nitfol && |
| 62 | git commit -a -m all |
| 63 | ' |
| 64 | |
Nguyễn Thái Ngọc Duy | eec3e7e | 2012-12-16 11:15:28 +0700 | [diff] [blame] | 65 | test_expect_success 'cache-tree invalidates i-t-a paths' ' |
| 66 | git reset --hard && |
| 67 | mkdir dir && |
| 68 | : >dir/foo && |
| 69 | git add dir/foo && |
| 70 | git commit -m foo && |
| 71 | |
| 72 | : >dir/bar && |
| 73 | git add -N dir/bar && |
| 74 | git diff --cached --name-only >actual && |
Junio C Hamano | 78cc1a5 | 2015-06-23 10:27:47 -0700 | [diff] [blame] | 75 | echo dir/bar >expect && |
Nguyễn Thái Ngọc Duy | eec3e7e | 2012-12-16 11:15:28 +0700 | [diff] [blame] | 76 | test_cmp expect actual && |
| 77 | |
| 78 | git write-tree >/dev/null && |
| 79 | |
| 80 | git diff --cached --name-only >actual && |
Junio C Hamano | 78cc1a5 | 2015-06-23 10:27:47 -0700 | [diff] [blame] | 81 | echo dir/bar >expect && |
Nguyễn Thái Ngọc Duy | eec3e7e | 2012-12-16 11:15:28 +0700 | [diff] [blame] | 82 | test_cmp expect actual |
| 83 | ' |
| 84 | |
Junio C Hamano | 3942581 | 2008-08-21 01:44:53 -0700 | [diff] [blame] | 85 | test_done |
| 86 | |