#!/bin/sh global test_description := ''checkout from unborn branch'' source ./test-lib.sh test_expect_success 'setup' ' mkdir parent && (cd parent && git init && echo content >file && git add file && git commit -m base ) && git fetch parent master:origin ' test_expect_success 'checkout from unborn preserves untracked files' ' echo precious >expect && echo precious >file && test_must_fail git checkout -b new origin && test_cmp expect file ' test_expect_success 'checkout from unborn preserves index contents' ' echo precious >expect && echo precious >file && git add file && test_must_fail git checkout -b new origin && test_cmp expect file && git show :file >file && test_cmp expect file ' test_expect_success 'checkout from unborn merges identical index contents' ' echo content >file && git add file && git checkout -b new origin ' test_expect_success 'checking out another branch from unborn state' ' git checkout --orphan newroot && git checkout -b anothername && test_must_fail git show-ref --verify refs/heads/newroot && git symbolic-ref HEAD >actual && echo refs/heads/anothername >expect && test_cmp expect actual ' test_expect_success 'checking out in a newly created repo' ' test_create_repo empty && ( cd empty && git symbolic-ref HEAD >expect && test_must_fail git checkout && git symbolic-ref HEAD >actual && test_cmp expect actual ) ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"checkout from unborn branch">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tmkdir parent &&\n"> <"\t(cd parent &&\n"> <"\t git init &&\n"> <"\t echo content >file &&\n"> <"\t git add file &&\n"> <"\t git commit -m base\n"> <"\t) &&\n"> <"\tgit fetch parent master:origin\n"> ) } ) (C {(test_expect_success)} {(SQ <"checkout from unborn preserves untracked files">)} { (SQ <"\n"> <"\techo precious >expect &&\n"> <"\techo precious >file &&\n"> <"\ttest_must_fail git checkout -b new origin &&\n"> <"\ttest_cmp expect file\n"> ) } ) (C {(test_expect_success)} {(SQ <"checkout from unborn preserves index contents">)} { (SQ <"\n"> <"\techo precious >expect &&\n"> <"\techo precious >file &&\n"> <"\tgit add file &&\n"> <"\ttest_must_fail git checkout -b new origin &&\n"> <"\ttest_cmp expect file &&\n"> <"\tgit show :file >file &&\n"> <"\ttest_cmp expect file\n"> ) } ) (C {(test_expect_success)} {(SQ <"checkout from unborn merges identical index contents">)} { (SQ <"\n"> <"\techo content >file &&\n"> <"\tgit add file &&\n"> <"\tgit checkout -b new origin\n"> ) } ) (C {(test_expect_success)} {(SQ <"checking out another branch from unborn state">)} { (SQ <"\n"> <"\tgit checkout --orphan newroot &&\n"> <"\tgit checkout -b anothername &&\n"> <"\ttest_must_fail git show-ref --verify refs/heads/newroot &&\n"> <"\tgit symbolic-ref HEAD >actual &&\n"> <"\techo refs/heads/anothername >expect &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"checking out in a newly created repo">)} { (SQ <"\n"> <"\ttest_create_repo empty &&\n"> <"\t(\n"> <"\t\tcd empty &&\n"> <"\t\tgit symbolic-ref HEAD >expect &&\n"> <"\t\ttest_must_fail git checkout &&\n"> <"\t\tgit symbolic-ref HEAD >actual &&\n"> <"\t\ttest_cmp expect actual\n"> <"\t)\n"> ) } ) (C {(test_done)}) ] )