(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 into detached HEAD state'>)} spids: [12] ) ] spids: [12] ) (C {(.)} {(./test-lib.sh)}) (command.FuncDef name: check_detached body: (command.BraceGroup children: [ (command.SimpleCommand words: [{(test_must_fail)} {(git)} {(symbolic-ref)} {(-q)} {(HEAD)}] redirects: [(redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(/dev/null)})] ) ] spids: [27] ) spids: [22 26] ) (command.FuncDef name: check_not_detached body: (command.BraceGroup children: [ (command.SimpleCommand words: [{(git)} {(symbolic-ref)} {(-q)} {(HEAD)}] redirects: [(redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(/dev/null)})] ) ] spids: [51] ) spids: [46 50] ) (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:PREV_HEAD_DESC spids:[68]) op: Equal rhs: {(SQ <'Previous HEAD position was'>)} spids: [68] ) ] spids: [68] ) (command.FuncDef name: check_orphan_warning body: (command.BraceGroup children: [ (command.AndOr ops: [Op_DAmp] children: [ (C {(test_i18ngrep)} {(DQ ('you are leaving ') ($ VSub_Number '$2') (' behind'))} {(DQ ($ VSub_Number '$1'))} ) (C {(test_i18ngrep)} {(KW_Bang '!')} {(DQ ($ VSub_Name '$PREV_HEAD_DESC'))} {(DQ ($ VSub_Number '$1'))} ) ] ) ] spids: [77] ) spids: [73 76] ) (command.FuncDef name: check_no_orphan_warning body: (command.BraceGroup children: [ (command.AndOr ops: [Op_DAmp] children: [ (C {(test_i18ngrep)} {(KW_Bang '!')} {(DQ ('you are leaving .* commit.*behind'))} {(DQ ($ VSub_Number '$1'))} ) (C {(test_i18ngrep)} {(DQ ($ VSub_Name '$PREV_HEAD_DESC'))} {(DQ ($ VSub_Number '$1'))}) ] ) ] spids: [113] ) spids: [109 112] ) (command.FuncDef name: reset body: (command.BraceGroup children: [ (command.AndOr ops: [Op_DAmp] children: [(C {(git)} {(checkout)} {(master)}) (C {(check_not_detached)})] ) ] spids: [149] ) spids: [144 148] ) (C {(test_expect_success)} {(SQ <setup>)} { (SQ <'\n'> <'\ttest_commit one &&\n'> <'\ttest_commit two &&\n'> <'\ttest_commit three && git tag -d three &&\n'> <'\ttest_commit four && git tag -d four &&\n'> <'\tgit branch branch &&\n'> <'\tgit tag tag\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout branch does not detach'>)} {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout branch &&\n'> <'\tcheck_not_detached\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout tag detaches'>)} {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout tag &&\n'> <'\tcheck_detached\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout branch by full name detaches'>)} {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout refs/heads/branch &&\n'> <'\tcheck_detached\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout non-ref detaches'>)} {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout branch^ &&\n'> <'\tcheck_detached\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout ref^0 detaches'>)} {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout branch^0 &&\n'> <'\tcheck_detached\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout --detach detaches'>)} {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach branch &&\n'> <'\tcheck_detached\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout --detach without branch name'>)} {(SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach &&\n'> <'\tcheck_detached\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout --detach errors out for non-commit'>)} { (SQ <'\n'> <'\treset &&\n'> <'\ttest_must_fail git checkout --detach one^{tree} &&\n'> <'\tcheck_not_detached\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout --detach errors out for extra argument'>)} { (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout master &&\n'> <'\ttest_must_fail git checkout --detach tag one.t &&\n'> <'\tcheck_not_detached\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout --detached and -b are incompatible'>)} { (SQ <'\n'> <'\treset &&\n'> <'\ttest_must_fail git checkout --detach -b newbranch tag &&\n'> <'\tcheck_not_detached\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout --detach moves HEAD'>)} { (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout one &&\n'> <'\tgit checkout --detach two &&\n'> <'\tgit diff --exit-code HEAD &&\n'> <'\tgit diff --exit-code two\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout warns on orphan commits'>)} { (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach two &&\n'> <'\techo content >orphan &&\n'> <'\tgit add orphan &&\n'> <'\tgit commit -a -m orphan1 &&\n'> <'\techo new content >orphan &&\n'> <'\tgit commit -a -m orphan2 &&\n'> <'\torphan2=$(git rev-parse HEAD) &&\n'> <'\tgit checkout master 2>stderr\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout warns on orphan commits: output'>)} {(SQ <'\n'> <'\tcheck_orphan_warning stderr "2 commits"\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout warns orphaning 1 of 2 commits'>)} {(SQ <'\n'> <'\tgit checkout "$orphan2" &&\n'> <'\tgit checkout HEAD^ 2>stderr\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout warns orphaning 1 of 2 commits: output'>)} {(SQ <'\n'> <'\tcheck_orphan_warning stderr "1 commit"\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout does not warn leaving ref tip'>)} { (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach two &&\n'> <'\tgit checkout master 2>stderr\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout does not warn leaving ref tip'>)} {(SQ <'\n'> <'\tcheck_no_orphan_warning stderr\n'>)} ) (C {(test_expect_success)} {(SQ <'checkout does not warn leaving reachable commit'>)} { (SQ <'\n'> <'\treset &&\n'> <'\tgit checkout --detach HEAD^ &&\n'> <'\tgit checkout master 2>stderr\n'> ) } ) (C {(test_expect_success)} {(SQ <'checkout does not warn leaving reachable commit'>)} {(SQ <'\n'> <'\tcheck_no_orphan_warning stderr\n'>)} ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(SQ <EOF>)} here_end_span_id: 461 stdin_parts: [ ("Your branch is behind 'master' by 1 commit, and can be fast-forwarded.\n") (' (use "git pull" to update your local branch)\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'tracking count is accurate after orphan check'>)} { (SQ <'\n'> <'\treset &&\n'> <'\tgit branch child master^ &&\n'> <'\tgit config branch.child.remote . &&\n'> <'\tgit config branch.child.merge refs/heads/master &&\n'> <'\tgit checkout child^ &&\n'> <'\tgit checkout child >stdout &&\n'> <'\ttest_i18ncmp expect stdout\n'> ) } ) (C {(test_expect_success)} {(SQ <'no advice given for explicit detached head state'>)} { (SQ <'\n'> <'\t# baseline\n'> <'\ttest_config advice.detachedHead true &&\n'> <'\tgit checkout child && git checkout HEAD^0 >expect.advice 2>&1 &&\n'> <'\ttest_config advice.detachedHead false &&\n'> <'\tgit checkout child && git checkout HEAD^0 >expect.no-advice 2>&1 &&\n'> <'\ttest_unconfig advice.detachedHead &&\n'> <'\t# without configuration, the advice.* variables default to true\n'> <'\tgit checkout child && git checkout HEAD^0 >actual 2>&1 &&\n'> <'\ttest_cmp expect.advice actual &&\n'> <'\n'> <'\t# with explicit --detach\n'> <'\t# no configuration\n'> <'\ttest_unconfig advice.detachedHead &&\n'> <'\tgit checkout child && git checkout --detach HEAD^0 >actual 2>&1 &&\n'> <'\ttest_cmp expect.no-advice actual &&\n'> <'\n'> <'\t# explicitly decline advice\n'> <'\ttest_config advice.detachedHead false &&\n'> <'\tgit checkout child && git checkout --detach HEAD^0 >actual 2>&1 &&\n'> <'\ttest_cmp expect.no-advice actual\n'> ) } ) (C {(test_done)}) ] )