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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jan 16, 2012 at 16:46 UTC
920b691fe4da8115f9b79901411c0cc5fff17efe
3 files changed
+6
-21
builtin/clone.c
+4
-8
@@ -518,8 +518,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
518
} else if (remote) {
519
/*
520
* 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.
522
* Detach HEAD in all these cases.
523
*/
524
update_ref(msg, "HEAD", remote->old_sha1,
@@ -816,12 +815,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
815
our_head_points_at =
816
find_remote_branch(mapped_refs, option_branch);
817
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);
821
}
822
else
823
our_head_points_at = remote_head_points_at;
t/t5500-fetch-pack.sh
-7
@@ -282,13 +282,6 @@ test_expect_success 'clone shallow object count' '
282
test_cmp count3.expected count3.actual
283
'
284
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
-
285
test_expect_success 'clone shallow with detached HEAD' '
286
git checkout HEAD^ &&
287
git clone --depth 1 "file://$(pwd)/." shallow5 &&
t/t5706-clone-branch.sh
+2
-6
@@ -57,12 +57,8 @@ test_expect_success 'clone -b does not munge remotes/origin/HEAD' '
57
)
58
'
59
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
62
'
63
64
test_done