@@ -45,7 +45,7 @@ describe('PullRequestGitHelper', function () {
4545 } ) ;
4646
4747 describe ( 'fetchAndCheckout' , function ( ) {
48- it ( 'fetches remote and updates local branch when local branch exists with different commit' , async function ( ) {
48+ it ( 'creates a unique branch when local branch exists with different commit to preserve user work ' , async function ( ) {
4949 const url = 'git@github.com:owner/name.git' ;
5050 const remote = new GitHubRemote ( 'origin' , url , new Protocol ( url ) , GitHubServerType . GitHubDotCom ) ;
5151 const gitHubRepository = new MockGitHubRepository ( remote , credentialStore , telemetry , sinon ) ;
@@ -80,13 +80,17 @@ describe('PullRequestGitHelper', function () {
8080
8181 await PullRequestGitHelper . fetchAndCheckout ( repository , remotes , pullRequest , { report : ( ) => undefined } ) ;
8282
83- // Verify that the local branch was updated to point to the remote commit
84- const updatedBranch = await repository . getBranch ( 'my-branch' ) ;
85- assert . strictEqual ( updatedBranch . commit , 'remote-commit-hash' ) ;
86- assert . strictEqual ( repository . state . HEAD ?. name , 'my-branch' ) ;
83+ // Verify that the original local branch is preserved
84+ const originalBranch = await repository . getBranch ( 'my-branch' ) ;
85+ assert . strictEqual ( originalBranch . commit , 'local-commit-hash' , 'Original branch should be preserved' ) ;
86+
87+ // Verify that a unique branch was created with the correct commit
88+ const uniqueBranch = await repository . getBranch ( 'pr/me/100' ) ;
89+ assert . strictEqual ( uniqueBranch . commit , 'remote-commit-hash' , 'Unique branch should have remote commit' ) ;
90+ assert . strictEqual ( repository . state . HEAD ?. name , 'pr/me/100' , 'Should check out the unique branch' ) ;
8791 } ) ;
8892
89- it ( 'updates branch even when currently checked out if commit differs from remote ' , async function ( ) {
93+ it ( 'creates a unique branch even when currently checked out on conflicting local branch ' , async function ( ) {
9094 const url = 'git@github.com:owner/name.git' ;
9195 const remote = new GitHubRemote ( 'origin' , url , new Protocol ( url ) , GitHubServerType . GitHubDotCom ) ;
9296 const gitHubRepository = new MockGitHubRepository ( remote , credentialStore , telemetry , sinon ) ;
@@ -121,11 +125,14 @@ describe('PullRequestGitHelper', function () {
121125
122126 await PullRequestGitHelper . fetchAndCheckout ( repository , remotes , pullRequest , { report : ( ) => undefined } ) ;
123127
124- // Verify that the local branch was updated to point to the remote commit, even though we were already on it
125- const updatedBranch = await repository . getBranch ( 'my-branch' ) ;
126- assert . strictEqual ( updatedBranch . commit , 'remote-commit-hash' ) ;
127- // Since we were already on the branch, HEAD should remain unchanged
128- assert . strictEqual ( repository . state . HEAD ?. name , 'my-branch' ) ;
128+ // Verify that the original local branch is preserved with its commit
129+ const originalBranch = await repository . getBranch ( 'my-branch' ) ;
130+ assert . strictEqual ( originalBranch . commit , 'local-commit-hash' , 'Original branch should be preserved' ) ;
131+
132+ // Verify that a unique branch was created and checked out
133+ const uniqueBranch = await repository . getBranch ( 'pr/me/100' ) ;
134+ assert . strictEqual ( uniqueBranch . commit , 'remote-commit-hash' , 'Unique branch should have remote commit' ) ;
135+ assert . strictEqual ( repository . state . HEAD ?. name , 'pr/me/100' , 'Should check out the unique branch' ) ;
129136 } ) ;
130137 } ) ;
131138
0 commit comments