@@ -631,6 +631,69 @@ describe('create-or-update-branch tests', () => {
631631 ) . toBeTruthy ( )
632632 } )
633633
634+ it ( 'tests create, force push of base branch, and update with identical changes' , async ( ) => {
635+ // If the base branch is force pushed to a different commit when there is an open
636+ // pull request, the branch must be reset to rebase the changes on the base.
637+
638+ // Create tracked and untracked file changes
639+ const changes = await createChanges ( )
640+ const commitMessage = uuidv4 ( )
641+ const result = await createOrUpdateBranch (
642+ git ,
643+ commitMessage ,
644+ '' ,
645+ BRANCH ,
646+ REMOTE_NAME ,
647+ false ,
648+ ADD_PATHS_DEFAULT
649+ )
650+ expect ( result . action ) . toEqual ( 'created' )
651+ expect ( await getFileContent ( TRACKED_FILE ) ) . toEqual ( changes . tracked )
652+ expect ( await getFileContent ( UNTRACKED_FILE ) ) . toEqual ( changes . untracked )
653+ expect (
654+ await gitLogMatches ( [ commitMessage , INIT_COMMIT_MESSAGE ] )
655+ ) . toBeTruthy ( )
656+
657+ // Push pull request branch to remote
658+ await git . push ( [
659+ '--force-with-lease' ,
660+ REMOTE_NAME ,
661+ `HEAD:refs/heads/${ BRANCH } `
662+ ] )
663+
664+ await afterTest ( false )
665+ await beforeTest ( )
666+
667+ // Force push the base branch to a different commit
668+ const amendedCommitMessage = uuidv4 ( )
669+ await git . commit ( [ '--amend' , '-m' , amendedCommitMessage ] )
670+ await git . push ( [
671+ '--force' ,
672+ REMOTE_NAME ,
673+ `HEAD:refs/heads/${ DEFAULT_BRANCH } `
674+ ] )
675+
676+ // Create the same tracked and untracked file changes (no change on update)
677+ const _changes = await createChanges ( changes . tracked , changes . untracked )
678+ const _commitMessage = uuidv4 ( )
679+ const _result = await createOrUpdateBranch (
680+ git ,
681+ _commitMessage ,
682+ '' ,
683+ BRANCH ,
684+ REMOTE_NAME ,
685+ false ,
686+ ADD_PATHS_DEFAULT
687+ )
688+ expect ( _result . action ) . toEqual ( 'updated' )
689+ expect ( _result . hasDiffWithBase ) . toBeTruthy ( )
690+ expect ( await getFileContent ( TRACKED_FILE ) ) . toEqual ( _changes . tracked )
691+ expect ( await getFileContent ( UNTRACKED_FILE ) ) . toEqual ( _changes . untracked )
692+ expect (
693+ await gitLogMatches ( [ _commitMessage , amendedCommitMessage ] )
694+ ) . toBeTruthy ( )
695+ } )
696+
634697 it ( 'tests create and update with commits on the working base (during the workflow)' , async ( ) => {
635698 // Create commits on the working base
636699 const commits = await createCommits ( git )
@@ -1519,6 +1582,75 @@ describe('create-or-update-branch tests', () => {
15191582 ) . toBeTruthy ( )
15201583 } )
15211584
1585+ it ( 'tests create, force push of base branch, and update with identical changes (WBNB)' , async ( ) => {
1586+ // If the base branch is force pushed to a different commit when there is an open
1587+ // pull request, the branch must be reset to rebase the changes on the base.
1588+
1589+ // Set the working base to a branch that is not the pull request base
1590+ await git . checkout ( NOT_BASE_BRANCH )
1591+
1592+ // Create tracked and untracked file changes
1593+ const changes = await createChanges ( )
1594+ const commitMessage = uuidv4 ( )
1595+ const result = await createOrUpdateBranch (
1596+ git ,
1597+ commitMessage ,
1598+ BASE ,
1599+ BRANCH ,
1600+ REMOTE_NAME ,
1601+ false ,
1602+ ADD_PATHS_DEFAULT
1603+ )
1604+ expect ( result . action ) . toEqual ( 'created' )
1605+ expect ( await getFileContent ( TRACKED_FILE ) ) . toEqual ( changes . tracked )
1606+ expect ( await getFileContent ( UNTRACKED_FILE ) ) . toEqual ( changes . untracked )
1607+ expect (
1608+ await gitLogMatches ( [ commitMessage , INIT_COMMIT_MESSAGE ] )
1609+ ) . toBeTruthy ( )
1610+
1611+ // Push pull request branch to remote
1612+ await git . push ( [
1613+ '--force-with-lease' ,
1614+ REMOTE_NAME ,
1615+ `HEAD:refs/heads/${ BRANCH } `
1616+ ] )
1617+
1618+ await afterTest ( false )
1619+ await beforeTest ( )
1620+
1621+ // Force push the base branch to a different commit
1622+ const amendedCommitMessage = uuidv4 ( )
1623+ await git . commit ( [ '--amend' , '-m' , amendedCommitMessage ] )
1624+ await git . push ( [
1625+ '--force' ,
1626+ REMOTE_NAME ,
1627+ `HEAD:refs/heads/${ DEFAULT_BRANCH } `
1628+ ] )
1629+
1630+ // Set the working base to a branch that is not the pull request base
1631+ await git . checkout ( NOT_BASE_BRANCH )
1632+
1633+ // Create the same tracked and untracked file changes (no change on update)
1634+ const _changes = await createChanges ( changes . tracked , changes . untracked )
1635+ const _commitMessage = uuidv4 ( )
1636+ const _result = await createOrUpdateBranch (
1637+ git ,
1638+ _commitMessage ,
1639+ BASE ,
1640+ BRANCH ,
1641+ REMOTE_NAME ,
1642+ false ,
1643+ ADD_PATHS_DEFAULT
1644+ )
1645+ expect ( _result . action ) . toEqual ( 'updated' )
1646+ expect ( _result . hasDiffWithBase ) . toBeTruthy ( )
1647+ expect ( await getFileContent ( TRACKED_FILE ) ) . toEqual ( _changes . tracked )
1648+ expect ( await getFileContent ( UNTRACKED_FILE ) ) . toEqual ( _changes . untracked )
1649+ expect (
1650+ await gitLogMatches ( [ _commitMessage , amendedCommitMessage ] )
1651+ ) . toBeTruthy ( )
1652+ } )
1653+
15221654 it ( 'tests create and update with commits on the working base (during the workflow) (WBNB)' , async ( ) => {
15231655 // Set the working base to a branch that is not the pull request base
15241656 await git . checkout ( NOT_BASE_BRANCH )
0 commit comments