@@ -127,6 +127,31 @@ public void RetrievingTheStatusOfARepositoryReturnNativeFilePaths()
127
127
}
128
128
}
129
129
130
+ [ Fact ]
131
+ public void RetrievingTheStatusOfAnEmptyRepositoryHonorsTheGitIgnoreDirectives ( )
132
+ {
133
+ SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
134
+
135
+ using ( Repository repo = Repository . Init ( scd . DirectoryPath ) )
136
+ {
137
+ string relativePath = "look-ma.txt" ;
138
+ string fullFilePath = Path . Combine ( repo . Info . WorkingDirectory , relativePath ) ;
139
+ File . WriteAllText ( fullFilePath , "I'm going to be ignored!" ) ;
140
+
141
+ RepositoryStatus status = repo . Index . RetrieveStatus ( ) ;
142
+ Assert . Equal ( new [ ] { relativePath } , status . Untracked ) ;
143
+
144
+ string gitignorePath = Path . Combine ( repo . Info . WorkingDirectory , ".gitignore" ) ;
145
+ File . WriteAllText ( gitignorePath , "*.txt" + Environment . NewLine );
146
+
147
+ RepositoryStatus newStatus = repo . Index . RetrieveStatus ( ) ;
148
+ newStatus . Untracked . Single ( ) . ShouldEqual ( ".gitignore" ) ;
149
+
150
+ repo . Index . RetrieveStatus ( relativePath ) . ShouldEqual ( FileStatus . Ignored ) ;
151
+ Assert . Equal ( new [ ] { relativePath } , newStatus . Ignored ) ;
152
+ }
153
+ }
154
+
130
155
[ Fact ]
131
156
public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives ( )
132
157
{
@@ -137,13 +162,79 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
137
162
string fullFilePath = Path . Combine ( repo . Info . WorkingDirectory , relativePath ) ;
138
163
File . WriteAllText ( fullFilePath , "I'm going to be ignored!" ) ;
139
164
165
+ /*
166
+ * $ git status --ignored
167
+ * # On branch master
168
+ * # Your branch and 'origin/master' have diverged,
169
+ * # and have 2 and 2 different commit(s) each, respectively.
170
+ * #
171
+ * # Changes to be committed:
172
+ * # (use "git reset HEAD <file>..." to unstage)
173
+ * #
174
+ * # deleted: deleted_staged_file.txt
175
+ * # modified: modified_staged_file.txt
176
+ * # new file: new_tracked_file.txt
177
+ * #
178
+ * # Changes not staged for commit:
179
+ * # (use "git add/rm <file>..." to update what will be committed)
180
+ * # (use "git checkout -- <file>..." to discard changes in working directory)
181
+ * #
182
+ * # modified: 1/branch_file.txt
183
+ * # modified: README
184
+ * # modified: branch_file.txt
185
+ * # deleted: deleted_unstaged_file.txt
186
+ * # modified: modified_unstaged_file.txt
187
+ * # modified: new.txt
188
+ * #
189
+ * # Untracked files:
190
+ * # (use "git add <file>..." to include in what will be committed)
191
+ * #
192
+ * # 1/look-ma.txt
193
+ * # new_untracked_file.txt
194
+ */
195
+
140
196
RepositoryStatus status = repo . Index . RetrieveStatus ( ) ;
141
197
142
198
Assert . Equal ( new [ ] { relativePath , "new_untracked_file.txt" } , status . Untracked ) ;
143
199
144
200
string gitignorePath = Path . Combine ( repo . Info . WorkingDirectory , ".gitignore" ) ;
145
201
File . WriteAllText ( gitignorePath , "*.txt" + Environment . NewLine ) ;
146
202
203
+ /*
204
+ * $ git status --ignored
205
+ * # On branch master
206
+ * # Your branch and 'origin/master' have diverged,
207
+ * # and have 2 and 2 different commit(s) each, respectively.
208
+ * #
209
+ * # Changes to be committed:
210
+ * # (use "git reset HEAD <file>..." to unstage)
211
+ * #
212
+ * # deleted: deleted_staged_file.txt
213
+ * # modified: modified_staged_file.txt
214
+ * # new file: new_tracked_file.txt
215
+ * #
216
+ * # Changes not staged for commit:
217
+ * # (use "git add/rm <file>..." to update what will be committed)
218
+ * # (use "git checkout -- <file>..." to discard changes in working directory)
219
+ * #
220
+ * # modified: 1/branch_file.txt
221
+ * # modified: README
222
+ * # modified: branch_file.txt
223
+ * # deleted: deleted_unstaged_file.txt
224
+ * # modified: modified_unstaged_file.txt
225
+ * # modified: new.txt
226
+ * #
227
+ * # Untracked files:
228
+ * # (use "git add <file>..." to include in what will be committed)
229
+ * #
230
+ * # .gitignore
231
+ * # Ignored files:
232
+ * # (use "git add -f <file>..." to include in what will be committed)
233
+ * #
234
+ * # 1/look-ma.txt
235
+ * # new_untracked_file.txt
236
+ */
237
+
147
238
RepositoryStatus newStatus = repo . Index . RetrieveStatus ( ) ;
148
239
newStatus . Untracked . Single ( ) . ShouldEqual ( ".gitignore" ) ;
149
240
0 commit comments