(CommandList
  children: [
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:test_description)
          op: Equal
          rhs: {(SQ <"git patch-id">)}
          spids: [4]
        )
      ]
      spids: [4]
    )
    (C {(.)} {(./test-lib.sh)})
    (C {(test_expect_success)} {(SQ <setup>)} 
      {
        (SQ <"\n"> <"\tas=\"a a a a a a a a\" && # eight a\n"> <"\ttest_write_lines $as >foo &&\n"> 
          <"\ttest_write_lines $as >bar &&\n"> <"\tgit add foo bar &&\n"> <"\tgit commit -a -m initial &&\n"> <"\ttest_write_lines $as b >foo &&\n"> 
          <"\ttest_write_lines $as b >bar &&\n"> <"\tgit commit -a -m first &&\n"> <"\tgit checkout -b same master &&\n"> 
          <"\tgit commit --amend -m same-msg &&\n"> <"\tgit checkout -b notsame master &&\n"> <"\techo c >foo &&\n"> <"\techo c >bar &&\n"> 
          <"\tgit commit --amend -a -m notsame-msg &&\n"> <"\ttest_write_lines bar foo >bar-then-foo &&\n"> <"\ttest_write_lines foo bar >foo-then-bar\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"patch-id output is well-formed">)} 
      {
        (SQ <"\n"> <"\tgit log -p -1 | git patch-id >output &&\n"> 
          <"\tgrep \"^[a-f0-9]\\{40\\} $(git rev-parse HEAD)$\" output\n">
        )
      }
    )
    (FuncDef
      name: calc_patch_id
      body: 
        (BraceGroup
          children: [
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:patch_name)
                  op: Equal
                  rhs: {(DQ ($ VSub_Number "$1"))}
                  spids: [66]
                )
              ]
              spids: [66]
            )
            (C {(shift)})
            (AndOr
              children: [
                (Pipeline
                  children: [
                    (C {(git)} {(patch-id)} {(DQ ($ VSub_At "$@"))})
                    (SimpleCommand
                      words: [{(sed)} {(DQ ("s/ .*//"))}]
                      redirects: [
                        (Redir
                          op_id: Redir_Great
                          fd: -1
                          arg_word: {(patch-id_) (DQ ($ VSub_Name "$patch_name"))}
                          spids: [92]
                        )
                      ]
                    )
                  ]
                  negated: False
                )
                (C {(test_line_count)} {(-gt)} {(0)} {(patch-id_) (DQ ($ VSub_Name "$patch_name"))})
              ]
              op_id: Op_DAmp
            )
          ]
          spids: [63]
        )
      spids: [58 62]
    )
    (FuncDef
      name: get_top_diff
      body: 
        (BraceGroup
          children: [
            (C {(git)} {(log)} {(-p)} {(-1)} {(DQ ($ VSub_At "$@"))} {(-O)} {(bar-then-foo)} {(--)})
          ]
          spids: [120]
        )
      spids: [115 119]
    )
    (FuncDef
      name: get_patch_id
      body: 
        (BraceGroup
          children: [
            (Pipeline
              children: [
                (C {(get_top_diff)} {(DQ ($ VSub_Number "$1"))})
                (C {(calc_patch_id)} {(DQ ($ VSub_At "$@"))})
              ]
              negated: False
            )
          ]
          spids: [149]
        )
      spids: [144 148]
    )
    (C {(test_expect_success)} {(SQ <"patch-id detects equality">)} 
      {
        (SQ <"\n"> <"\tget_patch_id master &&\n"> <"\tget_patch_id same &&\n"> 
          <"\ttest_cmp patch-id_master patch-id_same\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"patch-id detects inequality">)} 
      {
        (SQ <"\n"> <"\tget_patch_id master &&\n"> <"\tget_patch_id notsame &&\n"> 
          <"\t! test_cmp patch-id_master patch-id_notsame\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"patch-id supports git-format-patch output">)} 
      {
        (SQ <"\n"> <"\tget_patch_id master &&\n"> <"\tgit checkout same &&\n"> 
          <"\tgit format-patch -1 --stdout | calc_patch_id same &&\n"> <"\ttest_cmp patch-id_master patch-id_same &&\n"> 
          <"\tset $(git format-patch -1 --stdout | git patch-id) &&\n"> <"\ttest \"$2\" = $(git rev-parse HEAD)\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"whitespace is irrelevant in footer">)} 
      {
        (SQ <"\n"> <"\tget_patch_id master &&\n"> <"\tgit checkout same &&\n"> 
          <"\tgit format-patch -1 --stdout | sed \"s/ \\$//\" | calc_patch_id same &&\n"> <"\ttest_cmp patch-id_master patch-id_same\n">
        )
      }
    )
    (FuncDef
      name: cmp_patch_id
      body: 
        (BraceGroup
          children: [
            (If
              arms: [
                (if_arm
                  cond: [(C {(test)} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "=")} {(DQ (relevant))})]
                  action: [
                    (Pipeline
                      children: [
                        (C {(test_cmp)} {(patch-id_) (DQ ($ VSub_Number "$2"))} 
                          {(patch-id_) (DQ ($ VSub_Number "$3"))}
                        )
                      ]
                      negated: True
                    )
                  ]
                  spids: [-1 253]
                )
              ]
              else_action: [
                (C {(test_cmp)} {(patch-id_) (DQ ($ VSub_Number "$2"))} 
                  {(patch-id_) (DQ ($ VSub_Number "$3"))}
                )
              ]
              spids: [271 287]
            )
          ]
          spids: [234]
        )
      spids: [229 233]
    )
    (FuncDef
      name: test_patch_id_file_order
      body: 
        (BraceGroup
          children: [
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:relevant)
                  op: Equal
                  rhs: {(DQ ($ VSub_Number "$1"))}
                  spids: [300]
                )
              ]
              spids: [300]
            )
            (C {(shift)})
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:name)
                  op: Equal
                  rhs: {(DQ (order-) (${ VSub_Number 1) (-) ($ VSub_Name "$relevant"))}
                  spids: [309]
                )
              ]
              spids: [309]
            )
            (C {(shift)})
            (AndOr
              children: [
                (Pipeline
                  children: [
                    (C {(get_top_diff)} {(DQ (master))})
                    (C {(calc_patch_id)} {(DQ ($ VSub_Name "$name"))} {(DQ ($ VSub_At "$@"))})
                  ]
                  negated: False
                )
                (AndOr
                  children: [
                    (C {(git)} {(checkout)} {(same)})
                    (AndOr
                      children: [
                        (Pipeline
                          children: [
                            (C {(git)} {(format-patch)} {(-1)} {(--stdout)} {(-O)} {(foo-then-bar)})
                            (C {(calc_patch_id)} {(DQ (ordered-) ($ VSub_Name "$name"))} 
                              {(DQ ($ VSub_At "$@"))}
                            )
                          ]
                          negated: False
                        )
                        (C {(cmp_patch_id)} {($ VSub_Name "$relevant")} {(DQ ($ VSub_Name "$name"))} 
                          {(DQ (ordered-) ($ VSub_Name "$name"))}
                        )
                      ]
                      op_id: Op_DAmp
                    )
                  ]
                  op_id: Op_DAmp
                )
              ]
              op_id: Op_DAmp
            )
          ]
          spids: [297]
        )
      spids: [292 296]
    )
    (FuncDef
      name: test_patch_id
      body: 
        (BraceGroup
          children: [(C {(test_patch_id_file_order)} {(DQ ($ VSub_At "$@"))})]
          spids: [410]
        )
      spids: [405 409]
    )
    (C {(test_expect_success)} {(SQ <"file order is irrelevant with --stable">)} 
      {(SQ <"\n"> <"\ttest_patch_id_file_order irrelevant --stable --stable\n">)}
    )
    (C {(test_expect_success)} {(SQ <"file order is relevant with --unstable">)} 
      {(SQ <"\n"> <"\ttest_patch_id_file_order relevant --unstable --unstable\n">)}
    )
    (C {(test_expect_success)} {(SQ <"default is unstable">)} 
      {(SQ <"\n"> <"\ttest_patch_id relevant default\n">)}
    )
    (C {(test_expect_success)} {(SQ <"patchid.stable = true is stable">)} 
      {
        (SQ <"\n"> <"\ttest_config patchid.stable true &&\n"> 
          <"\ttest_patch_id irrelevant patchid.stable=true\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"patchid.stable = false is unstable">)} 
      {
        (SQ <"\n"> <"\ttest_config patchid.stable false &&\n"> 
          <"\ttest_patch_id relevant patchid.stable=false\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"--unstable overrides patchid.stable = true">)} 
      {
        (SQ <"\n"> <"\ttest_config patchid.stable true &&\n"> 
          <"\ttest_patch_id relevant patchid.stable=true--unstable --unstable\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"--stable overrides patchid.stable = false">)} 
      {
        (SQ <"\n"> <"\ttest_config patchid.stable false &&\n"> 
          <"\ttest_patch_id irrelevant patchid.stable=false--stable --stable\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"patch-id supports git-format-patch MIME output">)} 
      {
        (SQ <"\n"> <"\tget_patch_id master &&\n"> <"\tgit checkout same &&\n"> 
          <"\tgit format-patch -1 --attach --stdout | calc_patch_id same &&\n"> <"\ttest_cmp patch-id_master patch-id_same\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"patch-id respects config from subdir">)} 
      {
        (SQ <"\n"> <"\ttest_config patchid.stable true &&\n"> <"\tmkdir subdir &&\n"> <"\n"> 
          <"\t# copy these because test_patch_id() looks for them in\n"> <"\t# the current directory\n"> <"\tcp bar-then-foo foo-then-bar subdir &&\n"> <"\n"> <"\t(\n"> 
          <"\t\tcd subdir &&\n"> <"\t\ttest_patch_id irrelevant patchid.stable=true\n"> <"\t)\n">
        )
      }
    )
    (SimpleCommand
      words: [{(cat)}]
      redirects: [
        (Redir op_id:Redir_Great fd:-1 arg_word:{(nonl)} spids:[555])
        (HereDoc
          op_id: Redir_DLess
          fd: -1
          body: 
            {("diff --git i/a w/a\n") ("index e69de29..2e65efe 100644\n") ("--- i/a\n") ("+++ w/a\n") 
              ("@@ -0,0 +1 @@\n") ("+a\n") ("\\ No newline at end of file\n") ("diff --git i/b w/b\n") ("index e69de29..6178079 100644\n") 
              ("--- i/b\n") ("+++ w/b\n") ("@@ -0,0 +1 @@\n") ("+b\n")
            }
          do_expansion: False
          here_end: EOF
          was_filled: True
          spids: [558]
        )
      ]
    )
    (SimpleCommand
      words: [{(cat)}]
      redirects: [
        (Redir op_id:Redir_Great fd:-1 arg_word:{(withnl)} spids:[565])
        (HereDoc
          op_id: Redir_DLess
          fd: -1
          body: 
            {("diff --git i/a w/a\n") ("index e69de29..7898192 100644\n") ("--- i/a\n") ("+++ w/a\n") 
              ("@@ -0,0 +1 @@\n") ("+a\n") ("diff --git i/b w/b\n") ("index e69de29..6178079 100644\n") ("--- i/b\n") ("+++ w/b\n") 
              ("@@ -0,0 +1 @@\n") ("+b\n")
            }
          do_expansion: False
          here_end: EOF
          was_filled: True
          spids: [568]
        )
      ]
    )
    (C {(test_expect_success)} {(SQ <"patch-id handles no-nl-at-eof markers">)} 
      {
        (SQ <"\n"> <"\tcat nonl | calc_patch_id nonl &&\n"> 
          <"\tcat withnl | calc_patch_id withnl &&\n"> <"\ttest_cmp patch-id_nonl patch-id_withnl\n">
        )
      }
    )
    (C {(test_done)})
  ]
)