3473ad0cf6
For normal use cases, it does not make sense for 'checkout' to work on a bare repository, without a worktree. But "checkout --to" is an exception because it _creates_ a new worktree. Allow this option to run on bare repositories. People who check out from a bare repository should remember that core.logallrefupdates is off by default and it should be turned back on. `--to` cannot do this automatically behind the user's back because some user may deliberately want no reflog. For people interested in repository setup/discovery code, is_bare_repository_cfg (aka "core.bare") is unchanged by this patch, which means 'true' by default for bare repos. Fortunately when we get the repo through a linked checkout, is_bare_repository_cfg is never used. So all is still good. [nd: commit message] Signed-off-by: Dennis Kaarsemaker <dennis@kaarsemaker.net> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
100 lines
2.0 KiB
Bash
Executable File
100 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='test git checkout --to'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup' '
|
|
test_commit init
|
|
'
|
|
|
|
test_expect_success 'checkout --to not updating paths' '
|
|
test_must_fail git checkout --to -- init.t
|
|
'
|
|
|
|
test_expect_success 'checkout --to an existing worktree' '
|
|
mkdir existing &&
|
|
test_must_fail git checkout --detach --to existing master
|
|
'
|
|
|
|
test_expect_success 'checkout --to refuses to checkout locked branch' '
|
|
test_must_fail git checkout --to zere master &&
|
|
! test -d zere &&
|
|
! test -d .git/worktrees/zere
|
|
'
|
|
|
|
test_expect_success 'checkout --to a new worktree' '
|
|
git rev-parse HEAD >expect &&
|
|
git checkout --detach --to here master &&
|
|
(
|
|
cd here &&
|
|
test_cmp ../init.t init.t &&
|
|
test_must_fail git symbolic-ref HEAD &&
|
|
git rev-parse HEAD >actual &&
|
|
test_cmp ../expect actual &&
|
|
git fsck
|
|
)
|
|
'
|
|
|
|
test_expect_success 'checkout --to a new worktree from a subdir' '
|
|
(
|
|
mkdir sub &&
|
|
cd sub &&
|
|
git checkout --detach --to here master &&
|
|
cd here &&
|
|
test_cmp ../../init.t init.t
|
|
)
|
|
'
|
|
|
|
test_expect_success 'checkout --to from a linked checkout' '
|
|
(
|
|
cd here &&
|
|
git checkout --detach --to nested-here master &&
|
|
cd nested-here &&
|
|
git fsck
|
|
)
|
|
'
|
|
|
|
test_expect_success 'checkout --to a new worktree creating new branch' '
|
|
git checkout --to there -b newmaster master &&
|
|
(
|
|
cd there &&
|
|
test_cmp ../init.t init.t &&
|
|
git symbolic-ref HEAD >actual &&
|
|
echo refs/heads/newmaster >expect &&
|
|
test_cmp expect actual &&
|
|
git fsck
|
|
)
|
|
'
|
|
|
|
test_expect_success 'die the same branch is already checked out' '
|
|
(
|
|
cd here &&
|
|
test_must_fail git checkout newmaster
|
|
)
|
|
'
|
|
|
|
test_expect_success 'not die on re-checking out current branch' '
|
|
(
|
|
cd there &&
|
|
git checkout newmaster
|
|
)
|
|
'
|
|
|
|
test_expect_success 'checkout --to from a bare repo' '
|
|
(
|
|
git clone --bare . bare &&
|
|
cd bare &&
|
|
git checkout --to ../there2 -b bare-master master
|
|
)
|
|
'
|
|
|
|
test_expect_success 'checkout from a bare repo without --to' '
|
|
(
|
|
cd bare &&
|
|
test_must_fail git checkout master
|
|
)
|
|
'
|
|
|
|
test_done
|