mirror of
https://github.com/git/git.git
synced 2024-12-01 22:13:45 +08:00
fc7d47f0dd
Once upon a time, you could use "--local-env-vars" and
"--resolve-git-dir" outside of any git repository, but they
had to come first on the command line. Commit 68889b4
(rev-parse: remove restrictions on some options, 2013-07-21)
put them into the normal option-parsing loop, fixing the
latter. But it inadvertently broke the former, as we call
setup_git_directory() before starting that loop.
We can note that those options don't care even conditionally
about whether we are in a git repo. So it's fine if we
simply wait to setup the repo until we see an option that
needs it.
However, there is one special exception we should make:
historically, rev-parse will set up the repository and read
config even if there are _no_ options. Some of the
tests in t1300 rely on this to check "git -c $config"
parsing. That's not mirroring real-world use, and we could
tweak the test. But t0002 uses a bare "git rev-parse" to
check "are we in a git repository?". It's plausible that
real-world scripts are relying on this.
So let's cover this case specially, and treat an option-less
"rev-parse" as "see if we're in a repo".
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
46 lines
1.2 KiB
Bash
Executable File
46 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='check that certain rev-parse options work outside repo'
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'set up non-repo directory' '
|
|
GIT_CEILING_DIRECTORIES=$(pwd) &&
|
|
export GIT_CEILING_DIRECTORIES &&
|
|
mkdir non-repo &&
|
|
cd non-repo &&
|
|
# confirm that git does not find a repo
|
|
test_must_fail git rev-parse --git-dir
|
|
'
|
|
|
|
# Rather than directly test the output of sq-quote directly,
|
|
# make sure the shell can read back a tricky case, since
|
|
# that's what we really care about anyway.
|
|
tricky="really tricky with \\ and \" and '"
|
|
dump_args () {
|
|
for i in "$@"; do
|
|
echo "arg: $i"
|
|
done
|
|
}
|
|
test_expect_success 'rev-parse --sq-quote' '
|
|
dump_args "$tricky" easy >expect &&
|
|
eval "dump_args $(git rev-parse --sq-quote "$tricky" easy)" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'rev-parse --local-env-vars' '
|
|
git rev-parse --local-env-vars >actual &&
|
|
# we do not want to depend on the complete list here,
|
|
# so just look for something plausible
|
|
grep ^GIT_DIR actual
|
|
'
|
|
|
|
test_expect_success 'rev-parse --resolve-git-dir' '
|
|
git init --separate-git-dir repo dir &&
|
|
test_must_fail git rev-parse --resolve-git-dir . &&
|
|
echo "$(pwd)/repo" >expect &&
|
|
git rev-parse --resolve-git-dir dir/.git >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_done
|