]> git.ipfire.org Git - thirdparty/git.git/commitdiff
checkout: don't require a work tree when checking out into a new one
authorDennis Kaarsemaker <dennis@kaarsemaker.net>
Sun, 30 Nov 2014 08:24:56 +0000 (15:24 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Dec 2014 19:00:18 +0000 (11:00 -0800)
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>
builtin/checkout.c
git.c
t/t2025-checkout-to.sh

index 5dfdbda1a6bc248e86ebdc3f951f73c4a29fd192..8c5276cf443f5d1e84cd5fd34e5f899afd3e58b6 100644 (file)
@@ -1364,6 +1364,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        if (opts.new_worktree_mode)
                opts.new_worktree = NULL;
 
+       if (!opts.new_worktree)
+               setup_work_tree();
+
        if (conflict_style) {
                opts.merge = 1; /* implied */
                git_xmerge_config("merge.conflictstyle", conflict_style, NULL);
diff --git a/git.c b/git.c
index 18fbf79430687a473e9306f2bb65abbaec161bb4..160896a9439007b1ca110b56bac327d3b0e6af3d 100644 (file)
--- a/git.c
+++ b/git.c
@@ -383,7 +383,7 @@ static struct cmd_struct commands[] = {
        { "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },
        { "check-mailmap", cmd_check_mailmap, RUN_SETUP },
        { "check-ref-format", cmd_check_ref_format },
-       { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
+       { "checkout", cmd_checkout, RUN_SETUP },
        { "checkout-index", cmd_checkout_index,
                RUN_SETUP | NEED_WORK_TREE},
        { "cherry", cmd_cherry, RUN_SETUP },
index e2db07859b36d752bb0784918f9e1571a150a4f8..4bd1df4899c043a768ee2a45964c458254a6ec30 100755 (executable)
@@ -81,4 +81,19 @@ test_expect_success 'not die on re-checking out current branch' '
        )
 '
 
+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