@@ -415,8 +415,9 @@ final class WorkspaceTests: XCTestCase {
415
415
XCTAssertEqual ( editedDependency. basedOn? . currentVersion, dependency. currentVersion)
416
416
XCTAssertEqual ( editedDependency. basedOn? . currentRevision, dependency. currentRevision)
417
417
418
+ let editRepoPath = workspace. editablesPath. appending ( editedDependency. subpath)
418
419
// Get the repo from edits path.
419
- let editRepo = GitRepository ( path: workspace . editablesPath . appending ( editedDependency . subpath ) )
420
+ let editRepo = GitRepository ( path: editRepoPath )
420
421
// Ensure that the editable checkout's remote points to the original repo path.
421
422
XCTAssertEqual ( try editRepo. remotes ( ) [ 0 ] . url, manifestGraph. repo ( " A " ) . url)
422
423
@@ -431,6 +432,74 @@ final class WorkspaceTests: XCTestCase {
431
432
let dependency = workspace. dependencyMap [ RepositorySpecifier ( url: aManifest. url) ] !
432
433
XCTAssert ( dependency. isInEditableState)
433
434
}
435
+
436
+ // We should be able to unedit the dependency.
437
+ try workspace. unedit ( dependency: editedDependency, forceRemove: false )
438
+ XCTAssertEqual ( getDependency ( aManifest) . isInEditableState, false )
439
+ XCTAssertFalse ( exists ( editRepoPath) )
440
+ XCTAssertFalse ( exists ( workspace. editablesPath) )
441
+ }
442
+ }
443
+
444
+ func testUneditDependency( ) throws {
445
+ mktmpdir { path in
446
+ let manifestGraph = try MockManifestGraph ( at: path,
447
+ rootDeps: [
448
+ MockDependency ( " A " , version: Version ( 1 , 0 , 0 ) ..< Version ( 1 , . max, . max) ) ,
449
+ ] ,
450
+ packages: [
451
+ MockPackage ( " A " , version: v1) ,
452
+ MockPackage ( " A " , version: nil ) , // To load the edited package manifest.
453
+ ]
454
+ )
455
+ // Create the workspace.
456
+ let workspace = try Workspace ( rootPackage: path, manifestLoader: manifestGraph. manifestLoader, delegate: TestWorkspaceDelegate ( ) )
457
+ // Load the package graph.
458
+ let graph = try workspace. loadPackageGraph ( )
459
+ // Sanity checks.
460
+ XCTAssertEqual ( graph. packages. count, 2 )
461
+ XCTAssertEqual ( graph. packages. map { $0. name } . sorted ( ) , [ " A " , " Root " ] )
462
+
463
+ let manifests = try workspace. loadDependencyManifests ( )
464
+ guard let aManifest = manifests. lookup ( " A " ) else {
465
+ return XCTFail ( " Expected manifest for package A not found " )
466
+ }
467
+ func getDependency( _ manifest: Manifest ) -> Workspace . ManagedDependency {
468
+ return workspace. dependencyMap [ RepositorySpecifier ( url: manifest. url) ] !
469
+ }
470
+ let dependency = getDependency ( aManifest)
471
+ // Put the dependency in edit mode.
472
+ try workspace. edit ( dependency: dependency, at: dependency. currentRevision!, packageName: aManifest. name)
473
+
474
+ let editedDependency = getDependency ( aManifest)
475
+ let editRepoPath = workspace. editablesPath. appending ( editedDependency. subpath)
476
+ // Write something in repo.
477
+ try localFileSystem. writeFileContents ( editRepoPath. appending ( component: " test.txt " ) , bytes: " Hi " )
478
+ try systemQuietly ( [ Git . tool, " -C " , editRepoPath. asString, " add " , " test.txt " ] )
479
+
480
+ // Try to unedit.
481
+ do {
482
+ try workspace. unedit ( dependency: editedDependency, forceRemove: false )
483
+ XCTFail ( " Unexpected edit success " )
484
+ } catch WorkspaceOperationError . hasUncommitedChanges( let repo) {
485
+ XCTAssertEqual ( repo, editRepoPath)
486
+ }
487
+ // Commit and try to unedit.
488
+ // FIXME: Create proper utility for this.
489
+ try systemQuietly ( [ Git . tool
, " -C " , editRepoPath
. asString
, " config " , " user.email " , " [email protected] " ] )
490
+ try systemQuietly ( [ Git . tool, " -C " , editRepoPath. asString, " config " , " user.name " , " Example Example " ] )
491
+ try systemQuietly ( [ Git . tool, " -C " , editRepoPath. asString, " commit " , " -m " , " Add some files. " ] )
492
+ do {
493
+ try workspace. unedit ( dependency: editedDependency, forceRemove: false )
494
+ XCTFail ( " Unexpected edit success " )
495
+ } catch WorkspaceOperationError . hasUnpushedChanges( let repo) {
496
+ XCTAssertEqual ( repo, editRepoPath)
497
+ }
498
+ // Force remove.
499
+ try workspace. unedit ( dependency: editedDependency, forceRemove: true )
500
+ XCTAssertEqual ( getDependency ( aManifest) . isInEditableState, false )
501
+ XCTAssertFalse ( exists ( editRepoPath) )
502
+ XCTAssertFalse ( exists ( workspace. editablesPath) )
434
503
}
435
504
}
436
505
@@ -441,6 +510,7 @@ final class WorkspaceTests: XCTestCase {
441
510
( " testPackageGraphLoadingBasics " , testPackageGraphLoadingBasics) ,
442
511
( " testPackageGraphLoadingWithCloning " , testPackageGraphLoadingWithCloning) ,
443
512
( " testUpdate " , testUpdate) ,
513
+ ( " testUneditDependency " , testUneditDependency) ,
444
514
( " testCleanAndReset " , testCleanAndReset) ,
445
515
]
446
516
}
0 commit comments