(CommandList
  children: [
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:test_description)
          op: Equal
          rhs: {(SQ <"core.whitespace rules and git apply">)}
          spids: [4]
        )
      ]
      spids: [4]
    )
    (C {(.)} {(./test-lib.sh)})
    (FuncDef
      name: prepare_test_file
      body: 
        (BraceGroup
          children: [
            (SimpleCommand
              words: [{(sed)} {(-e)} {(DQ ("s/_/ /g"))} {(-e)} {(DQ ("s/>/\t/"))}]
              redirects: [
                (HereDoc
                  op_id: Redir_DLessDash
                  fd: -1
                  body: 
                    {("An_SP in an ordinary line>and a HT.\n") (">A HT (%).\n") 
                      ("_>A SP and a HT (@%).\n") ("_>_A SP, a HT and a SP (@%).\n") ("_______Seven SP.\n") ("________Eight SP (#).\n") 
                      ("_______>Seven SP and a HT (@%).\n") ("________>Eight SP and a HT (@#%).\n") ("_______>_Seven SP, a HT and a SP (@%).\n") 
                      ("________>_Eight SP, a HT and a SP (@#%).\n") ("_______________Fifteen SP (#).\n") ("_______________>Fifteen SP and a HT (@#%).\n") 
                      ("________________Sixteen SP (#=).\n") ("________________>Sixteen SP and a HT (@#%=).\n") ("_____a__Five SP, a non WS, two SP.\n") 
                      ("A line with a (!) trailing SP_\n") ("A line with a (!) trailing HT>\n")
                    }
                  do_expansion: False
                  here_end: EOF
                  was_filled: True
                  spids: [66]
                )
              ]
            )
          ]
          spids: [20]
        )
      spids: [15 19]
    )
    (FuncDef
      name: apply_patch
      body: 
        (BraceGroup
          children: [
            (AndOr
              children: [
                (SimpleCommand
                  redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(target)} spids:[81])]
                )
                (Pipeline
                  children: [
                    (SimpleCommand
                      words: [
                        {(sed)}
                        {(-e)}
                        {
                          (DQ ("s|") (EscapedLiteralPart token:<Lit_EscapedChar "\\(">) ("[ab]") 
                            (EscapedLiteralPart
                              token: <Lit_EscapedChar "\\)">
                            ) ("/file|") (EscapedLiteralPart token:<Lit_EscapedChar "\\1">) ("/target|")
                          )
                        }
                      ]
                      redirects: [(Redir op_id:Redir_Less fd:-1 arg_word:{(patch)} spids:[101])]
                    )
                    (C {(git)} {(apply)} {(DQ ($ VSub_At "$@"))})
                  ]
                  negated: False
                )
              ]
              op_id: Op_DAmp
            )
          ]
          spids: [78]
        )
      spids: [73 77]
    )
    (FuncDef
      name: test_fix
      body: 
        (BraceGroup
          children: [
            (AndOr
              children: [
                (C {(apply_patch)} {(--whitespace) (Lit_Other "=") (fix)})
                (ControlFlow token:<ControlFlow_Return return> arg_word:{(1)})
              ]
              op_id: Op_DPipe
            )
            (Pipeline
              children: [
                (C {($ VSub_Name "$DIFF")} {(file)} {(target)})
                (SimpleCommand
                  words: [{(sed)} {(-n)} {(-e)} {(DQ ("s/^> //p"))}]
                  redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(fixed)} spids:[166])]
                )
              ]
              negated: False
            )
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:fixed_cnt)
                  op: Equal
                  rhs: 
                    {
                      (CommandSubPart
                        command_list: 
                          (CommandList
                            children: [
                              (SimpleCommand
                                words: [{(wc)} {(-l)}]
                                redirects: [
                                  (Redir
                                    op_id: Redir_Less
                                    fd: -1
                                    arg_word: {(fixed)}
                                    spids: [181]
                                  )
                                ]
                              )
                            ]
                          )
                        left_token: <Left_CommandSub "$(">
                        spids: [176 183]
                      )
                    }
                  spids: [175]
                )
              ]
              spids: [175]
            )
            (Case
              to_match: {(DQ ($ VSub_Number "$1"))}
              arms: [
                (case_arm
                  pat_list: [{(SQ )}]
                  action: [
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:expect_cnt)
                          op: Equal
                          rhs: {($ VSub_Name "$fixed_cnt")}
                          spids: [199]
                        )
                      ]
                      spids: [199]
                    )
                  ]
                  spids: [-1 197 202 -1]
                )
                (case_arm
                  pat_list: [{(Lit_Other "?") (Lit_Other "*")}]
                  action: [
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:expect_cnt)
                          op: Equal
                          rhs: 
                            {
                              (CommandSubPart
                                command_list: 
                                  (CommandList
                                    children: [
                                      (Pipeline
                                        children: [
                                          (SimpleCommand
                                            words: [{(grep)} {(DQ ("[") ($ VSub_Number "$1") ("]"))}]
                                            redirects: [
                                              (Redir
                                                op_id: Redir_Less
                                                fd: -1
                                                arg_word: {(fixed)}
                                                spids: [219]
                                              )
                                            ]
                                          )
                                          (C {(wc)} {(-l)})
                                        ]
                                        negated: False
                                      )
                                    ]
                                  )
                                left_token: <Left_CommandSub "$(">
                                spids: [210 227]
                              )
                            }
                          spids: [209]
                        )
                      ]
                      spids: [209]
                    )
                  ]
                  spids: [205 207 229 -1]
                )
              ]
              spids: [186 192 232]
            )
            (AndOr
              children: [
                (C {(test)} {($ VSub_Name "$fixed_cnt")} {(-eq)} {($ VSub_Name "$expect_cnt")})
                (ControlFlow token:<ControlFlow_Return return> arg_word:{(1)})
              ]
              op_id: Op_DPipe
            )
            (Case
              to_match: {(DQ ($ VSub_Number "$1"))}
              arms: [
                (case_arm
                  pat_list: [{(SQ )}]
                  action: [
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:expect_cnt)
                          op: Equal
                          rhs: {(0)}
                          spids: [268]
                        )
                      ]
                      spids: [268]
                    )
                  ]
                  spids: [-1 266 271 -1]
                )
                (case_arm
                  pat_list: [{(Lit_Other "?") (Lit_Other "*")}]
                  action: [
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:expect_cnt)
                          op: Equal
                          rhs: 
                            {
                              (CommandSubPart
                                command_list: 
                                  (CommandList
                                    children: [
                                      (Pipeline
                                        children: [
                                          (SimpleCommand
                                            words: [{(grep)} {(DQ ("[") ($ VSub_Number "$1") ("]"))}]
                                            redirects: [
                                              (Redir
                                                op_id: Redir_Less
                                                fd: -1
                                                arg_word: {(file)}
                                                spids: [288]
                                              )
                                            ]
                                          )
                                          (C {(wc)} {(-l)})
                                        ]
                                        negated: False
                                      )
                                    ]
                                  )
                                left_token: <Left_CommandSub "$(">
                                spids: [279 296]
                              )
                            }
                          spids: [278]
                        )
                      ]
                      spids: [278]
                    )
                  ]
                  spids: [274 276 298 -1]
                )
              ]
              spids: [255 261 301]
            )
            (AndOr
              children: [
                (C {(test)} {($ VSub_Name "$fixed_cnt")} {(-eq)} {($ VSub_Name "$expect_cnt")})
                (ControlFlow token:<ControlFlow_Return return> arg_word:{(1)})
              ]
              op_id: Op_DPipe
            )
            (SimpleCommand
              words: [{(git)} {(diff-files)} {(-p)} {(target)}]
              redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(fixed-patch)} spids:[332])]
            )
            (AndOr
              children: [
                (C {(test)} {(-s)} {(fixed-patch)})
                (ControlFlow token:<ControlFlow_Return return> arg_word:{(0)})
              ]
              op_id: Op_DAmp
            )
            (SimpleCommand
              redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(target)} spids:[354])]
            )
            (SimpleCommand
              words: [{(git)} {(apply)} {(--whitespace) (Lit_Other "=") (error-all)}]
              redirects: [(Redir op_id:Redir_Less fd:-1 arg_word:{(fixed-patch)} spids:[366])]
            )
          ]
          spids: [123]
        )
      spids: [118 122]
    )
    (C {(test_expect_success)} {(setup)} 
      {
        (SQ <"\n"> <"\n"> <"\t>file &&\n"> <"\tgit add file &&\n"> <"\tprepare_test_file >file &&\n"> 
          <"\tgit diff-files -p >patch &&\n"> <"\t>target &&\n"> <"\tgit add target\n"> <"\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"whitespace=nowarn, default rule">)} 
      {
        (SQ <"\n"> <"\n"> <"\tapply_patch --whitespace=nowarn &&\n"> <"\ttest_cmp file target\n"> <"\n">)
      }
    )
    (C {(test_expect_success)} {(SQ <"whitespace=warn, default rule">)} 
      {
        (SQ <"\n"> <"\n"> <"\tapply_patch --whitespace=warn &&\n"> <"\ttest_cmp file target\n"> <"\n">)
      }
    )
    (C {(test_expect_success)} {(SQ <"whitespace=error-all, default rule">)} 
      {
        (SQ <"\n"> <"\n"> <"\ttest_must_fail apply_patch --whitespace=error-all &&\n"> 
          <"\t! test -s target\n"> <"\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"whitespace=error-all, no rule">)} 
      {
        (SQ <"\n"> <"\n"> <"\tgit config core.whitespace -trailing,-space-before,-indent &&\n"> 
          <"\tapply_patch --whitespace=error-all &&\n"> <"\ttest_cmp file target\n"> <"\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"whitespace=error-all, no rule (attribute)">)} 
      {
        (SQ <"\n"> <"\n"> <"\tgit config --unset core.whitespace &&\n"> 
          <"\techo \"target -whitespace\" >.gitattributes &&\n"> <"\tapply_patch --whitespace=error-all &&\n"> <"\ttest_cmp file target\n"> <"\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"spaces inserted by tab-in-indent">)} 
      {
        (SQ <"\n"> <"\n"> <"\tgit config core.whitespace -trailing,-space,-indent,tab &&\n"> 
          <"\trm -f .gitattributes &&\n"> <"\ttest_fix % &&\n"> <"\tsed -e \"s/_/ /g\" -e \"s/>/\t/\" <<-\\EOF >expect &&\n"> 
          <"\t\tAn_SP in an ordinary line>and a HT.\n"> <"\t\t________A HT (%).\n"> <"\t\t________A SP and a HT (@%).\n"> 
          <"\t\t_________A SP, a HT and a SP (@%).\n"> <"\t\t_______Seven SP.\n"> <"\t\t________Eight SP (#).\n"> <"\t\t________Seven SP and a HT (@%).\n"> 
          <"\t\t________________Eight SP and a HT (@#%).\n"> <"\t\t_________Seven SP, a HT and a SP (@%).\n"> 
          <"\t\t_________________Eight SP, a HT and a SP (@#%).\n"> <"\t\t_______________Fifteen SP (#).\n"> <"\t\t________________Fifteen SP and a HT (@#%).\n"> 
          <"\t\t________________Sixteen SP (#=).\n"> <"\t\t________________________Sixteen SP and a HT (@#%=).\n"> 
          <"\t\t_____a__Five SP, a non WS, two SP.\n"> <"\t\tA line with a (!) trailing SP_\n"> <"\t\tA line with a (!) trailing HT>\n"> <"\tEOF\n"> 
          <"\ttest_cmp expect target\n"> <"\n">
        )
      }
    )
    (ForEach
      iter_name: t
      iter_words: [{(-)} {(SQ )}]
      do_arg_iter: False
      body: 
        (DoGroup
          children: [
            (Case
              to_match: {(DQ ($ VSub_Name "$t"))}
              arms: [
                (case_arm
                  pat_list: [{(SQ )}]
                  action: [
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:tt)
                          op: Equal
                          rhs: {(SQ <"!">)}
                          spids: [530]
                        )
                      ]
                      spids: [530]
                    )
                  ]
                  spids: [-1 528 535 -1]
                )
                (case_arm
                  pat_list: [{(Lit_Other "*")}]
                  action: [
                    (Assignment
                      keyword: Assign_None
                      pairs: [(assign_pair lhs:(LhsName name:tt) op:Equal rhs:{(SQ )} spids:[540])]
                      spids: [540]
                    )
                  ]
                  spids: [537 538 542 -1]
                )
              ]
              spids: [518 524 544]
            )
            (ForEach
              iter_name: s
              iter_words: [{(-)} {(SQ )}]
              do_arg_iter: False
              body: 
                (DoGroup
                  children: [
                    (Case
                      to_match: {(DQ ($ VSub_Name "$s"))}
                      arms: [
                        (case_arm
                          pat_list: [{(SQ )}]
                          action: [
                            (Assignment
                              keyword: Assign_None
                              pairs: [
                                (assign_pair
                                  lhs: (LhsName name:ts)
                                  op: Equal
                                  rhs: {(SQ <"@">)}
                                  spids: [574]
                                )
                              ]
                              spids: [574]
                            )
                          ]
                          spids: [-1 572 579 -1]
                        )
                        (case_arm
                          pat_list: [{(Lit_Other "*")}]
                          action: [
                            (Assignment
                              keyword: Assign_None
                              pairs: [
                                (assign_pair
                                  lhs: (LhsName name:ts)
                                  op: Equal
                                  rhs: {(SQ )}
                                  spids: [584]
                                )
                              ]
                              spids: [584]
                            )
                          ]
                          spids: [581 582 586 -1]
                        )
                      ]
                      spids: [562 568 588]
                    )
                    (ForEach
                      iter_name: i
                      iter_words: [{(-)} {(SQ )}]
                      do_arg_iter: False
                      body: 
                        (DoGroup
                          children: [
                            (Case
                              to_match: {(DQ ($ VSub_Name "$i"))}
                              arms: [
                                (case_arm
                                  pat_list: [{(SQ )}]
                                  action: [
                                    (Assignment
                                      keyword: Assign_None
                                      pairs: [
                                        (assign_pair
                                          lhs: (LhsName name:ti)
                                          op: Equal
                                          rhs: {(SQ <"#">)}
                                          spids: [618]
                                        )
                                        (assign_pair
                                          lhs: (LhsName name:ti16)
                                          op: Equal
                                          rhs: {(SQ <"=">)}
                                          spids: [623]
                                        )
                                      ]
                                      spids: [618]
                                    )
                                  ]
                                  spids: [-1 616 627 -1]
                                )
                                (case_arm
                                  pat_list: [{(Lit_Other "*")}]
                                  action: [
                                    (Assignment
                                      keyword: Assign_None
                                      pairs: [
                                        (assign_pair
                                          lhs: (LhsName name:ti)
                                          op: Equal
                                          rhs: {(SQ )}
                                          spids: [632]
                                        )
                                        (assign_pair
                                          lhs: (LhsName name:ti16)
                                          op: Equal
                                          rhs: {(SQ )}
                                          spids: [634]
                                        )
                                      ]
                                      spids: [632]
                                    )
                                  ]
                                  spids: [629 630 636 -1]
                                )
                              ]
                              spids: [606 612 638]
                            )
                            (ForEach
                              iter_name: h
                              iter_words: [{(-)} {(SQ )}]
                              do_arg_iter: False
                              body: 
                                (DoGroup
                                  children: [
                                    (AndOr
                                      children: [
                                        (C {(Lit_Other "[")} {(-z)} 
                                          {(DQ ($ VSub_Name "$h") ($ VSub_Name "$i"))} {(Lit_Other "]")}
                                        )
                                        (ControlFlow
                                          token: <ControlFlow_Continue continue>
                                        )
                                      ]
                                      op_id: Op_DAmp
                                    )
                                    (Case
                                      to_match: {(DQ ($ VSub_Name "$h"))}
                                      arms: [
                                        (case_arm
                                          pat_list: [{(SQ )}]
                                          action: [
                                            (Assignment
                                              keyword: Assign_None
                                              pairs: [
                                                (assign_pair
                                                  lhs: (LhsName name:th)
                                                  op: Equal
                                                  rhs: {(SQ <"%">)}
                                                  spids: [684]
                                                )
                                              ]
                                              spids: [684]
                                            )
                                          ]
                                          spids: [-1 682 689 -1]
                                        )
                                        (case_arm
                                          pat_list: [{(Lit_Other "*")}]
                                          action: [
                                            (Assignment
                                              keyword: Assign_None
                                              pairs: [
                                                (assign_pair
                                                  lhs: (LhsName name:th)
                                                  op: Equal
                                                  rhs: {(SQ )}
                                                  spids: [694]
                                                )
                                              ]
                                              spids: [694]
                                            )
                                          ]
                                          spids: [691 692 696 -1]
                                        )
                                      ]
                                      spids: [672 678 698]
                                    )
                                    (Assignment
                                      keyword: Assign_None
                                      pairs: [
                                        (assign_pair
                                          lhs: (LhsName name:rule)
                                          op: Equal
                                          rhs: 
                                            {(${ VSub_Name t) (trailing) (Lit_Comma ",") 
                                              (${ VSub_Name s) (space) (Lit_Comma ",") (${ VSub_Name i) (indent) (Lit_Comma ",") (${ VSub_Name h) (tab)
                                            }
                                          spids: [701]
                                        )
                                      ]
                                      spids: [701]
                                    )
                                    (C {(rm)} {(-f)} {(.gitattributes)})
                                    (C {(test_expect_success)} {(DQ ("rule=") ($ VSub_Name "$rule"))} 
                                      {
                                        (SQ <"\n"> 
                                          <"\t\t\t\t\tgit config core.whitespace \"$rule\" &&\n"> <"\t\t\t\t\ttest_fix \"$tt$ts$ti$th\"\n"> <"\t\t\t\t">
                                        )
                                      }
                                    )
                                    (C {(test_expect_success)} 
                                      {(DQ ("rule=") ($ VSub_Name "$rule") (",tabwidth=16"))} 
                                      {
                                        (SQ <"\n"> 
                                          <
"\t\t\t\t\tgit config core.whitespace \"$rule,tabwidth=16\" &&\n"
                                          > <"\t\t\t\t\ttest_fix \"$tt$ts$ti16$th\"\n"> <"\t\t\t\t">
                                        )
                                      }
                                    )
                                    (C {(test_expect_success)} 
                                      {(DQ ("rule=") ($ VSub_Name "$rule") (" (attributes)"))} 
                                      {
                                        (SQ <"\n"> 
                                          <"\t\t\t\t\tgit config --unset core.whitespace &&\n"> <"\t\t\t\t\techo \"target whitespace=$rule\" >.gitattributes &&\n"> 
                                          <"\t\t\t\t\ttest_fix \"$tt$ts$ti$th\"\n"> <"\t\t\t\t">
                                        )
                                      }
                                    )
                                    (C {(test_expect_success)} 
                                      {
                                        (DQ ("rule=") ($ VSub_Name "$rule") 
                                          (",tabwidth=16 (attributes)")
                                        )
                                      } 
                                      {
                                        (SQ <"\n"> 
                                          <
"\t\t\t\t\techo \"target whitespace=$rule,tabwidth=16\" >.gitattributes &&\n"
                                          > <"\t\t\t\t\ttest_fix \"$tt$ts$ti16$th\"\n"> <"\t\t\t\t">
                                        )
                                      }
                                    )
                                  ]
                                  spids: [653 799]
                                )
                              spids: [646 -1]
                            )
                          ]
                          spids: [603 802]
                        )
                      spids: [596 -1]
                    )
                  ]
                  spids: [559 805]
                )
              spids: [552 -1]
            )
          ]
          spids: [515 807]
        )
      spids: [509 -1]
    )
    (FuncDef
      name: create_patch
      body: 
        (BraceGroup
          children: [
            (SimpleCommand
              words: [{(sed)} {(-e)} {(DQ ("s/_/ /"))}]
              redirects: [
                (HereDoc
                  op_id: Redir_DLessDash
                  fd: -1
                  body: 
                    {("diff --git a/target b/target\n") ("index e69de29..8bd6648 100644\n") 
                      ("--- a/target\n") ("+++ b/target\n") ("@@ -0,0 +1,3 @@\n") ("+An empty line follows\n") ("+\n") 
                      ("+A line with trailing whitespace and no newline_\n") ("\\ No newline at end of file\n")
                    }
                  do_expansion: False
                  here_end: EOF
                  was_filled: True
                  spids: [826]
                )
              ]
            )
          ]
          spids: [815]
        )
      spids: [810 814]
    )
    (C {(test_expect_success)} {(SQ <"trailing whitespace & no newline at the end of file">)} 
      {
        (SQ <"\n"> <"\t>target &&\n"> <"\tcreate_patch >patch-file &&\n"> 
          <"\tgit apply --whitespace=fix patch-file &&\n"> <"\tgrep \"newline$\" target &&\n"> <"\tgrep \"^$\" target\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"blank at EOF with --whitespace=fix (1)">)} 
      {
        (SQ <"\n"> <"\ttest_might_fail git config --unset core.whitespace &&\n"> 
          <"\trm -f .gitattributes &&\n"> <"\n"> <"\t{ echo a; echo b; echo c; } >one &&\n"> <"\tgit add one &&\n"> 
          <"\t{ echo a; echo b; echo c; } >expect &&\n"> <"\t{ cat expect; echo; } >one &&\n"> <"\tgit diff -- one >patch &&\n"> <"\n"> 
          <"\tgit checkout one &&\n"> <"\tgit apply --whitespace=fix patch &&\n"> <"\ttest_cmp expect one\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"blank at EOF with --whitespace=fix (2)">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo b; echo c; } >one &&\n"> <"\tgit add one &&\n"> 
          <"\t{ echo a; echo c; } >expect &&\n"> <"\t{ cat expect; echo; echo; } >one &&\n"> <"\tgit diff -- one >patch &&\n"> <"\n"> 
          <"\tgit checkout one &&\n"> <"\tgit apply --whitespace=fix patch &&\n"> <"\ttest_cmp expect one\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"blank at EOF with --whitespace=fix (3)">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo b; echo; } >one &&\n"> <"\tgit add one &&\n"> 
          <"\t{ echo a; echo c; echo; } >expect &&\n"> <"\t{ cat expect; echo; echo; } >one &&\n"> <"\tgit diff -- one >patch &&\n"> <"\n"> 
          <"\tgit checkout one &&\n"> <"\tgit apply --whitespace=fix patch &&\n"> <"\ttest_cmp expect one\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"blank at end of hunk, not at EOF with --whitespace=fix">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo b; echo; echo; echo; echo; echo; echo d; } >one &&\n"> 
          <"\tgit add one &&\n"> <"\t{ echo a; echo c; echo; echo; echo; echo; echo; echo; echo d; } >expect &&\n"> 
          <"\tcp expect one &&\n"> <"\tgit diff -- one >patch &&\n"> <"\n"> <"\tgit checkout one &&\n"> 
          <"\tgit apply --whitespace=fix patch &&\n"> <"\ttest_cmp expect one\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"blank at EOF with --whitespace=warn">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo b; echo c; } >one &&\n"> <"\tgit add one &&\n"> 
          <"\techo >>one &&\n"> <"\tcat one >expect &&\n"> <"\tgit diff -- one >patch &&\n"> <"\n"> <"\tgit checkout one &&\n"> 
          <"\tgit apply --whitespace=warn patch 2>error &&\n"> <"\ttest_cmp expect one &&\n"> <"\tgrep \"new blank line at EOF\" error\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"blank at EOF with --whitespace=error">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo b; echo c; } >one &&\n"> <"\tgit add one &&\n"> 
          <"\tcat one >expect &&\n"> <"\techo >>one &&\n"> <"\tgit diff -- one >patch &&\n"> <"\n"> <"\tgit checkout one &&\n"> 
          <"\ttest_must_fail git apply --whitespace=error patch 2>error &&\n"> <"\ttest_cmp expect one &&\n"> <"\tgrep \"new blank line at EOF\" error\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"blank but not empty at EOF">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo b; echo c; } >one &&\n"> <"\tgit add one &&\n"> 
          <"\techo \"   \" >>one &&\n"> <"\tcat one >expect &&\n"> <"\tgit diff -- one >patch &&\n"> <"\n"> <"\tgit checkout one &&\n"> 
          <"\tgit apply --whitespace=warn patch 2>error &&\n"> <"\ttest_cmp expect one &&\n"> <"\tgrep \"new blank line at EOF\" error\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"applying beyond EOF requires one non-blank context line">)} 
      {
        (SQ <"\n"> <"\t{ echo; echo; echo; echo; } >one &&\n"> <"\tgit add one &&\n"> 
          <"\t{ echo b; } >>one &&\n"> <"\tgit diff -- one >patch &&\n"> <"\n"> <"\tgit checkout one &&\n"> <"\t{ echo a; echo; } >one &&\n"> 
          <"\tcp one expect &&\n"> <"\ttest_must_fail git apply --whitespace=fix patch &&\n"> <"\ttest_cmp one expect &&\n"> 
          <"\ttest_must_fail git apply --ignore-space-change --whitespace=fix patch &&\n"> <"\ttest_cmp one expect\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"tons of blanks at EOF should not apply">)} 
      {
        (SQ <"\n"> <"\tfor i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do\n"> 
          <"\t\techo; echo; echo; echo;\n"> <"\tdone >one &&\n"> <"\tgit add one &&\n"> <"\techo a >>one &&\n"> <"\tgit diff -- one >patch &&\n"> 
          <"\n"> <"\t>one &&\n"> <"\ttest_must_fail git apply --whitespace=fix patch &&\n"> 
          <"\ttest_must_fail git apply --ignore-space-change --whitespace=fix patch\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"missing blank line at end with --whitespace=fix">)} 
      {
        (SQ <"\n"> <"\techo a >one &&\n"> <"\techo >>one &&\n"> <"\tgit add one &&\n"> 
          <"\techo b >>one &&\n"> <"\tcp one expect &&\n"> <"\tgit diff -- one >patch &&\n"> <"\techo a >one &&\n"> 
          <"\tcp one saved-one &&\n"> <"\ttest_must_fail git apply patch &&\n"> <"\tgit apply --whitespace=fix patch &&\n"> 
          <"\ttest_cmp one expect &&\n"> <"\tmv saved-one one &&\n"> <"\tgit apply --ignore-space-change --whitespace=fix patch &&\n"> 
          <"\ttest_cmp one expect\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"two missing blank lines at end with --whitespace=fix">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo; echo b; echo c; } >one &&\n"> <"\tcp one no-blank-lines &&\n"> 
          <"\t{ echo; echo; } >>one &&\n"> <"\tgit add one &&\n"> <"\techo d >>one &&\n"> <"\tcp one expect &&\n"> <"\techo >>one &&\n"> 
          <"\tgit diff -- one >patch &&\n"> <"\tcp no-blank-lines one &&\n"> <"\ttest_must_fail git apply patch &&\n"> 
          <"\tgit apply --whitespace=fix patch &&\n"> <"\ttest_cmp one expect &&\n"> <"\tmv no-blank-lines one &&\n"> 
          <"\ttest_must_fail git apply patch &&\n"> <"\tgit apply --ignore-space-change --whitespace=fix patch &&\n"> <"\ttest_cmp one expect\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"missing blank line at end, insert before end, --whitespace=fix">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo; } >one &&\n"> <"\tgit add one &&\n"> 
          <"\t{ echo b; echo a; echo; } >one &&\n"> <"\tcp one expect &&\n"> <"\tgit diff -- one >patch &&\n"> <"\techo a >one &&\n"> 
          <"\ttest_must_fail git apply patch &&\n"> <"\tgit apply --whitespace=fix patch &&\n"> <"\ttest_cmp one expect\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"shrink file with tons of missing blanks at end of file">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo b; echo c; } >one &&\n"> <"\tcp one no-blank-lines &&\n"> 
          <"\tfor i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do\n"> <"\t\techo; echo; echo; echo;\n"> <"\tdone >>one &&\n"> <"\tgit add one &&\n"> <"\techo a >one &&\n"> 
          <"\tcp one expect &&\n"> <"\tgit diff -- one >patch &&\n"> <"\tcp no-blank-lines one &&\n"> 
          <"\ttest_must_fail git apply patch &&\n"> <"\tgit apply --whitespace=fix patch &&\n"> <"\ttest_cmp one expect &&\n"> 
          <"\tmv no-blank-lines one &&\n"> <"\tgit apply --ignore-space-change --whitespace=fix patch &&\n"> <"\ttest_cmp one expect\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"missing blanks at EOF must only match blank lines">)} 
      {
        (SQ <"\n"> <"\t{ echo a; echo b; } >one &&\n"> <"\tgit add one &&\n"> 
          <"\t{ echo c; echo d; } >>one &&\n"> <"\tgit diff -- one >patch &&\n"> <"\n"> <"\techo a >one &&\n"> 
          <"\ttest_must_fail git apply patch &&\n"> <"\ttest_must_fail git apply --whitespace=fix patch &&\n"> 
          <"\ttest_must_fail git apply --ignore-space-change --whitespace=fix patch\n">
        )
      }
    )
    (SimpleCommand
      words: [{(sed)} {(-e) (SQ <s/Z//>)}]
      redirects: [
        (Redir op_id:Redir_Great fd:-1 arg_word:{(one)} spids:[1165])
        (HereDoc
          op_id: Redir_DLess
          fd: -1
          body: {(DQ ("a\n") ("b\n") ("c\n") ("\t\t      Z\n"))}
          do_expansion: True
          here_end: EOF
          was_filled: True
          spids: [1168]
        )
      ]
    )
    (C {(test_expect_success)} {(SQ <"missing blank line should match context line with spaces">)} 
      {
        (SQ <"\n"> <"\tgit add one &&\n"> <"\techo d >>one &&\n"> <"\tgit diff -- one >patch &&\n"> 
          <"\t{ echo a; echo b; echo c; } >one &&\n"> <"\tcp one expect &&\n"> <"\t{ echo; echo d; } >>expect &&\n"> <"\tgit add one &&\n"> <"\n"> 
          <"\tgit apply --whitespace=fix patch &&\n"> <"\ttest_cmp one expect\n">
        )
      }
    )
    (SimpleCommand
      words: [{(sed)} {(-e) (SQ <s/Z//>)}]
      redirects: [
        (Redir op_id:Redir_Great fd:-1 arg_word:{(one)} spids:[1204])
        (HereDoc
          op_id: Redir_DLess
          fd: -1
          body: {(DQ ("a\n") ("b\n") ("c\n") ("\t\t      Z\n"))}
          do_expansion: True
          here_end: EOF
          was_filled: True
          spids: [1207]
        )
      ]
    )
    (C {(test_expect_success)} {(SQ <"same, but with the --ignore-space-option">)} 
      {
        (SQ <"\n"> <"\tgit add one &&\n"> <"\techo d >>one &&\n"> <"\tcp one expect &&\n"> 
          <"\tgit diff -- one >patch &&\n"> <"\t{ echo a; echo b; echo c; } >one &&\n"> <"\tgit add one &&\n"> <"\n"> 
          <"\tgit checkout-index -f one &&\n"> <"\tgit apply --ignore-space-change --whitespace=fix patch &&\n"> <"\ttest_cmp one expect\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"same, but with CR-LF line endings && cr-at-eol set">)} 
      {
        (SQ <"\n"> <"\tgit config core.whitespace cr-at-eol &&\n"> <"\tprintf \"a\\r\\n\" >one &&\n"> 
          <"\tprintf \"b\\r\\n\" >>one &&\n"> <"\tprintf \"c\\r\\n\" >>one &&\n"> <"\tcp one save-one &&\n"> 
          <"\tprintf \"                 \\r\\n\" >>one &&\n"> <"\tgit add one &&\n"> <"\tprintf \"d\\r\\n\" >>one &&\n"> <"\tcp one expect &&\n"> 
          <"\tgit diff -- one >patch &&\n"> <"\tmv save-one one &&\n"> <"\n"> <"\tgit apply --ignore-space-change --whitespace=fix patch &&\n"> 
          <"\ttest_cmp one expect\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"same, but with CR-LF line endings && cr-at-eol unset">)} 
      {
        (SQ <"\n"> <"\tgit config --unset core.whitespace &&\n"> <"\tprintf \"a\\r\\n\" >one &&\n"> 
          <"\tprintf \"b\\r\\n\" >>one &&\n"> <"\tprintf \"c\\r\\n\" >>one &&\n"> <"\tcp one save-one &&\n"> 
          <"\tprintf \"                 \\r\\n\" >>one &&\n"> <"\tgit add one &&\n"> <"\tcp one expect &&\n"> <"\tprintf \"d\\r\\n\" >>one &&\n"> 
          <"\tgit diff -- one >patch &&\n"> <"\tmv save-one one &&\n"> <"\techo d >>expect &&\n"> <"\n"> 
          <"\tgit apply --ignore-space-change --whitespace=fix patch &&\n"> <"\ttest_cmp one expect\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"whitespace=fix to expand">)} 
      {
        (SQ <"\n"> <"\tqz_to_tab_space >preimage <<-\\EOF &&\n"> <"\tQQa\n"> <"\tQQb\n"> <"\tQQc\n"> 
          <"\tZZZZZZZZZZZZZZZZd\n"> <"\tQQe\n"> <"\tQQf\n"> <"\tQQg\n"> <"\tEOF\n"> <"\tqz_to_tab_space >patch <<-\\EOF &&\n"> 
          <"\tdiff --git a/preimage b/preimage\n"> <"\t--- a/preimage\n"> <"\t+++ b/preimage\n"> <"\t@@ -1,7 +1,6 @@\n"> <"\t QQa\n"> <"\t QQb\n"> 
          <"\t QQc\n"> <"\t-QQd\n"> <"\t QQe\n"> <"\t QQf\n"> <"\t QQg\n"> <"\tEOF\n"> 
          <"\tgit -c core.whitespace=tab-in-indent apply --whitespace=fix patch\n">
        )
      }
    )
    (C {(test_expect_success)} {(SQ <"whitespace check skipped for excluded paths">)} 
      {
        (SQ <"\n"> <"\tgit config core.whitespace blank-at-eol &&\n"> <"\t>used &&\n"> 
          <"\t>unused &&\n"> <"\tgit add used unused &&\n"> <"\techo \"used\" >used &&\n"> <"\techo \"unused \" >unused &&\n"> 
          <"\tgit diff-files -p used unused >patch &&\n"> <"\tgit apply --include=used --stat --whitespace=error <patch\n">
        )
      }
    )
    (C {(test_done)})
  ]
)