Merge branch 'db/maint-checkout-b'
* db/maint-checkout-b: Check early that a new branch is new and valid
This commit is contained in:
commit
666599d798
@ -580,6 +580,18 @@ no_reference:
|
|||||||
return checkout_paths(source_tree, pathspec);
|
return checkout_paths(source_tree, pathspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.new_branch) {
|
||||||
|
struct strbuf buf;
|
||||||
|
strbuf_init(&buf, 0);
|
||||||
|
strbuf_addstr(&buf, "refs/heads/");
|
||||||
|
strbuf_addstr(&buf, opts.new_branch);
|
||||||
|
if (!get_sha1(buf.buf, rev))
|
||||||
|
die("git checkout: branch %s already exists", opts.new_branch);
|
||||||
|
if (check_ref_format(buf.buf))
|
||||||
|
die("git checkout: we do not like '%s' as a branch name.", opts.new_branch);
|
||||||
|
strbuf_release(&buf);
|
||||||
|
}
|
||||||
|
|
||||||
if (new.name && !new.commit) {
|
if (new.name && !new.commit) {
|
||||||
die("Cannot switch branch to a non-commit.");
|
die("Cannot switch branch to a non-commit.");
|
||||||
}
|
}
|
||||||
|
@ -391,4 +391,14 @@ test_expect_success 'checkout an unmerged path should fail' '
|
|||||||
test_cmp sample file
|
test_cmp sample file
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'failing checkout -b should not break working tree' '
|
||||||
|
git reset --hard master &&
|
||||||
|
git symbolic-ref HEAD refs/heads/master &&
|
||||||
|
test_must_fail git checkout -b renamer side^ &&
|
||||||
|
test $(git symbolic-ref HEAD) = refs/heads/master &&
|
||||||
|
git diff --exit-code &&
|
||||||
|
git diff --cached --exit-code
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user