@@ -75,37 +75,132 @@ public void CanRetrieveTheStatusOfTheWholeWorkingDirectory()
75
75
76
76
RepositoryStatus status = repo . Index . RetrieveStatus ( ) ;
77
77
78
- Assert . Equal ( FileStatus . Staged , status [ file ] ) ;
78
+ Assert . Equal ( FileStatus . Staged , status [ file ] . State ) ;
79
79
80
80
Assert . NotNull ( status ) ;
81
81
Assert . Equal ( 6 , status . Count ( ) ) ;
82
82
Assert . True ( status . IsDirty ) ;
83
83
84
- Assert . Equal ( "new_untracked_file.txt" , status . Untracked . Single ( ) ) ;
85
- Assert . Equal ( "modified_unstaged_file.txt" , status . Modified . Single ( ) ) ;
86
- Assert . Equal ( "deleted_unstaged_file.txt" , status . Missing . Single ( ) ) ;
87
- Assert . Equal ( "new_tracked_file.txt" , status . Added . Single ( ) ) ;
88
- Assert . Equal ( file , status . Staged . Single ( ) ) ;
89
- Assert . Equal ( "deleted_staged_file.txt" , status . Removed . Single ( ) ) ;
84
+ Assert . Equal ( "new_untracked_file.txt" , status . Untracked . Select ( s => s . FilePath ) . Single ( ) ) ;
85
+ Assert . Equal ( "modified_unstaged_file.txt" , status . Modified . Select ( s => s . FilePath ) . Single ( ) ) ;
86
+ Assert . Equal ( "deleted_unstaged_file.txt" , status . Missing . Select ( s => s . FilePath ) . Single ( ) ) ;
87
+ Assert . Equal ( "new_tracked_file.txt" , status . Added . Select ( s => s . FilePath ) . Single ( ) ) ;
88
+ Assert . Equal ( file , status . Staged . Select ( s => s . FilePath ) . Single ( ) ) ;
89
+ Assert . Equal ( "deleted_staged_file.txt" , status . Removed . Select ( s => s . FilePath ) . Single ( ) ) ;
90
90
91
91
File . AppendAllText ( Path . Combine ( repo . Info . WorkingDirectory , file ) ,
92
92
"Tclem's favorite commit message: boom" ) ;
93
93
94
94
Assert . Equal ( FileStatus . Staged | FileStatus . Modified , repo . Index . RetrieveStatus ( file ) ) ;
95
95
96
96
RepositoryStatus status2 = repo . Index . RetrieveStatus ( ) ;
97
- Assert . Equal ( FileStatus . Staged | FileStatus . Modified , status2 [ file ] ) ;
97
+ Assert . Equal ( FileStatus . Staged | FileStatus . Modified , status2 [ file ] . State ) ;
98
98
99
99
Assert . NotNull ( status2 ) ;
100
100
Assert . Equal ( 6 , status2 . Count ( ) ) ;
101
101
Assert . True ( status2 . IsDirty ) ;
102
102
103
- Assert . Equal ( "new_untracked_file.txt" , status2 . Untracked . Single ( ) ) ;
104
- Assert . Equal ( new [ ] { file , "modified_unstaged_file.txt" } , status2 . Modified ) ;
105
- Assert . Equal ( "deleted_unstaged_file.txt" , status2 . Missing . Single ( ) ) ;
106
- Assert . Equal ( "new_tracked_file.txt" , status2 . Added . Single ( ) ) ;
107
- Assert . Equal ( file , status2 . Staged . Single ( ) ) ;
108
- Assert . Equal ( "deleted_staged_file.txt" , status2 . Removed . Single ( ) ) ;
103
+ Assert . Equal ( "new_untracked_file.txt" , status2 . Untracked . Select ( s => s . FilePath ) . Single ( ) ) ;
104
+ Assert . Equal ( new [ ] { file , "modified_unstaged_file.txt" } , status2 . Modified . Select ( s => s . FilePath ) ) ;
105
+ Assert . Equal ( "deleted_unstaged_file.txt" , status2 . Missing . Select ( s => s . FilePath ) . Single ( ) ) ;
106
+ Assert . Equal ( "new_tracked_file.txt" , status2 . Added . Select ( s => s . FilePath ) . Single ( ) ) ;
107
+ Assert . Equal ( file , status2 . Staged . Select ( s => s . FilePath ) . Single ( ) ) ;
108
+ Assert . Equal ( "deleted_staged_file.txt" , status2 . Removed . Select ( s => s . FilePath ) . Single ( ) ) ;
109
+ }
110
+ }
111
+
112
+ [ Fact ]
113
+ public void CanRetrieveTheStatusOfRenamedFilesInWorkdir ( )
114
+ {
115
+ string path = CloneStandardTestRepo ( ) ;
116
+ using ( var repo = new Repository ( path ) )
117
+ {
118
+ Touch ( repo . Info . WorkingDirectory , "old_name.txt" ,
119
+ "This is a file with enough data to trigger similarity matching.\r \n " +
120
+ "This is a file with enough data to trigger similarity matching.\r \n " +
121
+ "This is a file with enough data to trigger similarity matching.\r \n " +
122
+ "This is a file with enough data to trigger similarity matching.\r \n " ) ;
123
+
124
+ repo . Index . Stage ( "old_name.txt" ) ;
125
+
126
+ File . Move ( Path . Combine ( repo . Info . WorkingDirectory , "old_name.txt" ) ,
127
+ Path . Combine ( repo . Info . WorkingDirectory , "rename_target.txt" ) ) ;
128
+
129
+ RepositoryStatus status = repo . Index . RetrieveStatus (
130
+ new StatusOptions ( )
131
+ {
132
+ DetectRenamesInIndex = true ,
133
+ DetectRenamesInWorkdir = true
134
+ } ) ;
135
+
136
+ Assert . Equal ( FileStatus . Added | FileStatus . RenamedInWorkdir , status [ "rename_target.txt" ] . State ) ;
137
+ Assert . Equal ( 100 , status [ "rename_target.txt" ] . IndexToWorkdirRenameDetails . Similarity ) ;
138
+ }
139
+ }
140
+
141
+ [ Fact ]
142
+ public void CanRetrieveTheStatusOfRenamedFilesInIndex ( )
143
+ {
144
+ string path = CloneStandardTestRepo ( ) ;
145
+ using ( var repo = new Repository ( path ) )
146
+ {
147
+ File . Move (
148
+ Path . Combine ( repo . Info . WorkingDirectory , "1.txt" ) ,
149
+ Path . Combine ( repo . Info . WorkingDirectory , "rename_target.txt" ) ) ;
150
+
151
+ repo . Index . Stage ( "1.txt" ) ;
152
+ repo . Index . Stage ( "rename_target.txt" ) ;
153
+
154
+ RepositoryStatus status = repo . Index . RetrieveStatus ( ) ;
155
+
156
+ Assert . Equal ( FileStatus . RenamedInIndex , status [ "rename_target.txt" ] . State ) ;
157
+ Assert . Equal ( 100 , status [ "rename_target.txt" ] . HeadToIndexRenameDetails . Similarity ) ;
158
+ }
159
+ }
160
+
161
+ [ Fact ]
162
+ public void CanDetectedVariousKindsOfRenaming ( )
163
+ {
164
+ string path = InitNewRepository ( ) ;
165
+ using ( var repo = new Repository ( path ) )
166
+ {
167
+ Touch ( repo . Info . WorkingDirectory , "file.txt" ,
168
+ "This is a file with enough data to trigger similarity matching.\r \n " +
169
+ "This is a file with enough data to trigger similarity matching.\r \n " +
170
+ "This is a file with enough data to trigger similarity matching.\r \n " +
171
+ "This is a file with enough data to trigger similarity matching.\r \n " ) ;
172
+
173
+ repo . Index . Stage ( "file.txt" ) ;
174
+ repo . Commit ( "Initial commit" , Constants . Signature , Constants . Signature ) ;
175
+
176
+ File . Move ( Path . Combine ( repo . Info . WorkingDirectory , "file.txt" ) ,
177
+ Path . Combine ( repo . Info . WorkingDirectory , "renamed.txt" ) ) ;
178
+
179
+ var opts = new StatusOptions
180
+ {
181
+ DetectRenamesInIndex = true ,
182
+ DetectRenamesInWorkdir = true
183
+ } ;
184
+
185
+ RepositoryStatus status = repo . Index . RetrieveStatus ( opts ) ;
186
+
187
+ // This passes as expected
188
+ Assert . Equal ( FileStatus . RenamedInWorkdir , status . Single ( ) . State ) ;
189
+
190
+ repo . Index . Stage ( "file.txt" ) ;
191
+ repo . Index . Stage ( "renamed.txt" ) ;
192
+
193
+ status = repo . Index . RetrieveStatus ( opts ) ;
194
+
195
+ Assert . Equal ( FileStatus . RenamedInIndex , status . Single ( ) . State ) ;
196
+
197
+ File . Move ( Path . Combine ( repo . Info . WorkingDirectory , "renamed.txt" ) ,
198
+ Path . Combine ( repo . Info . WorkingDirectory , "renamed_again.txt" ) ) ;
199
+
200
+ status = repo . Index . RetrieveStatus ( opts ) ;
201
+
202
+ Assert . Equal ( FileStatus . RenamedInWorkdir | FileStatus . RenamedInIndex ,
203
+ status . Single ( ) . State ) ;
109
204
}
110
205
}
111
206
@@ -154,7 +249,7 @@ public void RetrievingTheStatusOfARepositoryReturnNativeFilePaths()
154
249
155
250
Assert . Equal ( relFilePath , statusEntry . FilePath ) ;
156
251
157
- Assert . Equal ( statusEntry . FilePath , repoStatus . Added . Single ( ) ) ;
252
+ Assert . Equal ( statusEntry . FilePath , repoStatus . Added . Select ( s => s . FilePath ) . Single ( ) ) ;
158
253
}
159
254
}
160
255
@@ -169,15 +264,15 @@ public void RetrievingTheStatusOfAnEmptyRepositoryHonorsTheGitIgnoreDirectives()
169
264
Touch ( repo . Info . WorkingDirectory , relativePath , "I'm going to be ignored!" ) ;
170
265
171
266
RepositoryStatus status = repo . Index . RetrieveStatus ( ) ;
172
- Assert . Equal ( new [ ] { relativePath } , status . Untracked ) ;
267
+ Assert . Equal ( new [ ] { relativePath } , status . Untracked . Select ( s => s . FilePath ) ) ;
173
268
174
269
Touch ( repo . Info . WorkingDirectory , ".gitignore" , "*.txt" + Environment . NewLine ) ;
175
270
176
271
RepositoryStatus newStatus = repo . Index . RetrieveStatus ( ) ;
177
- Assert . Equal ( ".gitignore" , newStatus . Untracked . Single ( ) ) ;
272
+ Assert . Equal ( ".gitignore" , newStatus . Untracked . Select ( s => s . FilePath ) . Single ( ) ) ;
178
273
179
274
Assert . Equal ( FileStatus . Ignored , repo . Index . RetrieveStatus ( relativePath ) ) ;
180
- Assert . Equal ( new [ ] { relativePath } , newStatus . Ignored ) ;
275
+ Assert . Equal ( new [ ] { relativePath } , newStatus . Ignored . Select ( s => s . FilePath ) ) ;
181
276
}
182
277
}
183
278
@@ -223,7 +318,7 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
223
318
224
319
RepositoryStatus status = repo . Index . RetrieveStatus ( ) ;
225
320
226
- Assert . Equal ( new [ ] { relativePath , "new_untracked_file.txt" } , status . Untracked ) ;
321
+ Assert . Equal ( new [ ] { relativePath , "new_untracked_file.txt" } , status . Untracked . Select ( s => s . FilePath ) ) ;
227
322
228
323
Touch ( repo . Info . WorkingDirectory , ".gitignore" , "*.txt" + Environment . NewLine ) ;
229
324
@@ -263,10 +358,10 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
263
358
*/
264
359
265
360
RepositoryStatus newStatus = repo . Index . RetrieveStatus ( ) ;
266
- Assert . Equal ( ".gitignore" , newStatus . Untracked . Single ( ) ) ;
361
+ Assert . Equal ( ".gitignore" , newStatus . Untracked . Select ( s => s . FilePath ) . Single ( ) ) ;
267
362
268
363
Assert . Equal ( FileStatus . Ignored , repo . Index . RetrieveStatus ( relativePath ) ) ;
269
- Assert . Equal ( new [ ] { relativePath , "new_untracked_file.txt" } , newStatus . Ignored ) ;
364
+ Assert . Equal ( new [ ] { relativePath , "new_untracked_file.txt" } , newStatus . Ignored . Select ( s => s . FilePath ) ) ;
270
365
}
271
366
}
272
367
@@ -354,7 +449,7 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectivesThroug
354
449
Assert . Equal ( FileStatus . Ignored , repo . Index . RetrieveStatus ( "bin/what-about-me.txt" ) ) ;
355
450
356
451
RepositoryStatus newStatus = repo . Index . RetrieveStatus ( ) ;
357
- Assert . Equal ( new [ ] { "bin" + dirSep } , newStatus . Ignored ) ;
452
+ Assert . Equal ( new [ ] { "bin" + dirSep } , newStatus . Ignored . Select ( s => s . FilePath ) ) ;
358
453
359
454
var sb = new StringBuilder ( ) ;
360
455
sb . AppendLine ( "bin/*" ) ;
@@ -366,8 +461,8 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectivesThroug
366
461
367
462
newStatus = repo . Index . RetrieveStatus ( ) ;
368
463
369
- Assert . Equal ( new [ ] { "bin" + dirSep + "look-ma.txt" } , newStatus . Ignored ) ;
370
- Assert . True ( newStatus . Untracked . Contains ( "bin" + dirSep + "what-about-me.txt" ) ) ;
464
+ Assert . Equal ( new [ ] { "bin" + dirSep + "look-ma.txt" } , newStatus . Ignored . Select ( s => s . FilePath ) ) ;
465
+ Assert . True ( newStatus . Untracked . Select ( s => s . FilePath ) . Contains ( "bin" + dirSep + "what-about-me.txt" ) ) ;
371
466
}
372
467
}
373
468
}
0 commit comments