Skip to content

Instantly share code, notes, and snippets.

@qodunpob
Created August 2, 2018 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qodunpob/03d5fe324ed4d12c26e2bb2ebb59bf86 to your computer and use it in GitHub Desktop.
Save qodunpob/03d5fe324ed4d12c26e2bb2ebb59bf86 to your computer and use it in GitHub Desktop.
/* checking if branch exists in builds repository */
const isBranchExits = !!spawnSync(
'git',
['ls-remote', '--exit-code', 'origin', buildBranch],
getSpawnOptions(tempDir, 'pipe')
).stdout.toString().trim();
if (isBranchExits) {
/* checkout the target branch */
spawnSync('git', ['fetch', 'origin', buildBranch], getSpawnOptions(tempDir));
spawnSync('git', ['checkout', buildBranch], getSpawnOptions(tempDir));
} else {
/* checkout master */
spawnSync('git', ['fetch', 'origin', 'master'], getSpawnOptions(tempDir));
spawnSync('git', ['checkout', 'master'], getSpawnOptions(tempDir));
/* creating branch */
spawnSync('git', ['checkout', '-b', buildBranch], getSpawnOptions(tempDir));
/* creating initial commit */
spawnSync('git', ['commit', '--allow-empty', '-m', '"Initial commit"'], getSpawnOptions(tempDir));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment