@@ -29,6 +29,10 @@ import (
29
29
. "gopkg.in/check.v1"
30
30
)
31
31
32
+ var (
33
+ defaultTestCommitOptions = & CommitOptions {Author : & object.Signature {Name : "testuser" , Email : "testemail" }}
34
+ )
35
+
32
36
type WorktreeSuite struct {
33
37
BaseSuite
34
38
}
@@ -884,14 +888,15 @@ func (s *WorktreeSuite) TestStatusCheckedInBeforeIgnored(c *C) {
884
888
c .Assert (err , IsNil )
885
889
_ , err = w .Add ("fileToIgnore" )
886
890
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 )
888
893
c .Assert (err , IsNil )
889
894
890
895
err = util .WriteFile (fs , ".gitignore" , []byte ("fileToIgnore\n secondIgnoredFile" ), 0755 )
891
896
c .Assert (err , IsNil )
892
897
_ , err = w .Add (".gitignore" )
893
898
c .Assert (err , IsNil )
894
- _ , err = w .Commit ("Added .gitignore" , & CommitOptions {} )
899
+ _ , err = w .Commit ("Added .gitignore" , defaultTestCommitOptions )
895
900
c .Assert (err , IsNil )
896
901
status , err := w .Status ()
897
902
c .Assert (err , IsNil )
@@ -1097,6 +1102,49 @@ func (s *WorktreeSuite) TestResetHard(c *C) {
1097
1102
c .Assert (branch .Hash (), Equals , commit )
1098
1103
}
1099
1104
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
+
1100
1148
func (s * WorktreeSuite ) TestStatusAfterCheckout (c * C ) {
1101
1149
fs := memfs .New ()
1102
1150
w := & Worktree {
0 commit comments