2008-02-20 22:13:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='.git file
|
|
|
|
|
|
|
|
Verify that plumbing commands work when .git is a file
|
|
|
|
'
|
2020-11-18 23:44:21 +00:00
|
|
|
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
|
|
|
|
|
2021-10-12 13:56:37 +00:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2008-02-20 22:13:13 +00:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
objpath() {
|
2013-12-08 05:56:57 +00:00
|
|
|
echo "$1" | sed -e 's|\(..\)|\1/|'
|
2008-02-20 22:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'initial setup' '
|
|
|
|
REAL="$(pwd)/.real" &&
|
|
|
|
mv .git "$REAL"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'bad setup: invalid .git file format' '
|
|
|
|
echo "gitdir $REAL" >.git &&
|
2018-02-10 11:31:29 +00:00
|
|
|
test_must_fail git rev-parse 2>.err &&
|
2018-02-27 18:33:58 +00:00
|
|
|
test_i18ngrep "invalid gitfile format" .err
|
2008-02-20 22:13:13 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'bad setup: invalid .git file path' '
|
|
|
|
echo "gitdir: $REAL.not" >.git &&
|
2018-02-10 11:31:29 +00:00
|
|
|
test_must_fail git rev-parse 2>.err &&
|
2018-02-27 18:33:58 +00:00
|
|
|
test_i18ngrep "not a git repository" .err
|
2008-02-20 22:13:13 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'final setup + check rev-parse --git-dir' '
|
|
|
|
echo "gitdir: $REAL" >.git &&
|
|
|
|
test "$REAL" = "$(git rev-parse --git-dir)"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check hash-object' '
|
|
|
|
echo "foo" >bar &&
|
|
|
|
SHA=$(cat bar | git hash-object -w --stdin) &&
|
2018-02-10 11:31:29 +00:00
|
|
|
test_path_is_file "$REAL/objects/$(objpath $SHA)"
|
2008-02-20 22:13:13 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check cat-file' '
|
|
|
|
git cat-file blob $SHA >actual &&
|
2008-07-22 21:17:43 +00:00
|
|
|
test_cmp bar actual
|
2008-02-20 22:13:13 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check update-index' '
|
2018-02-10 11:31:29 +00:00
|
|
|
test_path_is_missing "$REAL/index" &&
|
2008-02-20 22:13:13 +00:00
|
|
|
rm -f "$REAL/objects/$(objpath $SHA)" &&
|
|
|
|
git update-index --add bar &&
|
2018-02-10 11:31:29 +00:00
|
|
|
test_path_is_file "$REAL/index" &&
|
|
|
|
test_path_is_file "$REAL/objects/$(objpath $SHA)"
|
2008-02-20 22:13:13 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check write-tree' '
|
|
|
|
SHA=$(git write-tree) &&
|
2018-02-10 11:31:29 +00:00
|
|
|
test_path_is_file "$REAL/objects/$(objpath $SHA)"
|
2008-02-20 22:13:13 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check commit-tree' '
|
|
|
|
SHA=$(echo "commit bar" | git commit-tree $SHA) &&
|
2018-02-10 11:31:29 +00:00
|
|
|
test_path_is_file "$REAL/objects/$(objpath $SHA)"
|
2008-02-20 22:13:13 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check rev-list' '
|
2020-05-20 17:36:08 +00:00
|
|
|
git update-ref "HEAD" "$SHA" &&
|
2008-02-20 22:13:13 +00:00
|
|
|
test "$SHA" = "$(git rev-list HEAD)"
|
|
|
|
'
|
|
|
|
|
setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when ..
Commit d95138e [1] attempted to fix a .git file problem by
setting GIT_WORK_TREE whenever GIT_DIR is set. It sounded harmless
because we handle GIT_DIR and GIT_WORK_TREE side by side for most
commands, with two exceptions: git-init and git-clone.
"git clone" is not happy with d95138e. This command ignores GIT_DIR
but respects GIT_WORK_TREE [2] [3] which means it used to run fine
from a hook, where GIT_DIR was set but GIT_WORK_TREE was not (*).
With d95138e, GIT_WORK_TREE is set all the time and git-clone
interprets that as "I give you order to put the worktree here",
usually against the user's intention.
The solution in d95138e is reverted earlier, and instead we reuse
the solution from c056261 [4]. It fixed another setup-messed-
up-by-alias by saving and restoring env and spawning a new process,
but for git-clone and git-init only.
Now we conclude that setup-messed-up-by-alias is always evil. So the
env restoration is done for _all_ commands, including external ones,
whenever aliases are involved. It fixes what d95138e tried to fix,
without upsetting git-clone-inside-hooks.
The test from d95138e remains to verify it's not broken by this. A new
test is added to make sure git-clone-inside-hooks remains happy.
(*) GIT_WORK_TREE was not set _most of the time_. In some cases
GIT_WORK_TREE is set and git-clone will behave differently. The
use of GIT_WORK_TREE to direct git-clone to put work tree
elsewhere looks like a mistake because it causes surprises this
way. But that's a separate story.
[1] d95138e (setup: set env $GIT_WORK_TREE when work tree is set, like
$GIT_DIR - 2015-06-26)
[2] 2beebd2 (clone: create intermediate directories of destination
repo - 2008-06-25)
[3] 20ccef4 (make git-clone GIT_WORK_TREE aware - 2007-07-06)
[4] c056261 (git potty: restore environments after alias expansion -
2014-06-08)
Reported-by: Anthony Sottile <asottile@umich.edu>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-12-20 07:50:18 +00:00
|
|
|
test_expect_success 'setup_git_dir twice in subdir' '
|
setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR
In the test case, we run setup_git_dir_gently() the first time to read
$GIT_DIR/config so that we can resolve aliases. We'll enter
setup_discovered_git_dir() and may or may not call set_git_dir() near
the end of the function, depending on whether the detected git dir is
".git" or not. This set_git_dir() will set env var $GIT_DIR.
For normal repo, git dir detected via setup_discovered_git_dir() will be
".git", and set_git_dir() is not called. If .git file is used however,
the git dir can't be ".git" and set_git_dir() is called and $GIT_DIR
set. This is the key of this problem.
If we expand an alias (or autocorrect command names), then
setup_git_dir_gently() is run the second time. If $GIT_DIR is not set in
the first run, we run the same setup_discovered_git_dir() as before.
Nothing to see. If it is, however, we'll enter setup_explicit_git_dir()
this time.
This is where the "fun" is. If $GIT_WORK_TREE is not set but
$GIT_DIR is, you are supposed to be at the root level of the
worktree. But if you are in a subdir "foo/bar" (real worktree's top
is "foo"), this rule bites you: your detected worktree is now
"foo/bar", even though the first run correctly detected worktree as
"foo". You get "internal error: work tree has already been set" as a
result.
Bottom line is, when $GIT_DIR is set, $GIT_WORK_TREE should be set too
unless there's no work tree. But setting $GIT_WORK_TREE inside
set_git_dir() may backfire. We don't know at that point if work tree is
already configured by the caller. So set it when work tree is
detected. It does not harm if $GIT_WORK_TREE is set while $GIT_DIR is
not.
Reported-by: Bjørnar Snoksrud <snoksrud@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-06-26 10:37:35 +00:00
|
|
|
git init sgd &&
|
|
|
|
(
|
|
|
|
cd sgd &&
|
|
|
|
git config alias.lsfi ls-files &&
|
|
|
|
mv .git .realgit &&
|
|
|
|
echo "gitdir: .realgit" >.git &&
|
|
|
|
mkdir subdir &&
|
|
|
|
cd subdir &&
|
|
|
|
>foo &&
|
|
|
|
git add foo &&
|
|
|
|
git lsfi >actual &&
|
|
|
|
echo foo >expected &&
|
|
|
|
test_cmp expected actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-09-28 13:06:12 +00:00
|
|
|
test_expect_success 'enter_repo non-strict mode' '
|
|
|
|
test_create_repo enter_repo &&
|
|
|
|
(
|
|
|
|
cd enter_repo &&
|
|
|
|
test_tick &&
|
|
|
|
test_commit foo &&
|
|
|
|
mv .git .realgit &&
|
|
|
|
echo "gitdir: .realgit" >.git
|
|
|
|
) &&
|
2018-09-13 05:17:34 +00:00
|
|
|
head=$(git -C enter_repo rev-parse HEAD) &&
|
2015-09-28 13:06:12 +00:00
|
|
|
git ls-remote enter_repo >actual &&
|
2018-09-13 05:17:34 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
$head HEAD
|
2020-11-18 23:44:21 +00:00
|
|
|
$head refs/heads/main
|
2018-09-13 05:17:34 +00:00
|
|
|
$head refs/tags/foo
|
2015-09-28 13:06:12 +00:00
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2015-09-28 13:06:13 +00:00
|
|
|
test_expect_success 'enter_repo linked checkout' '
|
|
|
|
(
|
|
|
|
cd enter_repo &&
|
|
|
|
git worktree add ../foo refs/tags/foo
|
|
|
|
) &&
|
2018-09-13 05:17:34 +00:00
|
|
|
head=$(git -C enter_repo rev-parse HEAD) &&
|
2015-09-28 13:06:13 +00:00
|
|
|
git ls-remote foo >actual &&
|
2018-09-13 05:17:34 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
$head HEAD
|
2020-11-18 23:44:21 +00:00
|
|
|
$head refs/heads/main
|
2018-09-13 05:17:34 +00:00
|
|
|
$head refs/tags/foo
|
2015-09-28 13:06:13 +00:00
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2015-09-28 13:06:14 +00:00
|
|
|
test_expect_success 'enter_repo strict mode' '
|
2018-09-13 05:17:34 +00:00
|
|
|
head=$(git -C enter_repo rev-parse HEAD) &&
|
2015-09-28 13:06:14 +00:00
|
|
|
git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual &&
|
2018-09-13 05:17:34 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
$head HEAD
|
2020-11-18 23:44:21 +00:00
|
|
|
$head refs/heads/main
|
2018-09-13 05:17:34 +00:00
|
|
|
$head refs/tags/foo
|
2015-09-28 13:06:14 +00:00
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2008-02-20 22:13:13 +00:00
|
|
|
test_done
|