Signed-off-by: Tay Ray Chuan <rctay89@xxxxxxxxx> --- t/t2018-checkout-branch.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 66 insertions(+), 0 deletions(-) create mode 100755 t/t2018-checkout-branch.sh diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh new file mode 100755 index 0000000..678a34f --- /dev/null +++ b/t/t2018-checkout-branch.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +test_description='checkout ' + +. ./test-lib.sh + +# Arguments: <branch> <sha> [<checkout options>] +do_checkout() { + exp_branch=$1 && + exp_ref="refs/heads/$exp_branch" && + + # if <sha> is not specified, use HEAD. + exp_sha=${2:-$(git rev-parse --verify HEAD)} && + + git checkout ${3+"$3"} -b $exp_branch $exp_sha && + + test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) && + test $exp_sha = $(git rev-parse --verify HEAD) +} + +test_dirty() { + ! git diff --exit-code >/dev/null +} + +setup_dirty() { + echo >>file1 change2 +} + +test_expect_success 'setup' ' + test_commit initial file1 && + HEAD1=$(git rev-parse --verify HEAD) && + + test_commit change1 file1 && + HEAD2=$(git rev-parse --verify HEAD) && + + git branch -m branch1 +' + +test_expect_success 'checkout -b to a new branch' ' + do_checkout branch2 +' + +test_expect_success 'checkout -b to a new branch (explicit ref)' ' + git checkout branch1 && + git branch -D branch2 && + + do_checkout branch2 $HEAD1 +' + +test_expect_success 'checkout -b to a new branch (dirty)' ' + git checkout branch1 && + git branch -D branch2 && + + setup_dirty && + test_must_fail do_checkout branch2 $HEAD1 && + test_dirty +' + +test_expect_success 'checkout -b to an existing branch fails' ' + git reset --hard HEAD && + git branch branch2 && + + test_must_fail do_checkout branch2 $HEAD2 +' + +test_done -- 1.7.1.513.g4f18 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html