Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const commandName = `${name}: git ${args.join(' ')}`
const result = await GitPerf.measure(commandName, () =>
GitProcess.exec(args, path, options)
)
const exitCode = result.exitCode
let gitError: DugiteError | null = null
const acceptableExitCode = opts.successExitCodes
? opts.successExitCodes.has(exitCode)
: false
if (!acceptableExitCode) {
gitError = GitProcess.parseError(result.stderr)
if (!gitError) {
gitError = GitProcess.parseError(result.stdout)
}
}
const gitErrorDescription = gitError ? getDescriptionForError(gitError) : null
const gitResult = { ...result, gitError, gitErrorDescription }
let acceptableError = true
if (gitError && opts.expectedErrors) {
acceptableError = opts.expectedErrors.has(gitError)
}
if ((gitError && acceptableError) || acceptableExitCode) {
return gitResult
}
// The caller should either handle this error, or expect that exit code.
async function findChangedFiles (top) {
const result = await GitProcess.exec(['diff', '--name-only', '--cached'], top)
if (result.exitCode !== 0) {
console.log('Failed to find changed files', GitProcess.parseError(result.stderr))
process.exit(1)
}
const relativePaths = result.stdout.split(/\r\n|\r|\n/g)
const absolutePaths = relativePaths.map(x => path.join(top, x))
return new Set(absolutePaths)
}
async function mergeReleaseIntoBranch (branchName) {
console.log(`Merging release branch into ${branchName}.`)
let mergeArgs = ['merge', 'release', '--squash']
let mergeDetails = await GitProcess.exec(mergeArgs, gitDir)
if (mergeDetails.exitCode === 0) {
return true
} else {
const error = GitProcess.parseError(mergeDetails.stderr)
if (error === GitError.MergeConflicts) {
console.log(`${fail} Could not merge release branch into ${branchName} ` +
`due to merge conflicts.`)
return false
} else {
console.log(`${fail} Could not merge release branch into ${branchName} ` +
`due to an error: ${mergeDetails.stderr}.`)
process.exit(1)
}
}
}
async function handleGitCall (args, gitDir) {
const details = await GitProcess.exec(args, gitDir)
if (details.exitCode === 0) {
return details.stdout.replace(/^\*|\s+|\s+$/, '')
} else {
const error = GitProcess.parseError(details.stderr)
console.log(`${fail} couldn't parse git process call: `, error)
process.exit(1)
}
}
async function revertBumpCommit (tag) {
const branch = await getCurrentBranch()
const commitToRevert = getLastBumpCommit(tag).hash
await GitProcess.exec(['revert', commitToRevert], ELECTRON_DIR)
const pushDetails = await GitProcess.exec(['push', 'origin', `HEAD:${branch}`, '--follow-tags'], ELECTRON_DIR)
if (pushDetails.exitCode === 0) {
console.log(`${pass} successfully reverted release commit.`)
} else {
const error = GitProcess.parseError(pushDetails.stderr)
console.error(`${fail} could not push release commit: `, error)
process.exit(1)
}
}
const opts = { ...defaultOptions, ...options }
const commandName = `${name}: git ${args.join(' ')}`
const result = await GitPerf.measure(commandName, () =>
GitProcess.exec(args, path, options)
)
const exitCode = result.exitCode
let gitError: DugiteError | null = null
const acceptableExitCode = opts.successExitCodes
? opts.successExitCodes.has(exitCode)
: false
if (!acceptableExitCode) {
gitError = GitProcess.parseError(result.stderr)
if (!gitError) {
gitError = GitProcess.parseError(result.stdout)
}
}
const gitErrorDescription = gitError ? getDescriptionForError(gitError) : null
const gitResult = { ...result, gitError, gitErrorDescription }
let acceptableError = true
if (gitError && opts.expectedErrors) {
acceptableError = opts.expectedErrors.has(gitError)
}
if ((gitError && acceptableError) || acceptableExitCode) {
return gitResult
}