(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'git reset\n'> <'\n'> <'Documented tests for git reset'>)}
          spids: [13]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShFunction
      name: commit_msg
      body: 
        (BraceGroup
          children: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:msg)
                  op: assign_op.Equal
                  rhs: 
                    {
                      (DQ <'modify 2nd file (ge'> <Id.Lit_Other '\\'> <303> <Id.Lit_Other '\\'> 
                        <'244ndert)'> <Id.Lit_Other '\\'> <n>
                      )
                    }
                  spids: [46]
                )
              ]
            )
            (command.If
              arms: [
                (if_arm
                  cond: [(C {<test>} {<-n>} {(DQ ($ Id.VSub_Number '$1'))})]
                  action: [
                    (command.Pipeline
                      children: [
                        (C {<printf>} {(DQ ($ Id.VSub_DollarName '$msg'))})
                        (C {<iconv>} {<-f>} {<utf-8>} {<-t>} {(DQ ($ Id.VSub_Number '$1'))})
                      ]
                      negated: F
                    )
                  ]
                  spids: [58 69]
                )
              ]
              else_action: [(C {<printf>} {(DQ ($ Id.VSub_DollarName '$msg'))})]
            )
          ]
        )
    )
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_encoding)
          op: assign_op.Equal
          rhs: {(DQ <ISO8859-1>)}
          spids: [111]
        )
      ]
    )
    (C {<test_expect_success>} {(SQ <'creating initial files and commits'>)} 
      {
        (SQ <'\n'> <'\ttest_tick &&\n'> <'\techo "1st file" >first &&\n'> <'\tgit add first &&\n'> 
          <'\tgit commit -m "create 1st file" &&\n'> <'\n'> <'\techo "2nd file" >second &&\n'> <'\tgit add second &&\n'> 
          <'\tgit commit -m "create 2nd file" &&\n'> <'\n'> <'\techo "2nd line 1st file" >>first &&\n'> <'\tgit commit -a -m "modify 1st file" &&\n'> <'\n'> 
          <'\tgit rm first &&\n'> <'\tgit mv second secondfile &&\n'> <'\tgit commit -a -m "remove 1st and rename 2nd" &&\n'> <'\n'> 
          <'\techo "1st line 2nd file" >secondfile &&\n'> <'\techo "2nd line 2nd file" >>secondfile &&\n'> 
          <'\t# "git commit -m" would break MinGW, as Windows refuse to pass\n'> <'\t# $test_encoding encoded parameter to git.\n'> 
          <
'\tcommit_msg $test_encoding | git -c "i18n.commitEncoding=$test_encoding" commit -a -F - &&\n'
          > <'\thead5=$(git rev-parse --verify HEAD)\n'>
        )
      }
    )
    (command.ShFunction
      name: check_changes
      body: 
        (BraceGroup
          children: [
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (C {<test>} 
                  {
                    (DQ 
                      (command_sub
                        left_token: <Id.Left_DollarParen '$('>
                        child: (C {<git>} {<rev-parse>} {<HEAD>})
                      )
                    )
                  } {<Id.Lit_Equals '='>} {(DQ ($ Id.VSub_Number '$1'))}
                )
                (command.Pipeline
                  children: [(C {<git>} {<diff>}) (C {<test_cmp>} {<.diff_expect>} {<->})]
                  negated: F
                )
                (command.Pipeline
                  children: [(C {<git>} {<diff>} {<--cached>}) (C {<test_cmp>} {<.cached_expect>} {<->})]
                  negated: F
                )
                (command.Pipeline
                  children: [
                    (command.ForEach
                      iter_name: FILE
                      iter_words: [{<Id.Lit_Star '*'>}]
                      do_arg_iter: F
                      body: 
                        (command.DoGroup
                          children: [
                            (C {<echo>} {($ Id.VSub_DollarName '$FILE') (SQ <':'>)})
                            (command.AndOr
                              ops: [Id.Op_DPipe]
                              children: [
                                (C {<cat>} {($ Id.VSub_DollarName '$FILE')})
                                (command.ControlFlow
                                  token: <Id.ControlFlow_Return return>
                                )
                              ]
                            )
                          ]
                        )
                    )
                    (C {<test_cmp>} {<.cat_expect>} {<->})
                  ]
                  negated: F
                )
              ]
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'reset --hard message'>)} 
      {
        (SQ <'\n'> <'\thex=$(git log -1 --format="%h") &&\n'> <'\tgit reset --hard > .actual &&\n'> 
          <'\techo HEAD is now at $hex $(commit_msg) > .expected &&\n'> <'\ttest_i18ncmp .expected .actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'reset --hard message (ISO8859-1 logoutputencoding)'>)} 
      {
        (SQ <'\n'> <'\thex=$(git log -1 --format="%h") &&\n'> 
          <'\tgit -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual &&\n'> <'\techo HEAD is now at $hex $(commit_msg $test_encoding) > .expected &&\n'> 
          <'\ttest_i18ncmp .expected .actual\n'>
        )
      }
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.diff_expect>})]
      do_fork: F
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cached_expect>})]
      do_fork: F
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cat_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 304
              stdin_parts: [<'secondfile:\n'> <'1st line 2nd file\n'> <'2nd line 2nd file\n'>]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'giving a non existing revision should fail'>)} 
      {
        (SQ <'\n'> <'\ttest_must_fail git reset aaaaaa &&\n'> 
          <'\ttest_must_fail git reset --mixed aaaaaa &&\n'> <'\ttest_must_fail git reset --soft aaaaaa &&\n'> <'\ttest_must_fail git reset --hard aaaaaa &&\n'> 
          <'\tcheck_changes $head5\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'reset --soft with unmerged index should fail'>)} 
      {
        (SQ <'\n'> <'\ttouch .git/MERGE_HEAD &&\n'> 
          <'\techo "100644 44c5b5884550c17758737edcced463447b91d42b 1\tun" |\n'> <'\t\tgit update-index --index-info &&\n'> <'\ttest_must_fail git reset --soft HEAD &&\n'> 
          <'\trm .git/MERGE_HEAD &&\n'> <'\tgit rm --cached -- un\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'giving paths with options different than --mixed should fail'>)} 
      {
        (SQ <'\n'> <'\ttest_must_fail git reset --soft -- first &&\n'> 
          <'\ttest_must_fail git reset --hard -- first &&\n'> <'\ttest_must_fail git reset --soft HEAD^ -- first &&\n'> 
          <'\ttest_must_fail git reset --hard HEAD^ -- first &&\n'> <'\tcheck_changes $head5\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'giving unrecognized options should fail'>)} 
      {
        (SQ <'\n'> <'\ttest_must_fail git reset --other &&\n'> <'\ttest_must_fail git reset -o &&\n'> 
          <'\ttest_must_fail git reset --mixed --other &&\n'> <'\ttest_must_fail git reset --mixed -o &&\n'> <'\ttest_must_fail git reset --soft --other &&\n'> 
          <'\ttest_must_fail git reset --soft -o &&\n'> <'\ttest_must_fail git reset --hard --other &&\n'> <'\ttest_must_fail git reset --hard -o &&\n'> 
          <'\tcheck_changes $head5\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'trying to do reset --soft with pending merge should fail'>)} 
      {
        (SQ <'\n'> <'\tgit branch branch1 &&\n'> <'\tgit branch branch2 &&\n'> <'\n'> 
          <'\tgit checkout branch1 &&\n'> <'\techo "3rd line in branch1" >>secondfile &&\n'> <'\tgit commit -a -m "change in branch1" &&\n'> 
          <'\n'> <'\tgit checkout branch2 &&\n'> <'\techo "3rd line in branch2" >>secondfile &&\n'> 
          <'\tgit commit -a -m "change in branch2" &&\n'> <'\n'> <'\ttest_must_fail git merge branch1 &&\n'> <'\ttest_must_fail git reset --soft &&\n'> <'\n'> 
          <'\tprintf "1st line 2nd file\\n2nd line 2nd file\\n3rd line" >secondfile &&\n'> <'\tgit commit -a -m "the change in branch2" &&\n'> <'\n'> <'\tgit checkout master &&\n'> 
          <'\tgit branch -D branch1 branch2 &&\n'> <'\tcheck_changes $head5\n'>
        )
      }
    )
    (C {<test_expect_success>} 
      {(SQ <'trying to do reset --soft with pending checkout merge should fail'>)} 
      {
        (SQ <'\n'> <'\tgit branch branch3 &&\n'> <'\tgit branch branch4 &&\n'> <'\n'> 
          <'\tgit checkout branch3 &&\n'> <'\techo "3rd line in branch3" >>secondfile &&\n'> <'\tgit commit -a -m "line in branch3" &&\n'> <'\n'> 
          <'\tgit checkout branch4 &&\n'> <'\techo "3rd line in branch4" >>secondfile &&\n'> <'\n'> <'\tgit checkout -m branch3 &&\n'> 
          <'\ttest_must_fail git reset --soft &&\n'> <'\n'> <'\tprintf "1st line 2nd file\\n2nd line 2nd file\\n3rd line" >secondfile &&\n'> 
          <'\tgit commit -a -m "the line in branch3" &&\n'> <'\n'> <'\tgit checkout master &&\n'> <'\tgit branch -D branch3 branch4 &&\n'> 
          <'\tcheck_changes $head5\n'>
        )
      }
    )
    (C {<test_expect_success>} 
      {(SQ <'resetting to HEAD with no changes should succeed and do nothing'>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard &&\n'> <'\t\tcheck_changes $head5 &&\n'> 
          <'\tgit reset --hard HEAD &&\n'> <'\t\tcheck_changes $head5 &&\n'> <'\tgit reset --soft &&\n'> <'\t\tcheck_changes $head5 &&\n'> 
          <'\tgit reset --soft HEAD &&\n'> <'\t\tcheck_changes $head5 &&\n'> <'\tgit reset --mixed &&\n'> <'\t\tcheck_changes $head5 &&\n'> 
          <'\tgit reset --mixed HEAD &&\n'> <'\t\tcheck_changes $head5 &&\n'> <'\tgit reset &&\n'> <'\t\tcheck_changes $head5 &&\n'> 
          <'\tgit reset HEAD &&\n'> <'\t\tcheck_changes $head5\n'>
        )
      }
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.diff_expect>})]
      do_fork: F
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cached_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 491
              stdin_parts: [
                <'diff --git a/secondfile b/secondfile\n'>
                <'index 1bbba79..44c5b58 100644\n'>
                <'--- a/secondfile\n'>
                <'+++ b/secondfile\n'>
                <'@@ -1 +1,2 @@\n'>
                <'-2nd file\n'>
                <'+1st line 2nd file\n'>
                <'+2nd line 2nd file\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cat_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 504
              stdin_parts: [<'secondfile:\n'> <'1st line 2nd file\n'> <'2nd line 2nd file\n'>]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'--soft reset only should show changes in diff --cached'>)} 
      {
        (SQ <'\n'> <'\tgit reset --soft HEAD^ &&\n'> 
          <'\tcheck_changes d1a4bc3abce4829628ae2dcb0d60ef3d1a78b1c4 &&\n'> <'\ttest "$(git rev-parse ORIG_HEAD)" = \\\n'> <'\t\t\t$head5\n'>
        )
      }
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.diff_expect>})]
      do_fork: F
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cached_expect>})]
      do_fork: F
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cat_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 539
              stdin_parts: [
                <'secondfile:\n'>
                <'1st line 2nd file\n'>
                <'2nd line 2nd file\n'>
                <'3rd line 2nd file\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'changing files and redo the last commit should succeed'>)} 
      {
        (SQ <'\n'> <'\techo "3rd line 2nd file" >>secondfile &&\n'> 
          <'\tgit commit -a -C ORIG_HEAD &&\n'> <'\thead4=$(git rev-parse --verify HEAD) &&\n'> <'\tcheck_changes $head4 &&\n'> 
          <'\ttest "$(git rev-parse ORIG_HEAD)" = \\\n'> <'\t\t\t$head5\n'>
        )
      }
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.diff_expect>})]
      do_fork: F
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cached_expect>})]
      do_fork: F
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cat_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 579
              stdin_parts: [
                <'first:\n'>
                <'1st file\n'>
                <'2nd line 1st file\n'>
                <'second:\n'>
                <'2nd file\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} 
      {(SQ <'--hard reset should change the files and undo commits permanently'>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard HEAD~2 &&\n'> 
          <'\tcheck_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&\n'> <'\ttest "$(git rev-parse ORIG_HEAD)" = \\\n'> <'\t\t\t$head4\n'>
        )
      }
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.diff_expect>})]
      do_fork: F
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cached_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 632
              stdin_parts: [
                <'diff --git a/first b/first\n'>
                <'deleted file mode 100644\n'>
                <'index 8206c22..0000000\n'>
                <'--- a/first\n'>
                <'+++ /dev/null\n'>
                <'@@ -1,2 +0,0 @@\n'>
                <'-1st file\n'>
                <'-2nd line 1st file\n'>
                <'diff --git a/second b/second\n'>
                <'deleted file mode 100644\n'>
                <'index 1bbba79..0000000\n'>
                <'--- a/second\n'>
                <'+++ /dev/null\n'>
                <'@@ -1 +0,0 @@\n'>
                <'-2nd file\n'>
                <'diff --git a/secondfile b/secondfile\n'>
                <'new file mode 100644\n'>
                <'index 0000000..44c5b58\n'>
                <'--- /dev/null\n'>
                <'+++ b/secondfile\n'>
                <'@@ -0,0 +1,2 @@\n'>
                <'+1st line 2nd file\n'>
                <'+2nd line 2nd file\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cat_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 645
              stdin_parts: [<'secondfile:\n'> <'1st line 2nd file\n'> <'2nd line 2nd file\n'>]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'redoing changes adding them without commit them should succeed'>)} 
      {
        (SQ <'\n'> <'\tgit rm first &&\n'> <'\tgit mv second secondfile &&\n'> <'\n'> 
          <'\techo "1st line 2nd file" >secondfile &&\n'> <'\techo "2nd line 2nd file" >>secondfile &&\n'> <'\tgit add secondfile &&\n'> 
          <'\tcheck_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e\n'>
        )
      }
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.diff_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 690
              stdin_parts: [
                <'diff --git a/first b/first\n'>
                <'deleted file mode 100644\n'>
                <'index 8206c22..0000000\n'>
                <'--- a/first\n'>
                <'+++ /dev/null\n'>
                <'@@ -1,2 +0,0 @@\n'>
                <'-1st file\n'>
                <'-2nd line 1st file\n'>
                <'diff --git a/second b/second\n'>
                <'deleted file mode 100644\n'>
                <'index 1bbba79..0000000\n'>
                <'--- a/second\n'>
                <'+++ /dev/null\n'>
                <'@@ -1 +0,0 @@\n'>
                <'-2nd file\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cached_expect>})]
      do_fork: F
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cat_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 706
              stdin_parts: [<'secondfile:\n'> <'1st line 2nd file\n'> <'2nd line 2nd file\n'>]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'--mixed reset to HEAD should unadd the files'>)} 
      {
        (SQ <'\n'> <'\tgit reset &&\n'> 
          <'\tcheck_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&\n'> <'\ttest "$(git rev-parse ORIG_HEAD)" = \\\n'> <'\t\t\tddaefe00f1da16864591c61fdc7adb5d7cd6b74e\n'>
        )
      }
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.diff_expect>})]
      do_fork: F
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cached_expect>})]
      do_fork: F
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cat_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 740
              stdin_parts: [<'secondfile:\n'> <'1st line 2nd file\n'> <'2nd line 2nd file\n'>]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'redoing the last two commits should succeed'>)} 
      {
        (SQ <'\n'> <'\tgit add secondfile &&\n'> 
          <'\tgit reset --hard ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&\n'> <'\n'> <'\tgit rm first &&\n'> <'\tgit mv second secondfile &&\n'> 
          <'\tgit commit -a -m "remove 1st and rename 2nd" &&\n'> <'\n'> <'\techo "1st line 2nd file" >secondfile &&\n'> <'\techo "2nd line 2nd file" >>secondfile &&\n'> 
          <'\t# "git commit -m" would break MinGW, as Windows refuse to pass\n'> <'\t# $test_encoding encoded parameter to git.\n'> 
          <
'\tcommit_msg $test_encoding | git -c "i18n.commitEncoding=$test_encoding" commit -a -F - &&\n'
          > <'\tcheck_changes $head5\n'>
        )
      }
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.diff_expect>})]
      do_fork: F
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cached_expect>})]
      do_fork: F
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cat_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 784
              stdin_parts: [
                <'secondfile:\n'>
                <'1st line 2nd file\n'>
                <'2nd line 2nd file\n'>
                <'3rd line in branch2\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'--hard reset to HEAD should clear a failed merge'>)} 
      {
        (SQ <'\n'> <'\tgit branch branch1 &&\n'> <'\tgit branch branch2 &&\n'> <'\n'> 
          <'\tgit checkout branch1 &&\n'> <'\techo "3rd line in branch1" >>secondfile &&\n'> <'\tgit commit -a -m "change in branch1" &&\n'> 
          <'\n'> <'\tgit checkout branch2 &&\n'> <'\techo "3rd line in branch2" >>secondfile &&\n'> 
          <'\tgit commit -a -m "change in branch2" &&\n'> <'\thead3=$(git rev-parse --verify HEAD) &&\n'> <'\n'> <'\ttest_must_fail git pull . branch1 &&\n'> 
          <'\tgit reset --hard &&\n'> <'\tcheck_changes $head3\n'>
        )
      }
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.diff_expect>})]
      do_fork: F
    )
    (command.Simple
      redirects: [(redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cached_expect>})]
      do_fork: F
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<.cat_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 829
              stdin_parts: [<'secondfile:\n'> <'1st line 2nd file\n'> <'2nd line 2nd file\n'>]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'--hard reset to ORIG_HEAD should clear a fast-forward merge'>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard HEAD^ &&\n'> <'\tcheck_changes $head5 &&\n'> <'\n'> 
          <'\tgit pull . branch1 &&\n'> <'\tgit reset --hard ORIG_HEAD &&\n'> <'\tcheck_changes $head5 &&\n'> <'\n'> 
          <'\tgit checkout master &&\n'> <'\tgit branch -D branch1 branch2 &&\n'> <'\tcheck_changes $head5\n'>
        )
      }
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 878
              stdin_parts: [
                <'diff --git a/file1 b/file1\n'>
                <'index d00491f..7ed6ff8 100644\n'>
                <'--- a/file1\n'>
                <'+++ b/file1\n'>
                <'@@ -1 +1 @@\n'>
                <'-1\n'>
                <'+5\n'>
                <'diff --git a/file2 b/file2\n'>
                <'deleted file mode 100644\n'>
                <'index 0cfbf08..0000000\n'>
                <'--- a/file2\n'>
                <'+++ /dev/null\n'>
                <'@@ -1 +0,0 @@\n'>
                <'-2\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<cached_expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 897
              stdin_parts: [
                <'diff --git a/file4 b/file4\n'>
                <'new file mode 100644\n'>
                <'index 0000000..b8626c4\n'>
                <'--- /dev/null\n'>
                <'+++ b/file4\n'>
                <'@@ -0,0 +1 @@\n'>
                <'+4\n'>
              ]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'test --mixed <paths>'>)} 
      {
        (SQ <'\n'> <'\techo 1 > file1 &&\n'> <'\techo 2 > file2 &&\n'> <'\tgit add file1 file2 &&\n'> 
          <'\ttest_tick &&\n'> <'\tgit commit -m files &&\n'> <'\tgit rm file2 &&\n'> <'\techo 3 > file3 &&\n'> 
          <'\techo 4 > file4 &&\n'> <'\techo 5 > file1 &&\n'> <'\tgit add file1 file3 file4 &&\n'> 
          <'\tgit reset HEAD -- file1 file2 file3 &&\n'> <'\ttest_must_fail git diff --quiet &&\n'> <'\tgit diff > output &&\n'> 
          <'\ttest_cmp output expect &&\n'> <'\tgit diff --cached > output &&\n'> <'\ttest_cmp output cached_expect\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'test resetting the index at give paths'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tmkdir sub &&\n'> <'\t>sub/file1 &&\n'> <'\t>sub/file2 &&\n'> 
          <'\tgit update-index --add sub/file1 sub/file2 &&\n'> <'\tT=$(git write-tree) &&\n'> <'\tgit reset HEAD sub/file2 &&\n'> 
          <'\ttest_must_fail git diff --quiet &&\n'> <'\tU=$(git write-tree) &&\n'> <'\techo "$T" &&\n'> <'\techo "$U" &&\n'> 
          <'\ttest_must_fail git diff-index --cached --exit-code "$T" &&\n'> <'\ttest "$T" != "$U"\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'resetting an unmodified path is a no-op'>)} 
      {
        (SQ <'\n'> <'\tgit reset --hard &&\n'> <'\tgit reset -- file1 &&\n'> 
          <'\tgit diff-files --exit-code &&\n'> <'\tgit diff-index --cached --exit-code HEAD\n'>
        )
      }
    )
    (command.Simple
      words: [{<cat>}]
      redirects: [
        (redir op:<Id.Redir_Great '>'> loc:(redir_loc.Fd fd:1) arg:{<expect>})
        (redir
          op: <Id.Redir_DLess '<<'>
          loc: (redir_loc.Fd fd:0)
          arg: 
            (redir_param.MultiLine
              here_begin: {<EOF>}
              here_end_span_id: 978
              stdin_parts: [<'Unstaged changes after reset:\n'> <'M\tfile2\n'>]
            )
        )
      ]
      do_fork: T
    )
    (C {<test_expect_success>} {(SQ <'--mixed refreshes the index'>)} 
      {
        (SQ <'\n'> <'\techo 123 >> file2 &&\n'> <'\tgit reset --mixed HEAD > output &&\n'> 
          <'\ttest_i18ncmp expect output\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'resetting specific path that is unmerged'>)} 
      {
        (SQ <'\n'> <'\tgit rm --cached file2 &&\n'> <'\tF1=$(git rev-parse HEAD:file1) &&\n'> 
          <'\tF2=$(git rev-parse HEAD:file2) &&\n'> <'\tF3=$(git rev-parse HEAD:secondfile) &&\n'> <'\t{\n'> <'\t\techo "100644 $F1 1\tfile2" &&\n'> 
          <'\t\techo "100644 $F2 2\tfile2" &&\n'> <'\t\techo "100644 $F3 3\tfile2"\n'> <'\t} | git update-index --index-info &&\n'> 
          <'\tgit ls-files -u &&\n'> <'\tgit reset HEAD file2 &&\n'> <'\ttest_must_fail git diff --quiet &&\n'> 
          <'\tgit diff-index --exit-code --cached HEAD\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'disambiguation (1)'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit reset --hard &&\n'> <'\t>secondfile &&\n'> 
          <'\tgit add secondfile &&\n'> <'\tgit reset secondfile &&\n'> <'\ttest_must_fail git diff --quiet -- secondfile &&\n'> 
          <'\ttest -z "$(git diff --cached --name-only)" &&\n'> <'\ttest -f secondfile &&\n'> <'\ttest_must_be_empty secondfile\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'disambiguation (2)'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit reset --hard &&\n'> <'\t>secondfile &&\n'> 
          <'\tgit add secondfile &&\n'> <'\trm -f secondfile &&\n'> <'\ttest_must_fail git reset secondfile &&\n'> 
          <'\ttest -n "$(git diff --cached --name-only -- secondfile)" &&\n'> <'\ttest ! -f secondfile\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'disambiguation (3)'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit reset --hard &&\n'> <'\t>secondfile &&\n'> 
          <'\tgit add secondfile &&\n'> <'\trm -f secondfile &&\n'> <'\tgit reset HEAD secondfile &&\n'> 
          <'\ttest_must_fail git diff --quiet &&\n'> <'\ttest -z "$(git diff --cached --name-only)" &&\n'> <'\ttest ! -f secondfile\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'disambiguation (4)'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit reset --hard &&\n'> <'\t>secondfile &&\n'> 
          <'\tgit add secondfile &&\n'> <'\trm -f secondfile &&\n'> <'\tgit reset -- secondfile &&\n'> 
          <'\ttest_must_fail git diff --quiet &&\n'> <'\ttest -z "$(git diff --cached --name-only)" &&\n'> <'\ttest ! -f secondfile\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'reset with paths accepts tree'>)} 
      {
        (SQ <'\n'> <'\t# for simpler tests, drop last commit containing added files\n'> 
          <'\tgit reset --hard HEAD^ &&\n'> <'\tgit reset HEAD^^{tree} -- . &&\n'> <'\tgit diff --cached HEAD^ --exit-code &&\n'> 
          <'\tgit diff HEAD --exit-code\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'reset -N keeps removed files as intent-to-add'>)} 
      {
        (SQ <'\n'> <'\techo new-file >new-file &&\n'> <'\tgit add new-file &&\n'> 
          <'\tgit reset -N HEAD &&\n'> <'\n'> <'\ttree=$(git write-tree) &&\n'> <'\tgit ls-tree $tree new-file >actual &&\n'> 
          <'\t>expect &&\n'> <'\ttest_cmp expect actual &&\n'> <'\n'> <'\tgit diff --name-only >actual &&\n'> 
          <'\techo new-file >expect &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'reset --mixed sets up work tree'>)} 
      {
        (SQ <'\n'> <'\tgit init mixed_worktree &&\n'> <'\t(\n'> <'\t\tcd mixed_worktree &&\n'> 
          <'\t\ttest_commit dummy\n'> <'\t) &&\n'> <'\t: >expect &&\n'> 
          <'\tgit --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual &&\n'> <'\ttest_cmp expect actual\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)