Nguyễn Thái Ngọc Duy | 9c7c27e | 2010-10-22 01:51:00 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='basic update-index tests |
| 4 | |
| 5 | Tests for command-line parsing and basic operation. |
| 6 | ' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success 'update-index --nonsense fails' ' |
| 11 | test_must_fail git update-index --nonsense 2>msg && |
| 12 | cat msg && |
| 13 | test -s msg |
| 14 | ' |
| 15 | |
Jeff King | ac5ad86 | 2010-12-18 22:53:58 -0500 | [diff] [blame] | 16 | test_expect_success 'update-index --nonsense dumps usage' ' |
Nguyễn Thái Ngọc Duy | 9c7c27e | 2010-10-22 01:51:00 -0500 | [diff] [blame] | 17 | test_expect_code 129 git update-index --nonsense 2>err && |
Jiang Xin | 9a00138 | 2012-08-27 13:36:55 +0800 | [diff] [blame] | 18 | test_i18ngrep "[Uu]sage: git update-index" err |
Nguyễn Thái Ngọc Duy | 9c7c27e | 2010-10-22 01:51:00 -0500 | [diff] [blame] | 19 | ' |
| 20 | |
| 21 | test_expect_success 'update-index -h with corrupt index' ' |
| 22 | mkdir broken && |
| 23 | ( |
| 24 | cd broken && |
| 25 | git init && |
| 26 | >.git/index && |
| 27 | test_expect_code 129 git update-index -h >usage 2>&1 |
| 28 | ) && |
Jiang Xin | 9a00138 | 2012-08-27 13:36:55 +0800 | [diff] [blame] | 29 | test_i18ngrep "[Uu]sage: git update-index" broken/usage |
Nguyễn Thái Ngọc Duy | 9c7c27e | 2010-10-22 01:51:00 -0500 | [diff] [blame] | 30 | ' |
| 31 | |
Jeff King | c8e1ee4 | 2014-06-04 03:11:11 -0400 | [diff] [blame] | 32 | test_expect_success '--cacheinfo complains of missing arguments' ' |
| 33 | test_must_fail git update-index --cacheinfo |
| 34 | ' |
| 35 | |
Jeff King | 4337b58 | 2012-07-28 11:05:24 -0400 | [diff] [blame] | 36 | test_expect_success '--cacheinfo does not accept blob null sha1' ' |
| 37 | echo content >file && |
| 38 | git add file && |
| 39 | git rev-parse :file >expect && |
| 40 | test_must_fail git update-index --cacheinfo 100644 $_z40 file && |
| 41 | git rev-parse :file >actual && |
| 42 | test_cmp expect actual |
| 43 | ' |
| 44 | |
| 45 | test_expect_success '--cacheinfo does not accept gitlink null sha1' ' |
| 46 | git init submodule && |
| 47 | (cd submodule && test_commit foo) && |
| 48 | git add submodule && |
| 49 | git rev-parse :submodule >expect && |
| 50 | test_must_fail git update-index --cacheinfo 160000 $_z40 submodule && |
| 51 | git rev-parse :submodule >actual && |
| 52 | test_cmp expect actual |
| 53 | ' |
| 54 | |
Junio C Hamano | ec160ae | 2014-03-23 16:57:28 -0700 | [diff] [blame] | 55 | test_expect_success '--cacheinfo mode,sha1,path (new syntax)' ' |
| 56 | echo content >file && |
| 57 | git hash-object -w --stdin <file >expect && |
| 58 | |
| 59 | git update-index --add --cacheinfo 100644 "$(cat expect)" file && |
| 60 | git rev-parse :file >actual && |
| 61 | test_cmp expect actual && |
| 62 | |
| 63 | git update-index --add --cacheinfo "100644,$(cat expect),elif" && |
| 64 | git rev-parse :elif >actual && |
| 65 | test_cmp expect actual |
| 66 | ' |
| 67 | |
Nguyễn Thái Ngọc Duy | fa137f6 | 2014-11-02 07:24:37 +0100 | [diff] [blame] | 68 | test_expect_success '.lock files cleaned up' ' |
| 69 | mkdir cleanup && |
| 70 | ( |
| 71 | cd cleanup && |
| 72 | mkdir worktree && |
| 73 | git init repo && |
| 74 | cd repo && |
| 75 | git config core.worktree ../../worktree && |
| 76 | # --refresh triggers late setup_work_tree, |
| 77 | # active_cache_changed is zero, rollback_lock_file fails |
| 78 | git update-index --refresh && |
| 79 | ! test -f .git/index.lock |
| 80 | ) |
| 81 | ' |
| 82 | |
Nguyễn Thái Ngọc Duy | 9c7c27e | 2010-10-22 01:51:00 -0500 | [diff] [blame] | 83 | test_done |