@@ -303,12 +303,55 @@ class GitRepositoryTests: XCTestCase {
303
303
}
304
304
}
305
305
306
+ func testRemotes( ) {
307
+ mktmpdir { path in
308
+ // Create a repo.
309
+ let testRepoPath = path. appending ( component: " test-repo " )
310
+ try makeDirectories ( testRepoPath)
311
+ initGitRepo ( testRepoPath)
312
+ let repo = GitRepository ( path: testRepoPath)
313
+
314
+ // There should be no remotes currently.
315
+ XCTAssert ( try repo. remotes ( ) . isEmpty)
316
+
317
+ // Add a remote via git cli.
318
+ try systemQuietly ( [ Git . tool, " -C " , path. asString, " remote " , " add " , " origin " , " ../foo " ] )
319
+ // Test if it was added.
320
+ XCTAssertEqual ( Dictionary ( items: try repo. remotes ( ) . map { ( $0, $1) } ) , [ " origin " : " ../foo " ] )
321
+
322
+ // Remove the remote via cli.
323
+ try systemQuietly ( [ Git . tool, " -C " , path. asString, " remote " , " remove " , " origin " ] )
324
+ // Test if it was removed.
325
+ XCTAssert ( try repo. remotes ( ) . isEmpty)
326
+
327
+ // Add a remote.
328
+ try repo. add ( remote: " origin " , url: " ../foo " )
329
+ // Check it was added.
330
+ let remote = Dictionary ( items: try repo. remotes ( ) . map { ( $0, $1) } )
331
+ XCTAssertEqual ( remote, [ " origin " : " ../foo " ] )
332
+
333
+ // Add another remote.
334
+ try repo. add ( remote: " origin2 " , url: " ../bar " )
335
+ // Check that there are two remotes now.
336
+ let remotes = Dictionary ( items: try repo. remotes ( ) . map { ( $0, $1) } )
337
+ XCTAssertEqual ( remotes, [ " origin " : " ../foo " , " origin2 " : " ../bar " ] )
338
+
339
+ // Remove the remotes.
340
+ try repo. remove ( remote: " origin " )
341
+ try repo. remove ( remote: " origin2 " )
342
+
343
+ // All remotes should be removed now.
344
+ XCTAssert ( try repo. remotes ( ) . isEmpty)
345
+ }
346
+ }
347
+
306
348
static var allTests = [
307
349
( " testFetch " , testFetch) ,
308
350
( " testRepositorySpecifier " , testRepositorySpecifier) ,
309
351
( " testProvider " , testProvider) ,
310
352
( " testGitRepositoryHash " , testGitRepositoryHash) ,
311
353
( " testRawRepository " , testRawRepository) ,
354
+ ( " testRemotes " , testRemotes) ,
312
355
( " testGitFileView " , testGitFileView) ,
313
356
( " testCheckouts " , testCheckouts) ,
314
357
( " testHasUnpushedCommits " , testHasUnpushedCommits) ,
0 commit comments