| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2009, Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='log family learns --stdin' |
| 7 | |
| 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
| 11 | . ./test-lib.sh |
| 12 | |
| 13 | check () { |
| 14 | for cmd in rev-list "log --stat" |
| 15 | do |
| 16 | for i in "$@" |
| 17 | do |
| 18 | printf "%s\n" $i |
| 19 | done >input && |
| 20 | test_expect_success "check $cmd $*" ' |
| 21 | git $cmd $(cat input) >expect && |
| 22 | git $cmd --stdin <input >actual && |
| 23 | sed -e "s/^/input /" input && |
| 24 | sed -e "s/^/output /" expect && |
| 25 | test_cmp expect actual |
| 26 | ' |
| 27 | done |
| 28 | } |
| 29 | |
| 30 | them='1 2 3 4 5 6 7' |
| 31 | |
| 32 | test_expect_success setup ' |
| 33 | ( |
| 34 | for i in 0 $them |
| 35 | do |
| 36 | for j in $them |
| 37 | do |
| 38 | echo $i.$j >file-$j && |
| 39 | git add file-$j || exit |
| 40 | done && |
| 41 | test_tick && |
| 42 | git commit -m $i || exit |
| 43 | done && |
| 44 | for i in $them |
| 45 | do |
| 46 | git checkout -b side-$i main~$i && |
| 47 | echo updated $i >file-$i && |
| 48 | git add file-$i && |
| 49 | test_tick && |
| 50 | git commit -m side-$i || exit |
| 51 | done && |
| 52 | |
| 53 | git update-ref refs/heads/-dashed-branch HEAD |
| 54 | ) |
| 55 | ' |
| 56 | |
| 57 | check main |
| 58 | check side-1 ^side-4 |
| 59 | check side-1 ^side-7 -- |
| 60 | check side-1 ^side-7 -- file-1 |
| 61 | check side-1 ^side-7 -- file-2 |
| 62 | check side-3 ^side-4 -- file-3 |
| 63 | check side-3 ^side-2 |
| 64 | check side-3 ^side-2 -- file-1 |
| 65 | check --all |
| 66 | check --all --not --branches |
| 67 | check --glob=refs/heads |
| 68 | check --glob=refs/heads -- |
| 69 | check --glob=refs/heads -- file-1 |
| 70 | check --end-of-options -dashed-branch |
| 71 | check --all --not refs/heads/main |
| 72 | |
| 73 | test_expect_success 'not only --stdin' ' |
| 74 | cat >expect <<-EOF && |
| 75 | 7 |
| 76 | |
| 77 | file-1 |
| 78 | file-2 |
| 79 | EOF |
| 80 | cat >input <<-EOF && |
| 81 | ^main^ |
| 82 | -- |
| 83 | file-2 |
| 84 | EOF |
| 85 | git log --pretty=tformat:%s --name-only --stdin main -- file-1 \ |
| 86 | <input >actual && |
| 87 | test_cmp expect actual |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'pseudo-opt with missing value' ' |
| 91 | cat >input <<-EOF && |
| 92 | --glob |
| 93 | refs/heads |
| 94 | EOF |
| 95 | |
| 96 | cat >expect <<-EOF && |
| 97 | fatal: Option ${SQ}--glob${SQ} requires a value |
| 98 | EOF |
| 99 | |
| 100 | test_must_fail git rev-list --stdin <input 2>error && |
| 101 | test_cmp expect error |
| 102 | ' |
| 103 | |
| 104 | test_expect_success 'pseudo-opt with invalid value' ' |
| 105 | cat >input <<-EOF && |
| 106 | --no-walk=garbage |
| 107 | EOF |
| 108 | |
| 109 | cat >expect <<-EOF && |
| 110 | error: invalid argument to --no-walk |
| 111 | fatal: invalid option ${SQ}--no-walk=garbage${SQ} in --stdin mode |
| 112 | EOF |
| 113 | |
| 114 | test_must_fail git rev-list --stdin <input 2>error && |
| 115 | test_cmp expect error |
| 116 | ' |
| 117 | |
| 118 | test_expect_success 'unknown option without --end-of-options' ' |
| 119 | cat >input <<-EOF && |
| 120 | -dashed-branch |
| 121 | EOF |
| 122 | |
| 123 | cat >expect <<-EOF && |
| 124 | fatal: invalid option ${SQ}-dashed-branch${SQ} in --stdin mode |
| 125 | EOF |
| 126 | |
| 127 | test_must_fail git rev-list --stdin <input 2>error && |
| 128 | test_cmp expect error |
| 129 | ' |
| 130 | |
| 131 | test_expect_success '--not on command line does not influence revisions read via --stdin' ' |
| 132 | cat >input <<-EOF && |
| 133 | refs/heads/main |
| 134 | EOF |
| 135 | git rev-list refs/heads/main >expect && |
| 136 | |
| 137 | git rev-list refs/heads/main --not --stdin <input >actual && |
| 138 | test_cmp expect actual |
| 139 | ' |
| 140 | |
| 141 | test_expect_success '--not via stdin does not influence revisions from command line' ' |
| 142 | cat >input <<-EOF && |
| 143 | --not |
| 144 | EOF |
| 145 | git rev-list refs/heads/main >expect && |
| 146 | |
| 147 | git rev-list refs/heads/main --stdin refs/heads/main <input >actual && |
| 148 | test_cmp expect actual |
| 149 | ' |
| 150 | |
| 151 | test_expect_success '--no-walk filters by path (single commit, match)' ' |
| 152 | git rev-parse side-1 >expect && |
| 153 | git rev-list --no-walk side-1 -- file-1 >actual && |
| 154 | test_cmp expect actual |
| 155 | ' |
| 156 | |
| 157 | test_expect_success '--no-walk filters by path (single commit, no match)' ' |
| 158 | git rev-list --no-walk side-2 -- file-1 >actual && |
| 159 | test_must_be_empty actual |
| 160 | ' |
| 161 | |
| 162 | test_expect_success '--no-walk with pathspec exclusion' ' |
| 163 | git rev-parse side-3 side-2 >expect && |
| 164 | git rev-parse side-1 side-2 side-3 >input && |
| 165 | git rev-list --stdin --no-walk -- ":!file-1" <input >actual && |
| 166 | test_cmp expect actual |
| 167 | ' |
| 168 | |
| 169 | test_done |