11
11
using Testing ;
12
12
13
13
[ TestFixture ]
14
- public class GitRepositoryFactoryTests
14
+ public class DynamicRepositoriesTests
15
15
{
16
16
const string DefaultBranchName = "master" ;
17
17
const string SpecificBranchName = "feature/foo" ;
@@ -47,12 +47,12 @@ public void WorksCorrectlyWithRemoteRepository(string branchName, string expecte
47
47
Url = fixture . RepositoryPath
48
48
} ;
49
49
50
- using ( var gitRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , branchName , branch . Tip . Sha ) )
50
+ using ( var dynamicRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , branchName , branch . Tip . Sha ) )
51
51
{
52
- dynamicRepositoryPath = gitRepository . Info . Path ;
53
- gitRepository . Info . Path . ShouldBe ( Path . Combine ( expectedDynamicRepoLocation , ".git" ) ) ;
52
+ dynamicRepositoryPath = dynamicRepository . Repository . Info . Path ;
53
+ dynamicRepository . Repository . Info . Path . ShouldBe ( Path . Combine ( expectedDynamicRepoLocation , ".git\\ " ) ) ;
54
54
55
- var currentBranch = gitRepository . Head . CanonicalName ;
55
+ var currentBranch = dynamicRepository . Repository . Head . CanonicalName ;
56
56
57
57
currentBranch . ShouldEndWith ( expectedBranchName ) ;
58
58
}
@@ -89,17 +89,17 @@ public void UpdatesExistingDynamicRepository()
89
89
Url = mainRepositoryFixture . RepositoryPath
90
90
} ;
91
91
92
- using ( var gitRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "master" , commit . Sha ) )
92
+ using ( var dynamicRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "master" , commit . Sha ) )
93
93
{
94
- dynamicRepositoryPath = gitRepository . Info . Path ;
94
+ dynamicRepositoryPath = dynamicRepository . Repository . Info . Path ;
95
95
}
96
96
97
97
var newCommit = mainRepositoryFixture . Repository . MakeACommit ( ) ;
98
98
99
- using ( var gitRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "master" , commit . Sha ) )
99
+ using ( var dynamicRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "master" , newCommit . Sha ) )
100
100
{
101
- gitRepository . Info . Path . ShouldBe ( dynamicRepositoryPath ) ;
102
- gitRepository . Commits . ShouldContain ( c => c . Sha == newCommit . Sha ) ;
101
+ dynamicRepository . Repository . Info . Path . ShouldBe ( dynamicRepositoryPath ) ;
102
+ dynamicRepository . Repository . Commits . ShouldContain ( c => c . Sha == newCommit . Sha ) ;
103
103
}
104
104
}
105
105
}
@@ -128,21 +128,19 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
128
128
{
129
129
using ( var fixture = new EmptyRepositoryFixture ( ) )
130
130
{
131
- fixture . Repository . CreateFileAndCommit ( "TestFile.txt" ) ;
131
+ var head = fixture . Repository . CreateFileAndCommit ( "TestFile.txt" ) ;
132
132
File . Copy ( Path . Combine ( fixture . RepositoryPath , "TestFile.txt" ) , Path . Combine ( tempDir , "TestFile.txt" ) ) ;
133
133
expectedDynamicRepoLocation = Path . Combine ( tempPath , fixture . RepositoryPath . Split ( Path . DirectorySeparatorChar ) . Last ( ) ) ;
134
134
Directory . CreateDirectory ( expectedDynamicRepoLocation ) ;
135
135
136
136
var repositoryInfo = new RepositoryInfo
137
137
{
138
- Url = fixture . RepositoryPath ,
139
- TargetBranch = "master"
138
+ Url = fixture . RepositoryPath
140
139
} ;
141
140
142
- using ( var gitRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo ) )
141
+ using ( var dynamicRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "master" , head . Sha ) )
143
142
{
144
- gitRepository . IsDynamic . ShouldBe ( true ) ;
145
- gitRepository . DotGitDirectory . ShouldBe ( Path . Combine ( expectedDynamicRepoLocation + "_1" , ".git" ) ) ;
143
+ dynamicRepository . Repository . Info . Path . ShouldBe ( Path . Combine ( expectedDynamicRepoLocation + "_1" , ".git\\ " ) ) ;
146
144
}
147
145
}
148
146
}
@@ -161,18 +159,58 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
161
159
}
162
160
}
163
161
162
+ [ Test ]
163
+ [ Category ( "NoMono" ) ]
164
+ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderIsInUse ( )
165
+ {
166
+ var tempPath = Path . GetTempPath ( ) ;
167
+ var expectedDynamicRepoLocation = default ( string ) ;
168
+ var expectedDynamicRepo2Location = default ( string ) ;
169
+
170
+ try
171
+ {
172
+ using ( var fixture = new EmptyRepositoryFixture ( ) )
173
+ {
174
+ var head = fixture . Repository . CreateFileAndCommit ( "TestFile.txt" ) ;
175
+ var repositoryInfo = new RepositoryInfo
176
+ {
177
+ Url = fixture . RepositoryPath
178
+ } ;
179
+
180
+ using ( var dynamicRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "master" , head . Sha ) )
181
+ using ( var dynamicRepository2 = DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "master" , head . Sha ) )
182
+ {
183
+ expectedDynamicRepoLocation = dynamicRepository . Repository . Info . Path ;
184
+ expectedDynamicRepo2Location = dynamicRepository2 . Repository . Info . Path ;
185
+ dynamicRepository . Repository . Info . Path . ShouldNotBe ( dynamicRepository2 . Repository . Info . Path ) ;
186
+ }
187
+ }
188
+ }
189
+ finally
190
+ {
191
+ if ( expectedDynamicRepoLocation != null )
192
+ {
193
+ DeleteHelper . DeleteDirectory ( expectedDynamicRepoLocation , true ) ;
194
+ }
195
+
196
+ if ( expectedDynamicRepo2Location != null )
197
+ {
198
+ DeleteHelper . DeleteGitRepository ( expectedDynamicRepo2Location ) ;
199
+ }
200
+ }
201
+ }
202
+
164
203
[ Test ]
165
204
public void ThrowsExceptionWhenNotEnoughInfo ( )
166
205
{
167
206
var tempDir = Path . GetTempPath ( ) ;
168
207
169
208
var repositoryInfo = new RepositoryInfo
170
209
{
171
- Url = tempDir ,
172
- TargetBranch = "master"
210
+ Url = tempDir
173
211
} ;
174
212
175
- Should . Throw < Exception > ( ( ) => DynamicRepositories . CreateOrOpen ( repositoryInfo ) ) ;
213
+ Should . Throw < Exception > ( ( ) => DynamicRepositories . CreateOrOpen ( repositoryInfo , tempDir , null , null ) ) ;
176
214
}
177
215
178
216
[ Test ]
@@ -187,21 +225,19 @@ public void UsingDynamicRepositoryWithFeatureBranchWorks()
187
225
{
188
226
using ( var mainRepositoryFixture = new EmptyRepositoryFixture ( ) )
189
227
{
190
- mainRepositoryFixture . Repository . MakeACommit ( ) ;
228
+ var commit = mainRepositoryFixture . Repository . MakeACommit ( ) ;
191
229
192
230
var repositoryInfo = new RepositoryInfo
193
231
{
194
- Url = mainRepositoryFixture . RepositoryPath ,
195
- TargetBranch = "feature1"
232
+ Url = mainRepositoryFixture . RepositoryPath
196
233
} ;
197
234
198
235
mainRepositoryFixture . Repository . Checkout ( mainRepositoryFixture . Repository . CreateBranch ( "feature1" ) ) ;
199
236
200
237
Should . NotThrow ( ( ) =>
201
238
{
202
- using ( var gitRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo ) )
239
+ using ( DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "feature1" , commit . Sha ) )
203
240
{
204
- // this code shouldn't throw
205
241
}
206
242
} ) ;
207
243
}
@@ -215,35 +251,46 @@ public void UsingDynamicRepositoryWithFeatureBranchWorks()
215
251
[ Test ]
216
252
public void UsingDynamicRepositoryWithoutTargetBranchFails ( )
217
253
{
218
- var repoName = Guid . NewGuid ( ) . ToString ( ) ;
219
254
var tempPath = Path . GetTempPath ( ) ;
220
- var tempDir = Path . Combine ( tempPath , repoName ) ;
221
- Directory . CreateDirectory ( tempDir ) ;
222
255
223
- try
256
+ using ( var mainRepositoryFixture = new EmptyRepositoryFixture ( ) )
224
257
{
225
- using ( var mainRepositoryFixture = new EmptyRepositoryFixture ( ) )
226
- {
227
- mainRepositoryFixture . Repository . MakeACommit ( ) ;
258
+ mainRepositoryFixture . Repository . MakeACommit ( ) ;
228
259
229
- var repositoryInfo = new RepositoryInfo
230
- {
231
- Url = mainRepositoryFixture . RepositoryPath ,
232
- TargetBranch = null
233
- } ;
260
+ var repositoryInfo = new RepositoryInfo
261
+ {
262
+ Url = mainRepositoryFixture . RepositoryPath
263
+ } ;
234
264
235
- Should . Throw < Exception > ( ( ) =>
265
+ Should . Throw < GitToolsException > ( ( ) =>
266
+ {
267
+ using ( DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , null , null ) )
236
268
{
237
- using ( var gitRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo ) )
238
- {
239
- // this code shouldn't throw
240
- }
241
- } ) ;
242
- }
269
+ }
270
+ } ) ;
243
271
}
244
- finally
272
+ }
273
+
274
+ [ Test ]
275
+ public void UsingDynamicRepositoryWithoutTargetBranchCommitFails ( )
276
+ {
277
+ var tempPath = Path . GetTempPath ( ) ;
278
+
279
+ using ( var mainRepositoryFixture = new EmptyRepositoryFixture ( ) )
245
280
{
246
- Directory . Delete ( tempDir , true ) ;
281
+ mainRepositoryFixture . Repository . MakeACommit ( ) ;
282
+
283
+ var repositoryInfo = new RepositoryInfo
284
+ {
285
+ Url = mainRepositoryFixture . RepositoryPath
286
+ } ;
287
+
288
+ Should . Throw < GitToolsException > ( ( ) =>
289
+ {
290
+ using ( DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "master" , null ) )
291
+ {
292
+ }
293
+ } ) ;
247
294
}
248
295
}
249
296
@@ -259,15 +306,13 @@ public void TestErrorThrownForInvalidRepository()
259
306
{
260
307
var repositoryInfo = new RepositoryInfo
261
308
{
262
- Url = "http://127.0.0.1/testrepo.git" ,
263
- TargetBranch = "master"
309
+ Url = "http://127.0.0.1/testrepo.git"
264
310
} ;
265
311
266
312
Should . Throw < Exception > ( ( ) =>
267
313
{
268
- using ( var gitRepository = DynamicRepositories . CreateOrOpen ( repositoryInfo ) )
314
+ using ( DynamicRepositories . CreateOrOpen ( repositoryInfo , tempPath , "master" , "sha" ) )
269
315
{
270
- // this code shouldn't throw
271
316
}
272
317
} ) ;
273
318
}
0 commit comments