Skip to content

Commit

Permalink
clone: refuse to clone if --branch points to bogus ref
Browse files Browse the repository at this point in the history
It's possible that users make a typo in the branch name. Stop and let
users recheck. Falling back to remote's HEAD is not documented any
way.

Except when using remote helper, the pack has not been transferred at
this stage yet so we don't waste much bandwidth.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Jan 17, 2012
1 parent 9e58504 commit 920b691
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
12 changes: 4 additions & 8 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
} else if (remote) {
/*
* We know remote HEAD points to a non-branch, or
* HEAD points to a branch but we don't know which one, or
* we asked for a specific branch but it did not exist.
* HEAD points to a branch but we don't know which one.
* Detach HEAD in all these cases.
*/
update_ref(msg, "HEAD", remote->old_sha1,
Expand Down Expand Up @@ -816,12 +815,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
our_head_points_at =
find_remote_branch(mapped_refs, option_branch);

if (!our_head_points_at) {
warning(_("Remote branch %s not found in "
"upstream %s, using HEAD instead"),
option_branch, option_origin);
our_head_points_at = remote_head_points_at;
}
if (!our_head_points_at)
die(_("Remote branch %s not found in upstream %s"),
option_branch, option_origin);
}
else
our_head_points_at = remote_head_points_at;
Expand Down
7 changes: 0 additions & 7 deletions t/t5500-fetch-pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,6 @@ test_expect_success 'clone shallow object count' '
test_cmp count3.expected count3.actual
'

test_expect_success 'clone shallow with nonexistent --branch' '
git clone --depth 1 --branch Z "file://$(pwd)/." shallow4 &&
GIT_DIR=shallow4/.git git rev-parse HEAD >actual &&
git rev-parse HEAD >expected &&
test_cmp expected actual
'

test_expect_success 'clone shallow with detached HEAD' '
git checkout HEAD^ &&
git clone --depth 1 "file://$(pwd)/." shallow5 &&
Expand Down
8 changes: 2 additions & 6 deletions t/t5706-clone-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ test_expect_success 'clone -b does not munge remotes/origin/HEAD' '
)
'

test_expect_success 'clone -b with bogus branch chooses HEAD' '
git clone -b bogus parent clone-bogus &&
(cd clone-bogus &&
check_HEAD master &&
check_file one
)
test_expect_success 'clone -b with bogus branch' '
test_must_fail git clone -b bogus parent clone-bogus
'

test_done

0 comments on commit 920b691

Please sign in to comment.