Created
August 2, 2018 06:08
-
-
Save qodunpob/03d5fe324ed4d12c26e2bb2ebb59bf86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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