Skip to content

Commit

Permalink
Merge pull request #30 from bitovi/handle-non-master
Browse files Browse the repository at this point in the history
fix logic to handle non-master baseBranch
  • Loading branch information
Christopher Baker committed Feb 7, 2018
2 parents fa8f362 + 5b3286a commit 52a32d3
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/cli/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,11 @@ function createTempDirectory () {
})
}

async function cloneProject (directory, githubUrl) {
await execa('git', ['clone', '--depth', '1', '--', githubUrl, directory])
async function cloneProject (directory, baseBranchName, githubUrl) {
await execa('git', ['clone', '--depth', '1', '-b', baseBranchName, '--', githubUrl, directory])
}

async function createBranch (directory, baseBranchName, branchName) {
await execa('git', ['-C', directory, 'checkout', baseBranchName])
async function createBranch (directory, branchName) {
await execa('git', [ '-C', directory, 'checkout', '-b', branchName ])
}

Expand Down Expand Up @@ -289,7 +288,7 @@ function isMissingRepoError (error) {
}

function isMissingBaseBranchError (error) {
return hasKeyPhrases(getErrorMessage(error), ['pathspec', 'did not match'])
return hasKeyPhrases(getErrorMessage(error), ['not found in upstream origin'])
}

function isEmptyCommitError (error) {
Expand All @@ -316,23 +315,19 @@ function processRepo (repo, log, accessToken) {

return inTempDirectory(async directory => {
try {
await cloneProject(directory, fullProjectUrl)
await cloneProject(directory, baseBranchName, fullProjectUrl)
} catch (error) {
if (isMissingRepoError(error)) {
throw new Error(`Repository not found`)
}
throw error
}
log(`cloned repository "${projectUrl}"`)

try {
await createBranch(directory, baseBranchName, branchName)
} catch (error) {
if (isMissingBaseBranchError(error)) {
throw new Error(`Could not checkout non-existent branch "${baseBranchName}"`)
}
throw error
}
log(`cloned repository "${projectUrl}"`)

await createBranch(directory, branchName)
log(`created branch "${branchName}" from "${baseBranchName}"`)

await transformRepo(directory, mods, {accessToken}, log)
Expand Down

0 comments on commit 52a32d3

Please sign in to comment.