(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'apply same filename'>)}
          spids: [4]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShFunction
      name: modify
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [{<sed>} {<-e>} {(DQ ($ Id.VSub_Number '$1'))}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Less '<'>
                      loc: (redir_loc.Fd fd:0)
                      arg: {(DQ ($ Id.VSub_Number '$2'))}
                    )
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {(DQ ($ Id.VSub_Number '$2')) <.x>}
                    )
                  ]
                  do_fork: T
                )
                (C {<mv>} {(DQ ($ Id.VSub_Number '$2')) <.x>} {(DQ ($ Id.VSub_Number '$2'))})
              ]
            )
          ]
        )
    )
    (C {<test_expect_success>} {<setup>} 
      {
        (SQ <'\n'> <'\tfor i in a b c d e f g h i j k l m\n'> <'\tdo\n'> <'\t\techo $i\n'> 
          <'\tdone >same_fn &&\n'> <'\tcp same_fn other_fn &&\n'> <'\tgit add same_fn other_fn &&\n'> <'\tgit commit -m initial\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'apply same filename with independent changes'>)} 
      {
        (SQ <'\n'> <'\tmodify "s/^d/z/" same_fn &&\n'> <'\tgit diff > patch0 &&\n'> 
          <'\tgit add same_fn &&\n'> <'\tmodify "s/^i/y/" same_fn &&\n'> <'\tgit diff >> patch0 &&\n'> <'\tcp same_fn same_fn2 &&\n'> 
          <'\tgit reset --hard &&\n'> <'\tgit apply patch0 &&\n'> <'\ttest_cmp same_fn same_fn2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'apply same filename with overlapping changes'>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard &&\n'> <'\tmodify "s/^d/z/" same_fn &&\n'> 
          <'\tgit diff > patch0 &&\n'> <'\tgit add same_fn &&\n'> <'\tmodify "s/^e/y/" same_fn &&\n'> <'\tgit diff >> patch0 &&\n'> 
          <'\tcp same_fn same_fn2 &&\n'> <'\tgit reset --hard &&\n'> <'\tgit apply patch0 &&\n'> <'\ttest_cmp same_fn same_fn2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'apply same new filename after rename'>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard &&\n'> <'\tgit mv same_fn new_fn &&\n'> 
          <'\tmodify "s/^d/z/" new_fn &&\n'> <'\tgit add new_fn &&\n'> <'\tgit diff -M --cached > patch1 &&\n'> <'\tmodify "s/^e/y/" new_fn &&\n'> 
          <'\tgit diff >> patch1 &&\n'> <'\tcp new_fn new_fn2 &&\n'> <'\tgit reset --hard &&\n'> <'\tgit apply --index patch1 &&\n'> 
          <'\ttest_cmp new_fn new_fn2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'apply same old filename after rename -- should fail.'>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard &&\n'> <'\tgit mv same_fn new_fn &&\n'> 
          <'\tmodify "s/^d/z/" new_fn &&\n'> <'\tgit add new_fn &&\n'> <'\tgit diff -M --cached > patch1 &&\n'> <'\tgit mv new_fn same_fn &&\n'> 
          <'\tmodify "s/^e/y/" same_fn &&\n'> <'\tgit diff >> patch1 &&\n'> <'\tgit reset --hard &&\n'> <'\ttest_must_fail git apply patch1\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'apply A->B (rename), C->A (rename), A->A -- should pass.'>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard &&\n'> <'\tgit mv same_fn new_fn &&\n'> 
          <'\tmodify "s/^d/z/" new_fn &&\n'> <'\tgit add new_fn &&\n'> <'\tgit diff -M --cached > patch1 &&\n'> <'\tgit commit -m "a rename" &&\n'> 
          <'\tgit mv other_fn same_fn &&\n'> <'\tmodify "s/^e/y/" same_fn &&\n'> <'\tgit add same_fn &&\n'> 
          <'\tgit diff -M --cached >> patch1 &&\n'> <'\tmodify "s/^g/x/" same_fn &&\n'> <'\tgit diff >> patch1 &&\n'> <'\tgit reset --hard HEAD^ &&\n'> 
          <'\tgit apply patch1\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)