diff options
author | Dennis Kaarsemaker <dennis@kaarsemaker.net> | 2014-07-13 11:51:08 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-07-17 11:05:43 -0700 |
commit | bb75e4c9ffd0c0f1edfbea9bf4d4f63e4e68ff1c (patch) | |
tree | c5ae3ddb3246808bfb2f4724bab1c2cbf74e71a5 | |
parent | c55b5575463ba5043d4b420acea392b2e903c9ee (diff) | |
download | git-bb75e4c9ffd0c0f1edfbea9bf4d4f63e4e68ff1c.tar.gz |
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 <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>
-rw-r--r-- | builtin/checkout.c | 3 | ||||
-rw-r--r-- | git.c | 2 | ||||
-rwxr-xr-x | t/t2025-checkout-to.sh | 15 |
3 files changed, 19 insertions, 1 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 5b93f49cd1..c83f476a36 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1357,6 +1357,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); @@ -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 }, diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh index 20e3dc7de2..b0d97a0501 100755 --- a/t/t2025-checkout-to.sh +++ b/t/t2025-checkout-to.sh @@ -62,4 +62,19 @@ test_expect_success 'not detach 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 master + ) +' + +test_expect_success 'checkout from a bare repo without --to' ' + ( + cd bare && + test_must_fail git checkout master + ) +' + test_done |