Skip to content

Commit 16ab794

Browse files
rscharfegitster
authored andcommitted
checkout: add tests for -b and --track
Test git checkout -b with and without --track and demonstrate unexpected error messages when it's given an extra (i.e. unsupported) path argument. In both cases it reports: $ git checkout -b foo origin/master bar fatal: 'bar' is not a commit and a branch 'foo' cannot be created from it The problem is that the start point we gave for the new branch is "origin/master" and "bar" is just some extra argument -- it could even be a valid commit, which would make the message even more confusing. We have more fitting error messages in git commit, but get confused; use the text of the rights ones in the tests. Reported-by: Dana Dahlstrom <dahlstrom@google.com> Original-test-by: Jeff King <peff@peff.net> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ae92ac8 commit 16ab794

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

t/t2018-checkout-branch.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,14 @@ test_expect_success 'checkout -b to a new branch preserves mergeable changes des
260260
test_cmp expect actual
261261
'
262262

263+
test_expect_success 'checkout -b rejects an invalid start point' '
264+
test_must_fail git checkout -b branch4 file1 2>err &&
265+
test_i18ngrep "is not a commit" err
266+
'
267+
268+
test_expect_failure 'checkout -b rejects an extra path argument' '
269+
test_must_fail git checkout -b branch5 branch1 file1 2>err &&
270+
test_i18ngrep "Cannot update paths and switch to branch" err
271+
'
272+
263273
test_done

t/t2027-checkout-track.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
test_description='tests for git branch --track'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'setup' '
8+
test_commit one &&
9+
test_commit two
10+
'
11+
12+
test_expect_success 'checkout --track -b creates a new tracking branch' '
13+
git checkout --track -b branch1 master &&
14+
test $(git rev-parse --abbrev-ref HEAD) = branch1 &&
15+
test $(git config --get branch.branch1.remote) = . &&
16+
test $(git config --get branch.branch1.merge) = refs/heads/master
17+
'
18+
19+
test_expect_failure 'checkout --track -b rejects an extra path argument' '
20+
test_must_fail git checkout --track -b branch2 master one.t 2>err &&
21+
test_i18ngrep "cannot be used with updating paths" err
22+
'
23+
24+
test_done

0 commit comments

Comments
 (0)