(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'test <branch>@{upstream} syntax'>)}
          spids: [4]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (C {<test_expect_success>} {(SQ <setup>)} 
      {
        (SQ <'\n'> <'\n'> <'\ttest_commit 1 &&\n'> <'\tgit checkout -b side &&\n'> 
          <'\ttest_commit 2 &&\n'> <'\tgit checkout master &&\n'> <'\tgit clone . clone &&\n'> <'\ttest_commit 3 &&\n'> 
          <'\t(cd clone &&\n'> <'\t test_commit 4 &&\n'> <'\t git branch --track my-side origin/side &&\n'> 
          <'\t git branch --track local-master master &&\n'> <'\t git branch --track fun@ny origin/side &&\n'> <'\t git branch --track @funny origin/side &&\n'> 
          <'\t git branch --track funny@ origin/side &&\n'> <'\t git remote add -t master master-only .. &&\n'> <'\t git fetch master-only &&\n'> 
          <'\t git branch bad-upstream &&\n'> <'\t git config branch.bad-upstream.remote master-only &&\n'> 
          <'\t git config branch.bad-upstream.merge refs/heads/side\n'> <'\t)\n'>
        )
      }
    )
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:sq)
          op: assign_op.Equal
          rhs: {(DQ <'\''>)}
          spids: [47]
        )
      ]
    )
    (command.ShFunction
      name: full_name
      body: 
        (BraceGroup
          children: [
            (command.Subshell
              child: 
                (command.AndOr
                  ops: [Id.Op_DAmp]
                  children: [
                    (C {<cd>} {<clone>})
                    (C {<git>} {<rev-parse>} {<--symbolic-full-name>} {(DQ ($ Id.VSub_At '$@'))})
                  ]
                )
            )
          ]
        )
    )
    (command.ShFunction
      name: commit_subject
      body: 
        (BraceGroup
          children: [
            (command.Subshell
              child: 
                (command.AndOr
                  ops: [Id.Op_DAmp]
                  children: [
                    (C {<cd>} {<clone>})
                    (C {<git>} {<show>} {<-s>} 
                      {<--pretty> <Id.Lit_Equals '='> <format> <Id.Lit_Colon ':'> <Id.Lit_Other '%'> <s>} {(DQ ($ Id.VSub_At '$@'))}
                    )
                  ]
                )
            )
          ]
        )
    )
    (command.ShFunction
      name: error_message
      body: 
        (BraceGroup
          children: [
            (command.Subshell
              child: 
                (command.AndOr
                  ops: [Id.Op_DAmp]
                  children: [
                    (C {<cd>} {<clone>})
                    (C {<test_must_fail>} {<git>} {<rev-parse>} {<--verify>} {(DQ ($ Id.VSub_At '$@'))})
                  ]
                )
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'@{upstream} resolves to correct full name'>)} 
      {(SQ <'\n'> <'\ttest refs/remotes/origin/master = "$(full_name @{upstream})"\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'@{u} resolves to correct full name'>)} 
      {(SQ <'\n'> <'\ttest refs/remotes/origin/master = "$(full_name @{u})"\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'my-side@{upstream} resolves to correct full name'>)} 
      {(SQ <'\n'> <'\ttest refs/remotes/origin/side = "$(full_name my-side@{u})"\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'upstream of branch with @ in middle'>)} 
      {
        (SQ <'\n'> <'\tfull_name fun@ny@{u} >actual &&\n'> 
          <'\techo refs/remotes/origin/side >expect &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'upstream of branch with @ at start'>)} 
      {
        (SQ <'\n'> <'\tfull_name @funny@{u} >actual &&\n'> 
          <'\techo refs/remotes/origin/side >expect &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'upstream of branch with @ at end'>)} 
      {
        (SQ <'\n'> <'\tfull_name funny@@{u} >actual &&\n'> 
          <'\techo refs/remotes/origin/side >expect &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} 
      {(SQ <'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}'>)} {(SQ <'\n'> <'\ttest_must_fail full_name refs/heads/my-side@{upstream}\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'my-side@{u} resolves to correct commit'>)} 
      {
        (SQ <'\n'> <'\tgit checkout side &&\n'> <'\ttest_commit 5 &&\n'> 
          <'\t(cd clone && git fetch) &&\n'> <'\ttest 2 = "$(commit_subject my-side)" &&\n'> <'\ttest 5 = "$(commit_subject my-side@{u})"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'not-tracking@{u} fails'>)} 
      {
        (SQ <'\n'> <'\ttest_must_fail full_name non-tracking@{u} &&\n'> 
          <'\t(cd clone && git checkout --no-track -b non-tracking) &&\n'> <'\ttest_must_fail full_name non-tracking@{u}\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'<branch>@{u}@{1} resolves correctly'>)} 
      {
        (SQ <'\n'> <'\ttest_commit 6 &&\n'> <'\t(cd clone && git fetch) &&\n'> 
          <'\ttest 5 = $(commit_subject my-side@{u}@{1})\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'@{u} without specifying branch fails on a detached HEAD'>)} 
      {(SQ <'\n'> <'\tgit checkout HEAD^0 &&\n'> <'\ttest_must_fail git rev-parse @{u}\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'checkout -b new my-side@{u} forks from the same'>)} 
      {
        (SQ <'\n'> <'(\n'> <'\tcd clone &&\n'> <'\tgit checkout -b new my-side@{u} &&\n'> 
          <'\tgit rev-parse --symbolic-full-name my-side@{u} >expect &&\n'> <'\tgit rev-parse --symbolic-full-name new@{u} >actual &&\n'> <'\ttest_cmp expect actual\n'> <')\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'merge my-side@{u} records the correct name'>)} 
      {
        (SQ <'\n'> <'(\n'> <'\tcd clone || exit\n'> <'\tgit checkout master || exit\n'> 
          <'\tgit branch -D new ;# can fail but is ok\n'> <'\tgit branch -t new my-side@{u} &&\n'> <'\tgit merge -s ours new@{u} &&\n'> 
          <'\tgit show -s --pretty=tformat:%s >actual &&\n'> <'\techo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect &&\n'> 
          <'\ttest_cmp expect actual\n'> <')\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'branch -d other@{u}'>)} 
      {
        (SQ <'\n'> <'\tgit checkout -t -b other master &&\n'> <'\tgit branch -d @{u} &&\n'> 
          <'\tgit for-each-ref refs/heads/master >actual &&\n'> <'\t>expect &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'checkout other@{u}'>)} 
      {
        (SQ <'\n'> <'\tgit branch -f master HEAD &&\n'> <'\tgit checkout -t -b another master &&\n'> 
          <'\tgit checkout @{u} &&\n'> <'\tgit symbolic-ref HEAD >actual &&\n'> <'\techo refs/heads/master >expect &&\n'> 
          <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'branch@{u} works when tracking a local branch'>)} 
      {(SQ <'\n'> <'\ttest refs/heads/master = "$(full_name local-master@{u})"\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'branch@{u} error message when no upstream'>)} 
      {
        (SQ <'\n'> <'\tcat >expect <<-EOF &&\n'> 
          <'\tfatal: no upstream configured for branch ${sq}non-tracking${sq}\n'> <'\tEOF\n'> <'\terror_message non-tracking@{u} 2>actual &&\n'> <'\ttest_i18ncmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'@{u} error message when no upstream'>)} 
      {
        (SQ <'\n'> <'\tcat >expect <<-EOF &&\n'> 
          <'\tfatal: no upstream configured for branch ${sq}master${sq}\n'> <'\tEOF\n'> <'\ttest_must_fail git rev-parse --verify @{u} 2>actual &&\n'> 
          <'\ttest_i18ncmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'branch@{u} error message with misspelt branch'>)} 
      {
        (SQ <'\n'> <'\tcat >expect <<-EOF &&\n'> 
          <'\tfatal: no such branch: ${sq}no-such-branch${sq}\n'> <'\tEOF\n'> <'\terror_message no-such-branch@{u} 2>actual &&\n'> <'\ttest_i18ncmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'@{u} error message when not on a branch'>)} 
      {
        (SQ <'\n'> <'\tcat >expect <<-EOF &&\n'> <'\tfatal: HEAD does not point to a branch\n'> 
          <'\tEOF\n'> <'\tgit checkout HEAD^0 &&\n'> <'\ttest_must_fail git rev-parse --verify @{u} 2>actual &&\n'> 
          <'\ttest_i18ncmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'branch@{u} error message if upstream branch not fetched'>)} 
      {
        (SQ <'\n'> <'\tcat >expect <<-EOF &&\n'> 
          <
'\tfatal: upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch\n'
          > <'\tEOF\n'> <'\terror_message bad-upstream@{u} 2>actual &&\n'> <'\ttest_i18ncmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'pull works when tracking a local branch'>)} 
      {
        (SQ <'\n'> <'(\n'> <'\tcd clone &&\n'> <'\tgit checkout local-master &&\n'> <'\tgit pull\n'> 
          <')\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'@{u} works when tracking a local branch'>)} 
      {(SQ <'\n'> <'\ttest refs/heads/master = "$(full_name @{u})"\n'>)}
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 511
              stdin_parts: [
                <'commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5\n'>
                <'Reflog: master@{0} (C O Mitter <committer@example.com>)\n'>
                <'Reflog message: branch: Created from HEAD\n'>
                <'Author: A U Thor <author@example.com>\n'>
                <'Date:   Thu Apr 7 15:15:13 2005 -0700\n'>
                <'\n'>
                <'    3\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'log -g other@{u}'>)} 
      {(SQ <'\n'> <'\tgit log -1 -g other@{u} >actual &&\n'> <'\ttest_cmp expect actual\n'>)}
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 541
              stdin_parts: [
                <'commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5\n'>
                <
'Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)\n'
                >
                <'Reflog message: branch: Created from HEAD\n'>
                <'Author: A U Thor <author@example.com>\n'>
                <'Date:   Thu Apr 7 15:15:13 2005 -0700\n'>
                <'\n'>
                <'    3\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'log -g other@{u}@{now}'>)} 
      {(SQ <'\n'> <'\tgit log -1 -g other@{u}@{now} >actual &&\n'> <'\ttest_cmp expect actual\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'@{reflog}-parsing does not look beyond colon'>)} 
      {
        (SQ <'\n'> <'\techo content >@{yesterday} &&\n'> <'\tgit add @{yesterday} &&\n'> 
          <'\tgit commit -m "funny reflog file" &&\n'> <'\tgit hash-object @{yesterday} >expect &&\n'> <'\tgit rev-parse HEAD:@{yesterday} >actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'@{upstream}-parsing does not look beyond colon'>)} 
      {
        (SQ <'\n'> <'\techo content >@{upstream} &&\n'> <'\tgit add @{upstream} &&\n'> 
          <'\tgit commit -m "funny upstream file" &&\n'> <'\tgit hash-object @{upstream} >expect &&\n'> <'\tgit rev-parse HEAD:@{upstream} >actual\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)