git/t/t4208-log-magic-pathspec.sh

146 lines
3.7 KiB
Bash
Raw Normal View History

#!/bin/sh
test_description='magic pathspec tests using git-log'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
tests: mark tests relying on the current default for `init.defaultBranch` In addition to the manual adjustment to let the `linux-gcc` CI job run the test suite with `master` and then with `main`, this patch makes sure that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts that currently rely on the initial branch name being `master by default. To determine which test scripts to mark up, the first step was to force-set the default branch name to `master` in - all test scripts that contain the keyword `master`, - t4211, which expects `t/t4211/history.export` with a hard-coded ref to initialize the default branch, - t5560 because it sources `t/t556x_common` which uses `master`, - t8002 and t8012 because both source `t/annotate-tests.sh` which also uses `master`) This trick was performed by this command: $ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\ ' $(git grep -l master t/t[0-9]*.sh) \ t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh After that, careful, manual inspection revealed that some of the test scripts containing the needle `master` do not actually rely on a specific default branch name: either they mention `master` only in a comment, or they initialize that branch specificially, or they do not actually refer to the current default branch. Therefore, the aforementioned modification was undone in those test scripts thusly: $ git checkout HEAD -- \ t/t0027-auto-crlf.sh t/t0060-path-utils.sh \ t/t1011-read-tree-sparse-checkout.sh \ t/t1305-config-include.sh t/t1309-early-config.sh \ t/t1402-check-ref-format.sh t/t1450-fsck.sh \ t/t2024-checkout-dwim.sh \ t/t2106-update-index-assume-unchanged.sh \ t/t3040-subprojects-basic.sh t/t3301-notes.sh \ t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \ t/t3436-rebase-more-options.sh \ t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \ t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \ t/t5511-refspec.sh t/t5526-fetch-submodules.sh \ t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \ t/t5548-push-porcelain.sh \ t/t5552-skipping-fetch-negotiator.sh \ t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \ t/t5614-clone-submodules-shallow.sh \ t/t7508-status.sh t/t7606-merge-custom.sh \ t/t9302-fast-import-unpack-limit.sh We excluded one set of test scripts in these commands, though: the range of `git p4` tests. The reason? `git p4` stores the (foreign) remote branch in the branch called `p4/master`, which is obviously not the default branch. Manual analysis revealed that only five of these tests actually require a specific default branch name to pass; They were modified thusly: $ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\ ' t/t980[0167]*.sh t/t9811*.sh Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-18 23:44:19 +00:00
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
test_expect_success 'setup' '
test_commit initial &&
test_tick &&
git commit --allow-empty -m empty &&
mkdir sub
'
test_expect_success '"git log :/" should not be ambiguous' '
git log :/
'
test_expect_success '"git log :/a" should be ambiguous (applied both rev and worktree)' '
: >a &&
test_must_fail git log :/a 2>error &&
test_i18ngrep ambiguous error
'
test_expect_success '"git log :/a -- " should not be ambiguous' '
git log :/a --
'
test_expect_success '"git log :/detached -- " should find a commit only in HEAD' '
test_when_finished "git checkout main" &&
git checkout --detach &&
test_commit --no-tag detached &&
test_commit --no-tag something-else &&
git log :/detached --
'
test_expect_success '"git log :/detached -- " should not find an orphaned commit' '
test_must_fail git log :/detached --
'
test_expect_success '"git log :/detached -- " should find HEAD only of own worktree' '
git worktree add other-tree HEAD &&
git -C other-tree checkout --detach &&
test_tick &&
git -C other-tree commit --allow-empty -m other-detached &&
git -C other-tree log :/other-detached -- &&
test_must_fail git log :/other-detached --
'
test_expect_success '"git log -- :/a" should not be ambiguous' '
git log -- :/a
'
test_expect_success '"git log :/any/path/" should not segfault' '
test_must_fail git log :/any/path/
'
# This differs from the ":/a" check above in that :/in looks like a pathspec,
# but doesn't match an actual file.
test_expect_success '"git log :/in" should not be ambiguous' '
git log :/in
'
test_expect_success '"git log :" should be ambiguous' '
test_must_fail git log : 2>error &&
test_i18ngrep ambiguous error
'
test_expect_success 'git log -- :' '
git log -- :
'
test_expect_success 'git log HEAD -- :/' '
initial=$(git rev-parse --short HEAD^) &&
cat >expected <<-EOF &&
$initial initial
EOF
(cd sub && git log --oneline HEAD -- :/ >../actual) &&
test_cmp expected actual
'
test_expect_success '"git log :^sub" is not ambiguous' '
git log :^sub
'
test_expect_success '"git log :^does-not-exist" does not match anything' '
test_must_fail git log :^does-not-exist
'
test_expect_success '"git log :!" behaves the same as :^' '
git log :!sub &&
test_must_fail git log :!does-not-exist
'
verify_filename(): treat ":(magic)" as a pathspec For commands that take revisions and pathspecs, magic pathspecs like ":(exclude)foo" require the user to specify a disambiguating "--", since they do not match a file in the filesystem, like: git grep foo -- :(exclude)bar This makes them more annoying to use than they need to be. We loosened the rules for wildcards in 28fcc0b71 (pathspec: avoid the need of "--" when wildcard is used, 2015-05-02). Let's do the same for pathspecs with long-form magic. We already handle the short-forms ":/" and ":^" specially in check_filename(), so we don't need to handle them here. And in fact, we could do the same with long-form magic, parsing out the actual filename and making sure it exists. But there are a few reasons not to do it that way: - the parsing gets much more complicated, and we'd want to hand it off to the pathspec code. But that code isn't ready to do this kind of speculative parsing (it's happy to die() when it sees a syntactically invalid pathspec). - not all pathspec magic maps to a filesystem path. E.g., :(attr) should be treated as a pathspec regardless of what is in the filesystem - we can be a bit looser with ":(" than with the short-form ":/", because it is much less likely to have a false positive. Whereas ":/" also means "search for a commit with this regex". Note that because the change is in verify_filename() and not in its helper check_filename(), this doesn't affect the verify_non_filename() case. I.e., if an item that matches our new rule doesn't resolve as an object, we may fallback to treating it as a pathspec (rather than complaining it doesn't exist). But if it does resolve (e.g., as a file in the index that starts with an open-paren), we won't then complain that it's also a valid pathspec. This matches the wildcard-exception behavior. And of course in either case, one can always insert the "--" to get more precise results. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-26 19:10:31 +00:00
test_expect_success '"git log :(exclude)sub" is not ambiguous' '
git log ":(exclude)sub"
'
test_expect_success '"git log :(exclude)sub --" must resolve as an object' '
test_must_fail git log ":(exclude)sub" --
'
test_expect_success '"git log :(unknown-magic) complains of bogus magic' '
test_must_fail git log ":(unknown-magic)" 2>error &&
test_i18ngrep pathspec.magic error
'
test_expect_success 'command line pathspec parsing for "git log"' '
git reset --hard &&
>a &&
git add a &&
git commit -m "add an empty a" --allow-empty &&
echo 1 >a &&
git commit -a -m "update a to 1" &&
git checkout HEAD^ &&
echo 2 >a &&
git commit -a -m "update a to 2" &&
test_must_fail git merge main &&
git add a &&
git log --merge -- a
'
test_expect_success 'tree_entry_interesting does not match past submodule boundaries' '
test_when_finished "rm -rf repo submodule" &&
test_config_global protocol.file.allow always &&
git init submodule &&
test_commit -C submodule initial &&
git init repo &&
>"repo/[bracket]" &&
git -C repo add "[bracket]" &&
test_tick &&
git -C repo commit -m bracket &&
git -C repo rev-list HEAD -- "[bracket]" >expect &&
git -C repo submodule add ../submodule &&
test_tick &&
git -C repo commit -m submodule &&
git -C repo rev-list HEAD -- "[bracket]" >actual &&
test_cmp expect actual
'
test_done