fix check for branch existence

This commit is contained in:
Peter Evans
2024-08-08 16:55:33 +00:00
parent 0c8901cc91
commit 8605c43792
7 changed files with 21 additions and 589 deletions

View File

@ -1,7 +1,6 @@
import * as core from '@actions/core'
import {GitCommandManager, Commit} from './git-command-manager'
import {v4 as uuidv4} from 'uuid'
import * as utils from './utils'
const CHERRYPICK_EMPTY =
'The previous cherry-pick is now empty, possibly due to conflict resolution.'
@ -66,38 +65,6 @@ export async function buildBranchCommits(
return commits
}
export async function buildBranchFileChanges(
git: GitCommandManager,
base: string,
branch: string
): Promise<BranchFileChanges> {
const branchFileChanges: BranchFileChanges = {
additions: [],
deletions: []
}
const changedFiles = await git.getChangedFiles([
'--diff-filter=AM',
`${base}..${branch}`
])
const deletedFiles = await git.getChangedFiles([
'--diff-filter=D',
`${base}..${branch}`
])
const repoPath = git.getWorkingDirectory()
for (const file of changedFiles) {
branchFileChanges.additions!.push({
path: file,
contents: utils.readFileBase64([repoPath, file])
})
}
for (const file of deletedFiles) {
branchFileChanges.deletions!.push({
path: file
})
}
return branchFileChanges
}
// Return the number of commits that branch2 is ahead of branch1
async function commitsAhead(
git: GitCommandManager,
@ -176,7 +143,6 @@ interface CreateOrUpdateBranchResult {
base: string
hasDiffWithBase: boolean
headSha: string
branchFileChanges?: BranchFileChanges
branchCommits: Commit[]
}
@ -356,9 +322,6 @@ export async function createOrUpdateBranch(
// Build the branch commits
result.branchCommits = await buildBranchCommits(git, base, branch)
// Build the branch file changes
result.branchFileChanges = await buildBranchFileChanges(git, base, branch)
// Get the pull request branch SHA
result.headSha = await git.revParse('HEAD')