Skip to content

Commit 61b8354

Browse files
CopilotJamesIves
andcommitted
Fix temporaryDeploymentBranch conflict by replacing slash with hyphen
Co-authored-by: JamesIves <10888441+JamesIves@users.noreply.github.com>
1 parent b30d44c commit 61b8354

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

__tests__/git.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,5 +469,35 @@ describe('git', () => {
469469
expect(execute).toHaveBeenCalledTimes(17)
470470
expect(response).toBe(Status.SUCCESS)
471471
})
472+
473+
it('should generate temporary branch name without forward slashes to avoid conflicts', async () => {
474+
Object.assign(action, {
475+
hostname: 'github.com',
476+
silent: false,
477+
folder: 'assets',
478+
branch: 'branch',
479+
token: '123',
480+
repositoryName: 'JamesIves/montezuma',
481+
pusher: {
482+
name: 'asd',
483+
email: 'as@cat'
484+
},
485+
isTest: TestFlag.HAS_CHANGED_FILES
486+
})
487+
488+
await deploy(action)
489+
490+
// Check that execute was called with a checkout command that doesn't contain forward slashes in branch name
491+
const executeCalls = (execute as jest.Mock).mock.calls
492+
const checkoutCall = executeCalls.find((call) =>
493+
call[0].includes('checkout -b') && call[0].includes('github-pages-deploy-action')
494+
)
495+
496+
expect(checkoutCall).toBeDefined()
497+
// The branch name should contain 'github-pages-deploy-action-' (with hyphen, not slash)
498+
expect(checkoutCall[0]).toMatch(/github-pages-deploy-action-[a-z0-9]+/)
499+
// The branch name should NOT contain forward slashes
500+
expect(checkoutCall[0]).not.toMatch(/github-pages-deploy-action\//)
501+
})
472502
})
473503
})

src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export async function init(action: ActionInterface): Promise<void | Error> {
108108
export async function deploy(action: ActionInterface): Promise<Status> {
109109
const temporaryDeploymentDirectory =
110110
'github-pages-deploy-action-temp-deployment-folder'
111-
const temporaryDeploymentBranch = `github-pages-deploy-action/${Math.random()
111+
const temporaryDeploymentBranch = `github-pages-deploy-action-${Math.random()
112112
.toString(36)
113113
.substr(2, 9)}`
114114
const rsyncVersion = getRsyncVersion()

0 commit comments

Comments
 (0)