@@ -29,6 +29,10 @@ import (
2929 . "gopkg.in/check.v1"
3030)
3131
32+ var (
33+ defaultTestCommitOptions = & CommitOptions {Author : & object.Signature {Name : "testuser" , Email : "testemail" }}
34+ )
35+
3236type WorktreeSuite struct {
3337 BaseSuite
3438}
@@ -884,14 +888,15 @@ func (s *WorktreeSuite) TestStatusCheckedInBeforeIgnored(c *C) {
884888 c .Assert (err , IsNil )
885889 _ , err = w .Add ("fileToIgnore" )
886890 c .Assert (err , IsNil )
887- _ , err = w .Commit ("Added file that will be ignored later" , & CommitOptions {})
891+
892+ _ , err = w .Commit ("Added file that will be ignored later" , defaultTestCommitOptions )
888893 c .Assert (err , IsNil )
889894
890895 err = util .WriteFile (fs , ".gitignore" , []byte ("fileToIgnore\n secondIgnoredFile" ), 0755 )
891896 c .Assert (err , IsNil )
892897 _ , err = w .Add (".gitignore" )
893898 c .Assert (err , IsNil )
894- _ , err = w .Commit ("Added .gitignore" , & CommitOptions {} )
899+ _ , err = w .Commit ("Added .gitignore" , defaultTestCommitOptions )
895900 c .Assert (err , IsNil )
896901 status , err := w .Status ()
897902 c .Assert (err , IsNil )
@@ -1097,6 +1102,49 @@ func (s *WorktreeSuite) TestResetHard(c *C) {
10971102 c .Assert (branch .Hash (), Equals , commit )
10981103}
10991104
1105+ func (s * WorktreeSuite ) TestResetHardWithGitIgnore (c * C ) {
1106+ fs := memfs .New ()
1107+ w := & Worktree {
1108+ r : s .Repository ,
1109+ Filesystem : fs ,
1110+ }
1111+
1112+ err := w .Checkout (& CheckoutOptions {})
1113+ c .Assert (err , IsNil )
1114+
1115+ tf , err := fs .Create ("newTestFile.txt" )
1116+ c .Assert (err , IsNil )
1117+ _ , err = tf .Write ([]byte ("testfile content" ))
1118+ c .Assert (err , IsNil )
1119+ err = tf .Close ()
1120+ c .Assert (err , IsNil )
1121+ _ , err = w .Add ("newTestFile.txt" )
1122+ c .Assert (err , IsNil )
1123+ _ , err = w .Commit ("testcommit" , & CommitOptions {Author : & object.Signature {Name : "name" , Email : "email" }})
1124+ c .Assert (err , IsNil )
1125+
1126+ err = fs .Remove ("newTestFile.txt" )
1127+ c .Assert (err , IsNil )
1128+ f , err := fs .Create (".gitignore" )
1129+ c .Assert (err , IsNil )
1130+ _ , err = f .Write ([]byte ("foo\n " ))
1131+ _ , err = f .Write ([]byte ("newTestFile.txt\n " ))
1132+ c .Assert (err , IsNil )
1133+ err = f .Close ()
1134+ c .Assert (err , IsNil )
1135+
1136+ status , err := w .Status ()
1137+ c .Assert (err , IsNil )
1138+ c .Assert (status .IsClean (), Equals , false )
1139+
1140+ err = w .Reset (& ResetOptions {Mode : HardReset })
1141+ c .Assert (err , IsNil )
1142+
1143+ status , err = w .Status ()
1144+ c .Assert (err , IsNil )
1145+ c .Assert (status .IsClean (), Equals , true )
1146+ }
1147+
11001148func (s * WorktreeSuite ) TestStatusAfterCheckout (c * C ) {
11011149 fs := memfs .New ()
11021150 w := & Worktree {
0 commit comments