mirror of
https://github.com/git/git.git
synced 2024-09-29 16:41:53 +02:00
334afbc76f
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>
174 lines
5.5 KiB
Bash
Executable File
174 lines
5.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='test git worktree list'
|
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup' '
|
|
test_commit init
|
|
'
|
|
|
|
test_expect_success 'rev-parse --git-common-dir on main worktree' '
|
|
git rev-parse --git-common-dir >actual &&
|
|
echo .git >expected &&
|
|
test_cmp expected actual &&
|
|
mkdir sub &&
|
|
git -C sub rev-parse --git-common-dir >actual2 &&
|
|
echo ../.git >expected2 &&
|
|
test_cmp expected2 actual2
|
|
'
|
|
|
|
test_expect_success 'rev-parse --git-path objects linked worktree' '
|
|
echo "$(git rev-parse --show-toplevel)/.git/objects" >expect &&
|
|
test_when_finished "rm -rf linked-tree actual expect && git worktree prune" &&
|
|
git worktree add --detach linked-tree master &&
|
|
git -C linked-tree rev-parse --git-path objects >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '"list" all worktrees from main' '
|
|
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
|
|
test_when_finished "rm -rf here out actual expect && git worktree prune" &&
|
|
git worktree add --detach here master &&
|
|
echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
|
|
git worktree list >out &&
|
|
sed "s/ */ /g" <out >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '"list" all worktrees from linked' '
|
|
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
|
|
test_when_finished "rm -rf here out actual expect && git worktree prune" &&
|
|
git worktree add --detach here master &&
|
|
echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
|
|
git -C here worktree list >out &&
|
|
sed "s/ */ /g" <out >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '"list" all worktrees --porcelain' '
|
|
echo "worktree $(git rev-parse --show-toplevel)" >expect &&
|
|
echo "HEAD $(git rev-parse HEAD)" >>expect &&
|
|
echo "branch $(git symbolic-ref HEAD)" >>expect &&
|
|
echo >>expect &&
|
|
test_when_finished "rm -rf here actual expect && git worktree prune" &&
|
|
git worktree add --detach here master &&
|
|
echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect &&
|
|
echo "HEAD $(git rev-parse HEAD)" >>expect &&
|
|
echo "detached" >>expect &&
|
|
echo >>expect &&
|
|
git worktree list --porcelain >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '"list" all worktrees with locked annotation' '
|
|
test_when_finished "rm -rf locked unlocked out && git worktree prune" &&
|
|
git worktree add --detach locked master &&
|
|
git worktree add --detach unlocked master &&
|
|
git worktree lock locked &&
|
|
git worktree list >out &&
|
|
grep "/locked *[0-9a-f].* locked$" out &&
|
|
! grep "/unlocked *[0-9a-f].* locked$" out
|
|
'
|
|
|
|
test_expect_success 'bare repo setup' '
|
|
git init --bare bare1 &&
|
|
echo "data" >file1 &&
|
|
git add file1 &&
|
|
git commit -m"File1: add data" &&
|
|
git push bare1 master &&
|
|
git reset --hard HEAD^
|
|
'
|
|
|
|
test_expect_success '"list" all worktrees from bare main' '
|
|
test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" &&
|
|
git -C bare1 worktree add --detach ../there master &&
|
|
echo "$(pwd)/bare1 (bare)" >expect &&
|
|
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
|
|
git -C bare1 worktree list >out &&
|
|
sed "s/ */ /g" <out >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '"list" all worktrees --porcelain from bare main' '
|
|
test_when_finished "rm -rf there actual expect && git -C bare1 worktree prune" &&
|
|
git -C bare1 worktree add --detach ../there master &&
|
|
echo "worktree $(pwd)/bare1" >expect &&
|
|
echo "bare" >>expect &&
|
|
echo >>expect &&
|
|
echo "worktree $(git -C there rev-parse --show-toplevel)" >>expect &&
|
|
echo "HEAD $(git -C there rev-parse HEAD)" >>expect &&
|
|
echo "detached" >>expect &&
|
|
echo >>expect &&
|
|
git -C bare1 worktree list --porcelain >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '"list" all worktrees from linked with a bare main' '
|
|
test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" &&
|
|
git -C bare1 worktree add --detach ../there master &&
|
|
echo "$(pwd)/bare1 (bare)" >expect &&
|
|
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
|
|
git -C there worktree list >out &&
|
|
sed "s/ */ /g" <out >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'bare repo cleanup' '
|
|
rm -rf bare1
|
|
'
|
|
|
|
test_expect_success 'broken main worktree still at the top' '
|
|
git init broken-main &&
|
|
(
|
|
cd broken-main &&
|
|
test_commit new &&
|
|
git worktree add linked &&
|
|
cat >expected <<-EOF &&
|
|
worktree $(pwd)
|
|
HEAD $ZERO_OID
|
|
|
|
EOF
|
|
cd linked &&
|
|
echo "worktree $(pwd)" >expected &&
|
|
echo "ref: .broken" >../.git/HEAD &&
|
|
git worktree list --porcelain >out &&
|
|
head -n 3 out >actual &&
|
|
test_cmp ../expected actual &&
|
|
git worktree list >out &&
|
|
head -n 1 out >actual.2 &&
|
|
grep -F "(error)" actual.2
|
|
)
|
|
'
|
|
|
|
test_expect_success 'linked worktrees are sorted' '
|
|
mkdir sorted &&
|
|
git init sorted/main &&
|
|
(
|
|
cd sorted/main &&
|
|
test_tick &&
|
|
test_commit new &&
|
|
git worktree add ../first &&
|
|
git worktree add ../second &&
|
|
git worktree list --porcelain >out &&
|
|
grep ^worktree out >actual
|
|
) &&
|
|
cat >expected <<-EOF &&
|
|
worktree $(pwd)/sorted/main
|
|
worktree $(pwd)/sorted/first
|
|
worktree $(pwd)/sorted/second
|
|
EOF
|
|
test_cmp expected sorted/main/actual
|
|
'
|
|
|
|
test_expect_success 'worktree path when called in .git directory' '
|
|
git worktree list >list1 &&
|
|
git -C .git worktree list >list2 &&
|
|
test_cmp list1 list2
|
|
'
|
|
|
|
test_done
|