Nguyễn Thái Ngọc Duy | 6fd09f5 | 2011-05-08 18:08:26 +0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='magic pathspec tests using git-log' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'setup' ' |
| 8 | test_commit initial && |
| 9 | test_tick && |
| 10 | git commit --allow-empty -m empty && |
| 11 | mkdir sub |
| 12 | ' |
| 13 | |
Nguyễn Thái Ngọc Duy | 4db86e8 | 2013-01-21 20:00:48 +0700 | [diff] [blame] | 14 | test_expect_success '"git log :/" should not be ambiguous' ' |
| 15 | git log :/ |
| 16 | ' |
| 17 | |
| 18 | test_expect_success '"git log :/a" should be ambiguous (applied both rev and worktree)' ' |
| 19 | : >a && |
| 20 | test_must_fail git log :/a 2>error && |
Vasco Almeida | ab33a76 | 2016-06-17 20:21:06 +0000 | [diff] [blame] | 21 | test_i18ngrep ambiguous error |
Nguyễn Thái Ngọc Duy | 6fd09f5 | 2011-05-08 18:08:26 +0700 | [diff] [blame] | 22 | ' |
| 23 | |
Nguyễn Thái Ngọc Duy | 4db86e8 | 2013-01-21 20:00:48 +0700 | [diff] [blame] | 24 | test_expect_success '"git log :/a -- " should not be ambiguous' ' |
| 25 | git log :/a -- |
| 26 | ' |
| 27 | |
William Chargin | 6b3351e | 2018-07-11 22:49:09 -0700 | [diff] [blame] | 28 | test_expect_success '"git log :/detached -- " should find a commit only in HEAD' ' |
| 29 | test_when_finished "git checkout master" && |
| 30 | git checkout --detach && |
| 31 | # Must manually call `test_tick` instead of using `test_commit`, |
| 32 | # because the latter additionally creates a tag, which would make |
| 33 | # the commit reachable not only via HEAD. |
| 34 | test_tick && |
| 35 | git commit --allow-empty -m detached && |
| 36 | test_tick && |
| 37 | git commit --allow-empty -m something-else && |
| 38 | git log :/detached -- |
| 39 | ' |
| 40 | |
| 41 | test_expect_success '"git log :/detached -- " should not find an orphaned commit' ' |
| 42 | test_must_fail git log :/detached -- |
| 43 | ' |
| 44 | |
| 45 | test_expect_success '"git log :/detached -- " should find HEAD only of own worktree' ' |
| 46 | git worktree add other-tree HEAD && |
| 47 | git -C other-tree checkout --detach && |
| 48 | test_tick && |
| 49 | git -C other-tree commit --allow-empty -m other-detached && |
| 50 | git -C other-tree log :/other-detached -- && |
| 51 | test_must_fail git log :/other-detached -- |
| 52 | ' |
| 53 | |
Nguyễn Thái Ngọc Duy | 4db86e8 | 2013-01-21 20:00:48 +0700 | [diff] [blame] | 54 | test_expect_success '"git log -- :/a" should not be ambiguous' ' |
| 55 | git log -- :/a |
| 56 | ' |
| 57 | |
Jeff King | be6ed3f | 2017-05-26 15:06:41 -0400 | [diff] [blame] | 58 | # This differs from the ":/a" check above in that :/in looks like a pathspec, |
| 59 | # but doesn't match an actual file. |
| 60 | test_expect_success '"git log :/in" should not be ambiguous' ' |
| 61 | git log :/in |
| 62 | ' |
| 63 | |
Nguyễn Thái Ngọc Duy | 6fd09f5 | 2011-05-08 18:08:26 +0700 | [diff] [blame] | 64 | test_expect_success '"git log :" should be ambiguous' ' |
| 65 | test_must_fail git log : 2>error && |
Vasco Almeida | ab33a76 | 2016-06-17 20:21:06 +0000 | [diff] [blame] | 66 | test_i18ngrep ambiguous error |
Nguyễn Thái Ngọc Duy | 6fd09f5 | 2011-05-08 18:08:26 +0700 | [diff] [blame] | 67 | ' |
| 68 | |
| 69 | test_expect_success 'git log -- :' ' |
| 70 | git log -- : |
| 71 | ' |
| 72 | |
| 73 | test_expect_success 'git log HEAD -- :/' ' |
brian m. carlson | 0b2c4af | 2018-05-21 02:01:46 +0000 | [diff] [blame] | 74 | initial=$(git rev-parse --short HEAD^) && |
Nguyễn Thái Ngọc Duy | 6fd09f5 | 2011-05-08 18:08:26 +0700 | [diff] [blame] | 75 | cat >expected <<-EOF && |
brian m. carlson | 0b2c4af | 2018-05-21 02:01:46 +0000 | [diff] [blame] | 76 | $initial initial |
Nguyễn Thái Ngọc Duy | 6fd09f5 | 2011-05-08 18:08:26 +0700 | [diff] [blame] | 77 | EOF |
| 78 | (cd sub && git log --oneline HEAD -- :/ >../actual) && |
| 79 | test_cmp expected actual |
| 80 | ' |
| 81 | |
Jeff King | 42471bc | 2017-05-26 15:08:39 -0400 | [diff] [blame] | 82 | test_expect_success '"git log :^sub" is not ambiguous' ' |
| 83 | git log :^sub |
| 84 | ' |
| 85 | |
| 86 | test_expect_success '"git log :^does-not-exist" does not match anything' ' |
| 87 | test_must_fail git log :^does-not-exist |
| 88 | ' |
| 89 | |
| 90 | test_expect_success '"git log :!" behaves the same as :^' ' |
| 91 | git log :!sub && |
| 92 | test_must_fail git log :!does-not-exist |
| 93 | ' |
| 94 | |
Jeff King | c99eddd | 2017-05-26 15:10:31 -0400 | [diff] [blame] | 95 | test_expect_success '"git log :(exclude)sub" is not ambiguous' ' |
| 96 | git log ":(exclude)sub" |
| 97 | ' |
| 98 | |
| 99 | test_expect_success '"git log :(exclude)sub --" must resolve as an object' ' |
| 100 | test_must_fail git log ":(exclude)sub" -- |
| 101 | ' |
| 102 | |
| 103 | test_expect_success '"git log :(unknown-magic) complains of bogus magic' ' |
| 104 | test_must_fail git log ":(unknown-magic)" 2>error && |
| 105 | test_i18ngrep pathspec.magic error |
| 106 | ' |
| 107 | |
Nguyễn Thái Ngọc Duy | c8556c6 | 2013-10-19 09:41:24 +0700 | [diff] [blame] | 108 | test_expect_success 'command line pathspec parsing for "git log"' ' |
| 109 | git reset --hard && |
| 110 | >a && |
| 111 | git add a && |
| 112 | git commit -m "add an empty a" --allow-empty && |
| 113 | echo 1 >a && |
| 114 | git commit -a -m "update a to 1" && |
| 115 | git checkout HEAD^ && |
| 116 | echo 2 >a && |
| 117 | git commit -a -m "update a to 2" && |
| 118 | test_must_fail git merge master && |
| 119 | git add a && |
| 120 | git log --merge -- a |
| 121 | ' |
| 122 | |
Brandon Williams | eef3df5 | 2017-12-04 16:07:34 -0800 | [diff] [blame] | 123 | test_expect_success 'tree_entry_interesting does not match past submodule boundaries' ' |
| 124 | test_when_finished "rm -rf repo submodule" && |
| 125 | git init submodule && |
| 126 | test_commit -C submodule initial && |
| 127 | git init repo && |
| 128 | >"repo/[bracket]" && |
| 129 | git -C repo add "[bracket]" && |
| 130 | test_tick && |
| 131 | git -C repo commit -m bracket && |
| 132 | git -C repo rev-list HEAD -- "[bracket]" >expect && |
| 133 | |
| 134 | git -C repo submodule add ../submodule && |
| 135 | test_tick && |
| 136 | git -C repo commit -m submodule && |
| 137 | |
| 138 | git -C repo rev-list HEAD -- "[bracket]" >actual && |
| 139 | test_cmp expect actual |
| 140 | ' |
| 141 | |
Nguyễn Thái Ngọc Duy | 6fd09f5 | 2011-05-08 18:08:26 +0700 | [diff] [blame] | 142 | test_done |