Skip to content

Commit

Permalink
clone: allow "--bare" with "-o"
Browse files Browse the repository at this point in the history
We explicitly forbid the combination of "--bare" with "-o", but there
doesn't seem to be any good reason to do so. The original logic came as
part of e6489a1 (clone: do not accept more than one -o option.,
2006-01-22), but that commit does not give any reason.

Furthermore, the equivalent combination via config is allowed:

  git -c clone.defaultRemoteName=foo clone ...

and works as expected. It may be that this combination was considered
useless, because a bare clone does not set remote.origin.fetch (and
hence there is no refs/remotes/origin hierarchy). But it does set
remote.origin.url, and that name is visible to the user via "git fetch
origin", etc.

Let's allow the options to be used together, and switch the "forbid"
test in t5606 to check that we use the requested name. That test came
much later in 349cff7 (clone: add tests for --template and some
disallowed option pairs, 2020-09-29), and does not offer any logic
beyond "let's test what the code currently does".

Reported-by: John A. Leuenhagen <john@zlima12.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Sep 22, 2022
1 parent a0feb86 commit 3b910d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 0 additions & 3 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,9 +924,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
option_bare = 1;

if (option_bare) {
if (option_origin)
die(_("options '%s' and '%s %s' cannot be used together"),
"--bare", "--origin", option_origin);
if (real_git_dir)
die(_("options '%s' and '%s' cannot be used together"), "--bare", "--separate-git-dir");
option_no_checkout = 1;
Expand Down
9 changes: 5 additions & 4 deletions t/t5606-clone-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ test_expect_success 'rejects invalid -o/--origin' '
'

test_expect_success 'disallows --bare with --origin' '
test_expect_success 'clone --bare -o' '
test_must_fail git clone -o foo --bare parent clone-bare-o 2>err &&
test_debug "cat err" &&
test_i18ngrep -e "options .--bare. and .--origin foo. cannot be used together" err
git clone -o foo --bare parent clone-bare-o &&
(cd parent && pwd) >expect &&
git -C clone-bare-o config remote.foo.url >actual &&
test_cmp expect actual
'

Expand Down

0 comments on commit 3b910d6

Please sign in to comment.