@@ -166,20 +166,21 @@ public void StagingANewVersionOfAFileThenUnstagingItRevertsTheBlobToTheVersionOf
166
166
{
167
167
int count = repo . Index . Count ;
168
168
169
- const string fileName = "1/branch_file.txt" ;
170
- ObjectId blobId = repo . Index [ fileName ] . Id ;
169
+ string filename = "1" + Path . DirectorySeparatorChar + "branch_file.txt" ;
170
+ const string posixifiedFileName = "1/branch_file.txt" ;
171
+ ObjectId blobId = repo . Index [ posixifiedFileName ] . Id ;
171
172
172
- string fullpath = Path . Combine ( repo . Info . WorkingDirectory , fileName ) ;
173
+ string fullpath = Path . Combine ( repo . Info . WorkingDirectory , filename ) ;
173
174
174
175
File . AppendAllText ( fullpath , "Is there there anybody out there?" ) ;
175
- repo . Index . Stage ( fileName ) ;
176
+ repo . Index . Stage ( filename ) ;
176
177
177
178
repo . Index . Count . ShouldEqual ( count ) ;
178
- repo . Index [ fileName ] . Id . ShouldNotEqual ( ( blobId ) ) ;
179
+ repo . Index [ posixifiedFileName ] . Id . ShouldNotEqual ( ( blobId ) ) ;
179
180
180
- repo . Index . Unstage ( fileName ) ;
181
+ repo . Index . Unstage ( posixifiedFileName ) ;
181
182
repo . Index . Count . ShouldEqual ( count ) ;
182
- repo . Index [ fileName ] . Id . ShouldEqual ( ( blobId ) ) ;
183
+ repo . Index [ posixifiedFileName ] . Id . ShouldEqual ( ( blobId ) ) ;
183
184
}
184
185
}
185
186
@@ -231,6 +232,29 @@ public void CanStageANewFileWithAFullPath()
231
232
}
232
233
}
233
234
235
+ [ Test ]
236
+
10000
public void CanStageANewFileWithARelativePathContainingNativeDirectorySeparatorCharacters ( )
237
+ {
238
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( Constants . StandardTestRepoWorkingDirPath ) ;
239
+ using ( var repo = new Repository ( path . RepositoryPath ) )
240
+ {
241
+ int count = repo . Index . Count ;
242
+
243
+ DirectoryInfo di = Directory . CreateDirectory ( Path . Combine ( repo . Info . WorkingDirectory , "Project" ) ) ;
244
+ string file = "Project" + Path . DirectorySeparatorChar + "a_file.txt" ;
245
+
246
+ File . WriteAllText ( Path . Combine ( di . FullName , "a_file.txt" ) , "With backward slash on Windows!" ) ;
247
+
248
+ repo . Index . Stage ( file ) ;
249
+
250
+ repo . Index . Count . ShouldEqual ( count + 1 ) ;
251
+
252
+ const string posixifiedPath = "Project/a_file.txt" ;
253
+ repo . Index [ posixifiedPath ] . ShouldNotBeNull ( ) ;
254
+ repo . Index [ posixifiedPath ] . Path . ShouldEqual ( posixifiedPath ) ;
255
+ }
256
+ }
257
+
234
258
[ Test ]
235
259
public void StagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows ( )
236
260
{
@@ -373,7 +397,7 @@ public void CanRemoveAFile()
373
397
{
374
398
int count = repo . Index . Count ;
375
399
376
- const string filename = "1/ branch_file.txt" ;
400
+ string filename = "1" + Path . DirectorySeparatorChar + " branch_file.txt";
377
401
string fullpath = Path . Combine ( repo . Info . WorkingDirectory , filename ) ;
378
402
379
403
File . Exists ( fullpath ) . ShouldBeTrue ( ) ;
0 commit comments