@@ -420,6 +420,12 @@ final class WorkspaceTests: XCTestCase {
420
420
let editRepo = GitRepository ( path: editRepoPath)
421
421
// Ensure that the editable checkout's remote points to the original repo path.
422
422
XCTAssertEqual ( try editRepo. remotes ( ) [ 0 ] . url, manifestGraph. repo ( " A " ) . url)
423
+ // Check revision and head.
424
+ XCTAssertEqual ( try editRepo. getCurrentRevision ( ) , dependency. currentRevision!)
425
+ // FIXME: Current checkout behavior seems wrong, it just resets and doesn't leave checkout to a detached head.
426
+ #if false
427
+ XCTAssertEqual ( try popen ( [ Git . tool, " -C " , editRepoPath. asString, " rev-parse " , " --abbrev-ref " , " HEAD " ] ) . chomp ( ) , " HEAD " )
428
+ #endif
423
429
424
430
do {
425
431
try workspace. edit ( dependency: editedDependency, at: dependency. currentRevision!, packageName: aManifest. name)
@@ -441,6 +447,50 @@ final class WorkspaceTests: XCTestCase {
441
447
}
442
448
}
443
449
450
+ func testEditDependencyOnNewBranch( ) throws {
451
+ mktmpdir { path in
452
+ let manifestGraph = try MockManifestGraph ( at: path,
453
+ rootDeps: [
454
+ MockDependency ( " A " , version: Version ( 1 , 0 , 0 ) ..< Version ( 1 , . max, . max) ) ,
455
+ ] ,
456
+ packages: [
457
+ MockPackage ( " A " , version: v1) ,
458
+ MockPackage ( " A " , version: nil ) , // To load the edited package manifest.
459
+ ]
460
+ )
461
+ // Create the workspace.
462
+ let workspace = try Workspace ( rootPackage: path, manifestLoader: manifestGraph. manifestLoader, delegate: TestWorkspaceDelegate ( ) )
463
+ // Load the package graph.
464
+ let graph = try workspace. loadPackageGraph ( )
465
+ let manifests = try workspace. loadDependencyManifests ( )
466
+ guard let aManifest = manifests. lookup ( " A " ) else {
467
+ return XCTFail ( " Expected manifest for package A not found " )
468
+ }
469
+ func getDependency( _ manifest: Manifest ) -> Workspace . ManagedDependency {
470
+ return workspace. dependencyMap [ RepositorySpecifier ( url: manifest. url) ] !
471
+ }
472
+ // Get the dependency for package A.
473
+ let dependency = getDependency ( aManifest)
474
+ // Put the dependency in edit mode at its current revision on a new branch.
475
+ try workspace. edit ( dependency: dependency, at: dependency. currentRevision!, packageName: aManifest. name, checkoutBranch: " BugFix " )
476
+ let editedDependency = getDependency ( aManifest)
477
+ XCTAssert ( editedDependency. isInEditableState)
478
+
479
+ let editRepoPath = workspace. editablesPath. appending ( editedDependency. subpath)
480
+ let editRepo = GitRepository ( path: editRepoPath)
481
+ XCTAssertEqual ( try editRepo. getCurrentRevision ( ) , dependency. currentRevision!)
482
+ XCTAssertEqual ( try popen ( [ Git . tool, " -C " , editRepoPath. asString, " rev-parse " , " --abbrev-ref " , " HEAD " ] ) . chomp ( ) , " BugFix " )
483
+ // Unedit it.
484
+ try workspace. unedit ( dependency: editedDependency, forceRemove: false )
485
+ XCTAssertEqual ( getDependency ( aManifest) . isInEditableState, false )
486
+
487
+ do {
488
+ try workspace. edit ( dependency: dependency, at: dependency. currentRevision!, packageName: aManifest. name, checkoutBranch: " master " )
489
+ XCTFail ( " Unexpected edit success " )
490
+ } catch WorkspaceOperationError . branchAlreadyExists { }
491
+ }
492
+ }
493
+
444
494
func testUneditDependency( ) throws {
445
495
mktmpdir { path in
446
496
let manifestGraph = try MockManifestGraph ( at: path,
@@ -506,6 +556,7 @@ final class WorkspaceTests: XCTestCase {
506
556
static var allTests = [
507
557
( " testBasics " , testBasics) ,
508
558
( " testEditDependency " , testEditDependency) ,
559
+ ( " testEditDependencyOnNewBranch " , testEditDependencyOnNewBranch) ,
509
560
( " testDependencyManifestLoading " , testDependencyManifestLoading) ,
510
561
( " testPackageGraphLoadingBasics " , testPackageGraphLoadingBasics) ,
511
562
( " testPackageGraphLoadingWithCloning " , testPackageGraphLoadingWithCloning) ,
0 commit comments