(command.CommandList children: [ (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:test_description spids:[12]) op: Equal rhs: {(SQ <'checkout '>)} spids: [12] ) ] spids: [12] ) (C {(.)} {(./test-lib.sh)}) (command.FuncDef name: do_checkout body: (command.BraceGroup children: [ (command.AndOr ops: [Op_DAmp Op_DAmp Op_DAmp] children: [ (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:exp_branch spids:[54]) op: Equal rhs: {($ VSub_Number '$1')} spids: [54] ) ] spids: [54] ) (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:exp_ref spids:[60]) op: Equal rhs: {(DQ (refs/heads/) ($ VSub_Name '$exp_branch'))} spids: [60] ) ] spids: [60] ) (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:exp_sha spids:[74]) op: Equal rhs: { (word_part.BracedVarSub token: <VSub_Number 2> suffix_op: (suffix_op.StringUnary op_id: VTest_ColonHyphen arg_word: { (word_part.CommandSubPart command_list: (command.CommandList children: [(C {(git)} {(rev-parse)} {(--verify)} {(HEAD)})] ) left_token: <Left_CommandSub '$('> spids: [78 86] ) } ) spids: [75 87] ) } spids: [74] ) ] spids: [74] ) (command.If arms: [ (if_arm cond: [ (command.Sentence child: (C {(Lit_Other '[')} {(-z)} {(DQ ($ VSub_Number '$3'))} {(Lit_Other ']')}) terminator: <Op_Semi ';'> ) ] action: [ (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:opts spids:[113]) op: Equal rhs: {(DQ (-b))} spids: [113] ) ] spids: [113] ) ] spids: [16777215 110] ) ] else_action: [ (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:opts spids:[122]) op: Equal rhs: {(DQ ($ VSub_Number '$3'))} spids: [122] ) ] spids: [122] ) ] spids: [119 128] ) ] ) (command.AndOr ops: [Op_DAmp Op_DAmp] children: [ (C {(git)} {(checkout)} {($ VSub_Name '$opts')} {($ VSub_Name '$exp_branch')} {($ VSub_Name '$exp_sha')} ) (C {(test)} {($ VSub_Name '$exp_ref')} {(Lit_Other '=')} { (word_part.CommandSubPart command_list: (command.CommandList children: [(C {(git)} {(rev-parse)} {(--symbolic-full-name)} {(HEAD)})] ) left_token: <Left_CommandSub '$('> spids: [152 160] ) } ) (C {(test)} {($ VSub_Name '$exp_sha')} {(Lit_Other '=')} { (word_part.CommandSubPart command_list: (command.CommandList children: [(C {(git)} {(rev-parse)} {(--verify)} {(HEAD)})] ) left_token: <Left_CommandSub '$('> spids: [171 179] ) } ) ] ) ] spids: [51] ) spids: [47 50] ) (command.FuncDef name: test_dirty_unmergeable body: (command.BraceGroup children: [ (command.Pipeline children: [ (command.SimpleCommand words: [{(git)} {(diff)} {(--exit-code)}] redirects: [(redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(/dev/null)})] ) ] negated: T ) ] spids: [188] ) spids: [184 187] ) (command.FuncDef name: setup_dirty_unmergeable body: (command.BraceGroup children: [ (command.SimpleCommand words: [{(echo)} {(change2)}] redirects: [(redir.Redir op:<Redir_DGreat '>>'> fd:16777215 arg_word:{(file1)})] ) ] spids: [209] ) spids: [205 208] ) (command.FuncDef name: test_dirty_mergeable body: (command.BraceGroup children: [ (command.Pipeline children: [ (command.SimpleCommand words: [{(git)} {(diff)} {(--cached)} {(--exit-code)}] redirects: [(redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(/dev/null)})] ) ] negated: T ) ] spids: [226] ) spids: [222 225] ) (command.FuncDef name: setup_dirty_mergeable body: (command.BraceGroup children: [ (command.AndOr ops: [Op_DAmp] children: [ (command.SimpleCommand words: [{(echo)} {(file2)}] redirects: [(redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(file2)})] ) (C {(git)} {(add)} {(file2)}) ] ) ] spids: [249] ) spids: [245 248] ) (C {(test_expect_success)} {(SQ <setup>)} { (SQ <'\n'> <'\ttest_commit initial file1 &&\n'> <'\tHEAD1=$(git rev-parse --verify HEAD) &&\n'> <'\n'> <'\ttest_commit change1 file1 &&\n'> <'\tHEAD2=$(git rev-parse --verify HEAD) &&\n'> <'\n'> <'\tgit branch -m branch1\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -b to a new branch, set to HEAD'>)} {(SQ <'\n'> <'\tdo_checkout branch2\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout -b to a new branch, set to an explicit ref'>)} { (SQ <'\n'> <'\tgit checkout branch1 &&\n'> <'\tgit branch -D branch2 &&\n'> <'\n'> <'\tdo_checkout branch2 $HEAD1\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -b to a new branch with unmergeable changes fails'>)} { (SQ <'\n'> <'\tgit checkout branch1 &&\n'> <'\n'> <'\t# clean up from previous test\n'> <'\tgit branch -D branch2 &&\n'> <'\n'> <'\tsetup_dirty_unmergeable &&\n'> <'\ttest_must_fail do_checkout branch2 $HEAD1 &&\n'> <'\ttest_dirty_unmergeable\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -f -b to a new branch with unmergeable changes discards changes'>)} { (SQ <'\n'> <'\t# still dirty and on branch1\n'> <'\tdo_checkout branch2 $HEAD1 "-f -b" &&\n'> <'\ttest_must_fail test_dirty_unmergeable\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -b to a new branch preserves mergeable changes'>)} { (SQ <'\n'> <'\tgit checkout branch1 &&\n'> <'\n'> <'\t# clean up from previous test\n'> <'\tgit branch -D branch2 &&\n'> <'\n'> <'\tsetup_dirty_mergeable &&\n'> <'\tdo_checkout branch2 $HEAD1 &&\n'> <'\ttest_dirty_mergeable\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -f -b to a new branch with mergeable changes discards changes'>)} { (SQ <'\n'> <'\t# clean up from previous test\n'> <'\tgit reset --hard &&\n'> <'\n'> <'\tgit checkout branch1 &&\n'> <'\n'> <'\t# clean up from previous test\n'> <'\tgit branch -D branch2 &&\n'> <'\n'> <'\tsetup_dirty_mergeable &&\n'> <'\tdo_checkout branch2 $HEAD1 "-f -b" &&\n'> <'\ttest_must_fail test_dirty_mergeable\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -b to an existing branch fails'>)} { (SQ <'\n'> <'\tgit reset --hard HEAD &&\n'> <'\n'> <'\ttest_must_fail do_checkout branch2 $HEAD2\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -b to @{-1} fails with the right branch name'>)} { (SQ <'\n'> <'\tgit reset --hard HEAD &&\n'> <'\tgit checkout branch1 &&\n'> <'\tgit checkout branch2 &&\n'> <'\techo >expect "fatal: A branch named '> ) (word_part.EscapedLiteralPart token:<Lit_EscapedChar "\\'">) (SQ <branch1>) (word_part.EscapedLiteralPart token:<Lit_EscapedChar "\\'">) (SQ <' already exists." &&\n'> <'\ttest_must_fail git checkout -b @{-1} 2>actual &&\n'> <'\ttest_i18ncmp expect actual\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -B to an existing branch resets branch to HEAD'>)} {(SQ <'\n'> <'\tgit checkout branch1 &&\n'> <'\n'> <'\tdo_checkout branch2 "" -B\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout -B to an existing branch from detached HEAD resets branch to HEAD'>)} { (SQ <'\n'> <'\tgit checkout $(git rev-parse --verify HEAD) &&\n'> <'\n'> <'\tdo_checkout branch2 "" -B\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -B to an existing branch with an explicit ref resets branch to that ref'>)} {(SQ <'\n'> <'\tgit checkout branch1 &&\n'> <'\n'> <'\tdo_checkout branch2 $HEAD1 -B\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout -B to an existing branch with unmergeable changes fails'>)} { (SQ <'\n'> <'\tgit checkout branch1 &&\n'> <'\n'> <'\tsetup_dirty_unmergeable &&\n'> <'\ttest_must_fail do_checkout branch2 $HEAD1 -B &&\n'> <'\ttest_dirty_unmergeable\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -f -B to an existing branch with unmergeable changes discards changes'>)} { (SQ <'\n'> <'\t# still dirty and on branch1\n'> <'\tdo_checkout branch2 $HEAD1 "-f -B" &&\n'> <'\ttest_must_fail test_dirty_unmergeable\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -B to an existing branch preserves mergeable changes'>)} { (SQ <'\n'> <'\tgit checkout branch1 &&\n'> <'\n'> <'\tsetup_dirty_mergeable &&\n'> <'\tdo_checkout branch2 $HEAD1 -B &&\n'> <'\ttest_dirty_mergeable\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -f -B to an existing branch with mergeable changes discards changes'>)} { (SQ <'\n'> <'\t# clean up from previous test\n'> <'\tgit reset --hard &&\n'> <'\n'> <'\tgit checkout branch1 &&\n'> <'\n'> <'\tsetup_dirty_mergeable &&\n'> <'\tdo_checkout branch2 $HEAD1 "-f -B" &&\n'> <'\ttest_must_fail test_dirty_mergeable\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -b <describe>'>)} { (SQ <'\n'> <'\tgit tag -f -m "First commit" initial initial &&\n'> <'\tgit checkout -f change1 &&\n'> <'\tname=$(git describe) &&\n'> <'\tgit checkout -b $name &&\n'> <'\tgit diff --exit-code change1 &&\n'> <'\techo "refs/heads/$name" >expect &&\n'> <'\tgit symbolic-ref HEAD >actual &&\n'> <'\ttest_cmp expect actual\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout -B to the current branch works'>)} { (SQ <'\n'> <'\tgit checkout branch1 &&\n'> <'\tgit checkout -B branch1-scratch &&\n'> <'\n'> <'\tsetup_dirty_mergeable &&\n'> <'\tgit checkout -B branch1-scratch initial &&\n'> <'\ttest_dirty_mergeable\n'> ) } ) (C {(test_done)}) ] )