Skip to content

Commit 3473ad0

Browse files
seveasgitster
authored andcommitted
checkout: don't require a work tree when checking out into a new one
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 <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6cfbdcb commit 3473ad0

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

builtin/checkout.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
13641364
if (opts.new_worktree_mode)
13651365
opts.new_worktree = NULL;
13661366

1367+
if (!opts.new_worktree)
1368+
setup_work_tree();
1369+
13671370
if (conflict_style) {
13681371
opts.merge = 1; /* implied */
13691372
git_xmerge_config("merge.conflictstyle", conflict_style, NULL);

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static struct cmd_struct commands[] = {
383383
{ "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },
384384
{ "check-mailmap", cmd_check_mailmap, RUN_SETUP },
385385
{ "check-ref-format", cmd_check_ref_format },
386-
{ "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
386+
{ "checkout", cmd_checkout, RUN_SETUP },
387387
{ "checkout-index", cmd_checkout_index,
388388
RUN_SETUP | NEED_WORK_TREE},
389389
{ "cherry", cmd_cherry, RUN_SETUP },

t/t2025-checkout-to.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,19 @@ test_expect_success 'not die on re-checking out current branch' '
8181
)
8282
'
8383

84+
test_expect_success 'checkout --to from a bare repo' '
85+
(
86+
git clone --bare . bare &&
87+
cd bare &&
88+
git checkout --to ../there2 -b bare-master master
89+
)
90+
'
91+
92+
test_expect_success 'checkout from a bare repo without --to' '
93+
(
94+
cd bare &&
95+
test_must_fail git checkout master
96+
)
97+
'
98+
8499
test_done

0 commit comments

Comments
 (0)