Skip to content

Commit 920b691

Browse files
pcloudsgitster
authored andcommitted
clone: refuse to clone if --branch points to bogus ref
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9e58504 commit 920b691

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

builtin/clone.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
518518
} else if (remote) {
519519
/*
520520
* We know remote HEAD points to a non-branch, or
521-
* HEAD points to a branch but we don't know which one, or
522-
* we asked for a specific branch but it did not exist.
521+
* HEAD points to a branch but we don't know which one.
523522
* Detach HEAD in all these cases.
524523
*/
525524
update_ref(msg, "HEAD", remote->old_sha1,
@@ -816,12 +815,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
816815
our_head_points_at =
817816
find_remote_branch(mapped_refs, option_branch);
818817

819-
if (!our_head_points_at) {
820-
warning(_("Remote branch %s not found in "
821-
"upstream %s, using HEAD instead"),
822-
option_branch, option_origin);
823-
our_head_points_at = remote_head_points_at;
824-
}
818+
if (!our_head_points_at)
819+
die(_("Remote branch %s not found in upstream %s"),
820+
option_branch, option_origin);
825821
}
826822
else
827823
our_head_points_at = remote_head_points_at;

t/t5500-fetch-pack.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,6 @@ test_expect_success 'clone shallow object count' '
282282
test_cmp count3.expected count3.actual
283283
'
284284

285-
test_expect_success 'clone shallow with nonexistent --branch' '
286-
git clone --depth 1 --branch Z "file://$(pwd)/." shallow4 &&
287-
GIT_DIR=shallow4/.git git rev-parse HEAD >actual &&
288-
git rev-parse HEAD >expected &&
289-
test_cmp expected actual
290-
'
291-
292285
test_expect_success 'clone shallow with detached HEAD' '
293286
git checkout HEAD^ &&
294287
git clone --depth 1 "file://$(pwd)/." shallow5 &&

t/t5706-clone-branch.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ test_expect_success 'clone -b does not munge remotes/origin/HEAD' '
5757
)
5858
'
5959

60-
test_expect_success 'clone -b with bogus branch chooses HEAD' '
61-
git clone -b bogus parent clone-bogus &&
62-
(cd clone-bogus &&
63-
check_HEAD master &&
64-
check_file one
65-
)
60+
test_expect_success 'clone -b with bogus branch' '
61+
test_must_fail git clone -b bogus parent clone-bogus
6662
'
6763

6864
test_done

0 commit comments

Comments
 (0)