(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: 
            {
              (SQ <'merge-recursive rename options\n'> <'\n'> 
                <'Test rename detection by examining rename/delete conflicts.\n'> <'\n'> <'* (HEAD -> rename) rename\n'> <'| * (master) delete\n'> <'|/\n'> <'* base\n'> <'\n'> 
                <'git diff --name-status base master\n'> <'D\t0-old\n'> <'D\t1-old\n'> <'D\t2-old\n'> <'D\t3-old\n'> <'\n'> 
                <'git diff --name-status -M01 base rename\n'> <'R025    0-old   0-new\n'> <'R050    1-old   1-new\n'> <'R075    2-old   2-new\n'> 
                <'R100    3-old   3-new\n'> <'\n'> <'Actual similarity indices are parsed from diff output. We rely on the fact that\n'> 
                <'they are rounded down (see, e.g., Documentation/diff-generate-patch.txt, which\n'> <'mentions this in a different context).\n'>
              )
            }
          spids: [4]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShFunction
      name: get_expected_stages
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (C {<git>} {<checkout>} {<rename>} {<-->} {($ Id.VSub_Number '$1') <-new>})
                (command.Simple
                  words: [{<git>} {<ls-files>} {<--stage>} {($ Id.VSub_Number '$1') <-new>}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {<expected-stages-undetected-> ($ Id.VSub_Number '$1')}
                    )
                  ]
                  do_fork: T
                )
                (command.Simple
                  words: [{<sed>} {(DQ <'s/ 0\t/ 2\t/'>)}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Less '<'>
                      loc: (redir_loc.Fd fd:0)
                      arg: {<expected-stages-undetected-> ($ Id.VSub_Number '$1')}
                    )
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {<expected-stages-detected-> ($ Id.VSub_Number '$1')}
                    )
                  ]
                  do_fork: T
                )
                (C {<git>} {<read-tree>} {<-u>} {<--reset>} {<HEAD>})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: rename_detected
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [
                    {<git>}
                    {<ls-files>}
                    {<--stage>}
                    {($ Id.VSub_Number '$1') <-old>}
                    {($ Id.VSub_Number '$1') <-new>}
                  ]
                  redirects: [
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {<stages-actual-> ($ Id.VSub_Number '$1')}
                    )
                  ]
                  do_fork: T
                )
                (C {<test_cmp>} {<expected-stages-detected-> ($ Id.VSub_Number '$1')} 
                  {<stages-actual-> ($ Id.VSub_Number '$1')}
                )
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: rename_undetected
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [
                    {<git>}
                    {<ls-files>}
                    {<--stage>}
                    {($ Id.VSub_Number '$1') <-old>}
                    {($ Id.VSub_Number '$1') <-new>}
                  ]
                  redirects: [
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {<stages-actual-> ($ Id.VSub_Number '$1')}
                    )
                  ]
                  do_fork: T
                )
                (C {<test_cmp>} {<expected-stages-undetected-> ($ Id.VSub_Number '$1')} 
                  {<stages-actual-> ($ Id.VSub_Number '$1')}
                )
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: check_common
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [{<git>} {<ls-files>} {<--stage>}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {<stages-actual>}
                    )
                  ]
                  do_fork: T
                )
                (C {<test_line_count>} {<Id.Lit_Equals '='>} {<4>} {<stages-actual>})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: check_threshold_0
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (C {<check_common>})
                (C {<rename_detected>} {<0>})
                (C {<rename_detected>} {<1>})
                (C {<rename_detected>} {<2>})
                (C {<rename_detected>} {<3>})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: check_threshold_1
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (C {<check_common>})
                (C {<rename_undetected>} {<0>})
                (C {<rename_detected>} {<1>})
                (C {<rename_detected>} {<2>})
                (C {<rename_detected>} {<3>})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: check_threshold_2
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (C {<check_common>})
                (C {<rename_undetected>} {<0>})
                (C {<rename_undetected>} {<1>})
                (C {<rename_detected>} {<2>})
                (C {<rename_detected>} {<3>})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: check_exact_renames
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (C {<check_common>})
                (C {<rename_undetected>} {<0>})
                (C {<rename_undetected>} {<1>})
                (C {<rename_undetected>} {<2>})
                (C {<rename_detected>} {<3>})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: check_no_renames
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (C {<check_common>})
                (C {<rename_undetected>} {<0>})
                (C {<rename_undetected>} {<1>})
                (C {<rename_undetected>} {<2>})
                (C {<rename_undetected>} {<3>})
              ]
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'setup repo'>)} 
      {
        (SQ <'\n'> <'\tcat <<-\\EOF >3-old &&\n'> <'\t33a\n'> <'\t33b\n'> <'\t33c\n'> <'\t33d\n'> 
          <'\tEOF\n'> <'\tsed s/33/22/ <3-old >2-old &&\n'> <'\tsed s/33/11/ <3-old >1-old &&\n'> 
          <'\tsed s/33/00/ <3-old >0-old &&\n'> <'\tgit add [0-3]-old &&\n'> <'\tgit commit -m base &&\n'> <'\tgit rm [0-3]-old &&\n'> 
          <'\tgit commit -m delete &&\n'> <'\tgit checkout -b rename HEAD^ &&\n'> <'\tcp 3-old 3-new &&\n'> 
          <'\tsed 1,1s/./x/ <2-old >2-new &&\n'> <'\tsed 1,2s/./x/ <1-old >1-new &&\n'> <'\tsed 1,3s/./x/ <0-old >0-new &&\n'> 
          <'\tgit add [0-3]-new &&\n'> <'\tgit rm [0-3]-old &&\n'> <'\tgit commit -m rename &&\n'> <'\tget_expected_stages 0 &&\n'> 
          <'\tget_expected_stages 1 &&\n'> <'\tget_expected_stages 2 &&\n'> <'\tget_expected_stages 3 &&\n'> <'\tcheck_50="false" &&\n'> 
          <'\ttail="HEAD^ -- HEAD master"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'setup thresholds'>)} 
      {
        (SQ <'\n'> <'\tgit diff --name-status -M01 HEAD^ HEAD >diff-output &&\n'> 
          <'\ttest_debug "cat diff-output" &&\n'> <'\ttest_line_count = 4 diff-output &&\n'> 
          <'\tgrep "R[0-9][0-9][0-9]\t\\([0-3]\\)-old\t\\1-new" diff-output \\\n'> <'\t\t>grep-output &&\n'> <'\ttest_cmp diff-output grep-output &&\n'> 
          <'\tth0=$(sed -n "s/R\\(...\\)\t0-old\t0-new/\\1/p" <diff-output) &&\n'> <'\tth1=$(sed -n "s/R\\(...\\)\t1-old\t1-new/\\1/p" <diff-output) &&\n'> 
          <'\tth2=$(sed -n "s/R\\(...\\)\t2-old\t2-new/\\1/p" <diff-output) &&\n'> <'\tth3=$(sed -n "s/R\\(...\\)\t3-old\t3-new/\\1/p" <diff-output) &&\n'> 
          <'\ttest "$th0" -lt "$th1" &&\n'> <'\ttest "$th1" -lt "$th2" &&\n'> <'\ttest "$th2" -lt "$th3" &&\n'> <'\ttest "$th3" = 100 &&\n'> 
          <'\tif test 50 -le "$th0"\n'> <'\tthen\n'> <'\t\tcheck_50=check_threshold_0\n'> <'\telif test 50 -le "$th1"\n'> <'\tthen\n'> 
          <'\t\tcheck_50=check_threshold_1\n'> <'\telif test 50 -le "$th2"\n'> <'\tthen\n'> <'\t\tcheck_50=check_threshold_2\n'> <'\tfi &&\n'> 
          <'\tth0="$th0%" &&\n'> <'\tth1="$th1%" &&\n'> <'\tth2="$th2%" &&\n'> <'\tth3="$th3%"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'assumption for tests: rename detection with diff'>)} 
      {
        (SQ <'\n'> <'\tgit diff --name-status -M$th0 --diff-filter=R HEAD^ HEAD \\\n'> 
          <'\t\t>diff-output-0 &&\n'> <'\tgit diff --name-status -M$th1 --diff-filter=R HEAD^ HEAD \\\n'> <'\t\t>diff-output-1 &&\n'> 
          <'\tgit diff --name-status -M$th2 --diff-filter=R HEAD^ HEAD \\\n'> <'\t\t>diff-output-2 &&\n'> <'\tgit diff --name-status -M100% --diff-filter=R HEAD^ HEAD \\\n'> 
          <'\t\t>diff-output-3 &&\n'> <'\ttest_line_count = 4 diff-output-0 &&\n'> <'\ttest_line_count = 3 diff-output-1 &&\n'> 
          <'\ttest_line_count = 2 diff-output-2 &&\n'> <'\ttest_line_count = 1 diff-output-3\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'default similarity threshold is 50%'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive $tail &&\n'> <'\t$check_50\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'low rename threshold'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --find-renames=$th0 $tail &&\n'> <'\tcheck_threshold_0\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'medium rename threshold'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --find-renames=$th1 $tail &&\n'> <'\tcheck_threshold_1\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'high rename threshold'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --find-renames=$th2 $tail &&\n'> <'\tcheck_threshold_2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'exact renames only'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --find-renames=100% $tail &&\n'> <'\tcheck_exact_renames\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'rename threshold is truncated'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --find-renames=200% $tail &&\n'> <'\tcheck_exact_renames\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'disabled rename detection'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\tgit merge-recursive --no-renames $tail &&\n'> <'\tcheck_no_renames\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'last wins in --find-renames=<m> --find-renames=<n>'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive \\\n'> <'\t\t--find-renames=$th0 --find-renames=$th2 $tail &&\n'> <'\tcheck_threshold_2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'--find-renames resets threshold'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive \\\n'> <'\t\t--find-renames=$th0 --find-renames $tail &&\n'> <'\t$check_50\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'last wins in --no-renames --find-renames'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --no-renames --find-renames $tail &&\n'> <'\t$check_50\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'last wins in --find-renames --no-renames'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\tgit merge-recursive --find-renames --no-renames $tail &&\n'> <'\tcheck_no_renames\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'assumption for further tests: trivial merge succeeds'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\tgit merge-recursive HEAD -- HEAD HEAD &&\n'> <'\tgit diff --quiet --cached &&\n'> 
          <'\tgit merge-recursive --find-renames=$th0 HEAD -- HEAD HEAD &&\n'> <'\tgit diff --quiet --cached &&\n'> 
          <'\tgit merge-recursive --find-renames=$th2 HEAD -- HEAD HEAD &&\n'> <'\tgit diff --quiet --cached &&\n'> 
          <'\tgit merge-recursive --find-renames=100% HEAD -- HEAD HEAD &&\n'> <'\tgit diff --quiet --cached &&\n'> <'\tgit merge-recursive --no-renames HEAD -- HEAD HEAD &&\n'> 
          <'\tgit diff --quiet --cached\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'--find-renames rejects negative argument'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --find-renames=-25 \\\n'> <'\t\tHEAD -- HEAD HEAD &&\n'> <'\tgit diff --quiet --cached\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'--find-renames rejects non-numbers'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --find-renames=0xf \\\n'> <'\t\tHEAD -- HEAD HEAD &&\n'> <'\tgit diff --quiet --cached\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'rename-threshold=<n> is a synonym for find-renames=<n>'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --rename-threshold=$th0 $tail &&\n'> <'\tcheck_threshold_0\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'last wins in --no-renames --rename-threshold=<n>'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --no-renames --rename-threshold=$th0 $tail &&\n'> <'\tcheck_threshold_0\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'last wins in --rename-threshold=<n> --no-renames'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\tgit merge-recursive --rename-threshold=$th0 --no-renames $tail &&\n'> <'\tcheck_no_renames\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'--rename-threshold=<n> rejects negative argument'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --rename-threshold=-25 \\\n'> <'\t\tHEAD -- HEAD HEAD &&\n'> <'\tgit diff --quiet --cached\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'--rename-threshold=<n> rejects non-numbers'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive --rename-threshold=0xf \\\n'> <'\t\tHEAD -- HEAD HEAD &&\n'> <'\tgit diff --quiet --cached\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'last wins in --rename-threshold=<m> --find-renames=<n>'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive \\\n'> <'\t\t--rename-threshold=$th0 --find-renames=$th2 $tail &&\n'> <'\tcheck_threshold_2\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'last wins in --find-renames=<m> --rename-threshold=<n>'>)} 
      {
        (SQ <'\n'> <'\tgit read-tree --reset -u HEAD &&\n'> 
          <'\ttest_must_fail git merge-recursive \\\n'> <'\t\t--find-renames=$th2 --rename-threshold=$th0 $tail &&\n'> <'\tcheck_threshold_0\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)