(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'external diff interface test'>)}
          spids: [4]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (C {<test_expect_success>} {<setup>} 
      {
        (SQ <'\n'> <'\n'> <'\ttest_tick &&\n'> <'\techo initial >file &&\n'> <'\tgit add file &&\n'> 
          <'\tgit commit -m initial &&\n'> <'\n'> <'\ttest_tick &&\n'> <'\techo second >file &&\n'> <'\tgit add file &&\n'> 
          <'\tgit commit -m second &&\n'> <'\n'> <'\ttest_tick &&\n'> <'\techo third >file\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'GIT_EXTERNAL_DIFF environment'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tGIT_EXTERNAL_DIFF=echo git diff | {\n'> 
          <'\t\tread path oldfile oldhex oldmode newfile newhex newmode &&\n'> <'\t\ttest "z$path" = zfile &&\n'> <'\t\ttest "z$oldmode" = z100644 &&\n'> 
          <'\t\ttest "z$newhex" = "z$_z40" &&\n'> <'\t\ttest "z$newmode" = z100644 &&\n'> <'\t\toh=$(git rev-parse --verify HEAD:file) &&\n'> 
          <'\t\ttest "z$oh" = "z$oldhex"\n'> <'\t}\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'GIT_EXTERNAL_DIFF environment should apply only to diff'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tGIT_EXTERNAL_DIFF=echo git log -p -1 HEAD |\n'> 
          <'\tgrep "^diff --git a/file b/file"\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'GIT_EXTERNAL_DIFF environment and --no-ext-diff'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tGIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |\n'> 
          <'\tgrep "^diff --git a/file b/file"\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {<SYMLINKS>} {(SQ <'typechange diff'>)} 
      {
        (SQ <'\n'> <'\trm -f file &&\n'> <'\tln -s elif file &&\n'> 
          <'\tGIT_EXTERNAL_DIFF=echo git diff  | {\n'> <'\t\tread path oldfile oldhex oldmode newfile newhex newmode &&\n'> 
          <'\t\ttest "z$path" = zfile &&\n'> <'\t\ttest "z$oldmode" = z100644 &&\n'> <'\t\ttest "z$newhex" = "z$_z40" &&\n'> 
          <'\t\ttest "z$newmode" = z120000 &&\n'> <'\t\toh=$(git rev-parse --verify HEAD:file) &&\n'> <'\t\ttest "z$oh" = "z$oldhex"\n'> <'\t} &&\n'> 
          <'\tGIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&\n'> <'\tgit diff >expect &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <diff.external>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard &&\n'> <'\techo third >file &&\n'> 
          <'\ttest_config diff.external echo &&\n'> <'\tgit diff | {\n'> <'\t\tread path oldfile oldhex oldmode newfile newhex newmode &&\n'> 
          <'\t\ttest "z$path" = zfile &&\n'> <'\t\ttest "z$oldmode" = z100644 &&\n'> <'\t\ttest "z$newhex" = "z$_z40" &&\n'> 
          <'\t\ttest "z$newmode" = z100644 &&\n'> <'\t\toh=$(git rev-parse --verify HEAD:file) &&\n'> <'\t\ttest "z$oh" = "z$oldhex"\n'> <'\t}\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'diff.external should apply only to diff'>)} 
      {
        (SQ <'\n'> <'\ttest_config diff.external echo &&\n'> <'\tgit log -p -1 HEAD |\n'> 
          <'\tgrep "^diff --git a/file b/file"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'diff.external and --no-ext-diff'>)} 
      {
        (SQ <'\n'> <'\ttest_config diff.external echo &&\n'> <'\tgit diff --no-ext-diff |\n'> 
          <'\tgrep "^diff --git a/file b/file"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'diff attribute'>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard &&\n'> <'\techo third >file &&\n'> <'\n'> 
          <'\tgit config diff.parrot.command echo &&\n'> <'\n'> <'\techo >.gitattributes "file diff=parrot" &&\n'> <'\n'> <'\tgit diff | {\n'> 
          <'\t\tread path oldfile oldhex oldmode newfile newhex newmode &&\n'> <'\t\ttest "z$path" = zfile &&\n'> <'\t\ttest "z$oldmode" = z100644 &&\n'> 
          <'\t\ttest "z$newhex" = "z$_z40" &&\n'> <'\t\ttest "z$newmode" = z100644 &&\n'> <'\t\toh=$(git rev-parse --verify HEAD:file) &&\n'> 
          <'\t\ttest "z$oh" = "z$oldhex"\n'> <'\t}\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'diff attribute should apply only to diff'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit log -p -1 HEAD |\n'> <'\tgrep "^diff --git a/file b/file"\n'> <'\n'>)
      }
    )
    (C {<test_expect_success>} {(SQ <'diff attribute and --no-ext-diff'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit diff --no-ext-diff |\n'> <'\tgrep "^diff --git a/file b/file"\n'> 
          <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'diff attribute'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit config --unset diff.parrot.command &&\n'> 
          <'\tgit config diff.color.command echo &&\n'> <'\n'> <'\techo >.gitattributes "file diff=color" &&\n'> <'\n'> <'\tgit diff | {\n'> 
          <'\t\tread path oldfile oldhex oldmode newfile newhex newmode &&\n'> <'\t\ttest "z$path" = zfile &&\n'> <'\t\ttest "z$oldmode" = z100644 &&\n'> 
          <'\t\ttest "z$newhex" = "z$_z40" &&\n'> <'\t\ttest "z$newmode" = z100644 &&\n'> <'\t\toh=$(git rev-parse --verify HEAD:file) &&\n'> 
          <'\t\ttest "z$oh" = "z$oldhex"\n'> <'\t}\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'diff attribute should apply only to diff'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit log -p -1 HEAD |\n'> <'\tgrep "^diff --git a/file b/file"\n'> <'\n'>)
      }
    )
    (C {<test_expect_success>} {(SQ <'diff attribute and --no-ext-diff'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit diff --no-ext-diff |\n'> <'\tgrep "^diff --git a/file b/file"\n'> 
          <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'GIT_EXTERNAL_DIFF trumps diff.external'>)} 
      {
        (SQ <'\n'> <'\t>.gitattributes &&\n'> <'\ttest_config diff.external "echo ext-global" &&\n'> 
          <'\tGIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-env\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'attributes trump GIT_EXTERNAL_DIFF and diff.external'>)} 
      {
        (SQ <'\n'> <'\ttest_config diff.foo.command "echo ext-attribute" &&\n'> 
          <'\ttest_config diff.external "echo ext-global" &&\n'> <'\techo "file diff=foo" >.gitattributes &&\n'> 
          <'\tGIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-attribute\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'no diff with -diff'>)} 
      {(SQ <'\n'> <'\techo >.gitattributes "file -diff" &&\n'> <'\tgit diff | grep Binary\n'>)}
    )
    (command.Pipeline
      children: [
        (C {<echo>} {<NULZbetweenZwords>})
        (command.Simple
          words: [{<perl>} {<-pe>} {(SQ <'y/Z/\\000/'>)}]
          redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<file>})]
          do_fork: T
        )
      ]
      negated: F
    )
    (C {<test_expect_success>} {(SQ <'force diff with "diff"'>)} 
      {
        (SQ <'\n'> <'\techo >.gitattributes "file diff" &&\n'> <'\tgit diff >actual &&\n'> 
          <'\ttest_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'GIT_EXTERNAL_DIFF with more than one changed files'>)} 
      {
        (SQ <'\n'> <'\techo anotherfile > file2 &&\n'> <'\tgit add file2 &&\n'> 
          <'\tgit commit -m "added 2nd file" &&\n'> <'\techo modified >file2 &&\n'> <'\tGIT_EXTERNAL_DIFF=echo git diff\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'GIT_EXTERNAL_DIFF path counter/total'>)} 
      {
        (SQ <'\n'> <'\twrite_script external-diff.sh <<-\\EOF &&\n'> 
          <'\techo $GIT_DIFF_PATH_COUNTER of $GIT_DIFF_PATH_TOTAL >>counter.txt\n'> <'\tEOF\n'> <'\t>counter.txt &&\n'> <'\tcat >expect <<-\\EOF &&\n'> <'\t1 of 2\n'> <'\t2 of 2\n'> 
          <'\tEOF\n'> <'\tGIT_EXTERNAL_DIFF=./external-diff.sh git diff &&\n'> <'\ttest_cmp expect counter.txt\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'GIT_EXTERNAL_DIFF generates pretty paths'>)} 
      {
        (SQ <'\n'> <'\ttouch file.ext &&\n'> <'\tgit add file.ext &&\n'> 
          <'\techo with extension > file.ext &&\n'> <'\tGIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\\.ext &&\n'> 
          <'\tgit update-index --force-remove file.ext &&\n'> <'\trm file.ext\n'>
        )
      }
    )
    (command.Simple
      words: [{<echo>} {(DQ <'#!'> ($ Id.VSub_DollarName '$SHELL_PATH'))}]
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<fake-diff.sh>})]
      do_fork: T
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_DGreat '>>'> loc:(redir_loc.Fd fd:1) arg:{<fake-diff.sh>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {(word_part.EscapedLiteral token:<Id.Lit_EscapedChar '\\E'>) <OF>}
              here_end_span_id: 432
              stdin_parts: [<'cat $2 >> crlfed.txt\n'>]
            )
        )
      ]
      do_fork: T
    )
    (C {<chmod>} {<a> <Id.Lit_Other '+'> <x>} {<fake-diff.sh>})
    (command.ShFunction
      name: keep_only_cr
      body: (BraceGroup children:[(C {<tr>} {<-dc>} {(SQ <'\\015'>)})])
    )
    (C {<test_expect_success>} {(SQ <'external diff with autocrlf = true'>)} 
      {
        (SQ <'\n'> <'\ttest_config core.autocrlf true &&\n'> 
          <'\tGIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&\n'> <'\ttest $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'diff --cached'>)} 
      {
        (SQ <'\n'> <'\ttest_config core.autocrlf true &&\n'> <'\tgit add file &&\n'> 
          <'\tgit update-index --assume-unchanged file &&\n'> <'\techo second >file &&\n'> <'\tgit diff --cached >actual &&\n'> 
          <'\ttest_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'clean up crlf leftovers'>)} 
      {
        (SQ <'\n'> <'\tgit update-index --no-assume-unchanged file &&\n'> <'\trm -f file* &&\n'> 
          <'\tgit reset --hard\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'submodule diff'>)} 
      {
        (SQ <'\n'> <'\tgit init sub &&\n'> <'\t( cd sub && test_commit sub1 ) &&\n'> 
          <'\tgit add sub &&\n'> <'\ttest_tick &&\n'> <'\tgit commit -m "add submodule" &&\n'> <'\t( cd sub && test_commit sub2 ) &&\n'> 
          <'\twrite_script gather_pre_post.sh <<-\\EOF &&\n'> <'\techo "$1 $4" # path, mode\n'> <'\tcat "$2" # old file\n'> <'\tcat "$5" # new file\n'> <'\tEOF\n'> 
          <'\tGIT_EXTERNAL_DIFF=./gather_pre_post.sh git diff >actual &&\n'> <'\tcat >expected <<-EOF &&\n'> <'\tsub 160000\n'> <'\tSubproject commit $(git rev-parse HEAD:sub)\n'> 
          <'\tSubproject commit $(cd sub && git rev-parse HEAD)\n'> <'\tEOF\n'> <'\ttest_cmp expected actual\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)