Skip to content

Commit

Permalink
refactor: Seclude current branch resolve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Sep 17, 2020
1 parent 378b1be commit 5c542a8
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/private/setup-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const memoizee = require("memoizee")
, rm = require("fs2/rm")
, runProgram = require("../run-program");

const resolveCurrentBranch = async path =>
String(
(await runProgram("git", ["branch", "--show-current"], { cwd: path })).stdoutBuffer
).trim();

module.exports = memoizee(
async (packageContext, { multiPackageReposMeta }, inputOptions, { topPackageName }) => {
const meta = packageContext.meta.multiPackageRepoName
Expand All @@ -23,13 +28,7 @@ module.exports = memoizee(
const tryPush = inputOptions.push;

if (name !== topPackageName) {
// Confirm we're on expected branch
const currentBranch = String(
(await runProgram("git", ["branch", "--show-current"], { cwd: path }))
.stdoutBuffer
).trim();

if (currentBranch !== branch) {
if ((await resolveCurrentBranch()) !== branch) {
log.warning("%s is not at expected %s branch", name, branch);
return report;
}
Expand Down Expand Up @@ -84,10 +83,7 @@ module.exports = memoizee(
await runProgram("git", ["clone", repoUrl, path], {
logger: log.levelRoot.get("git:clone")
});
const currentBranch = String(
(await runProgram("git", ["branch", "--show-current"], { cwd: path })).stdoutBuffer
).trim();
if (currentBranch !== branch) {
if ((await resolveCurrentBranch()) !== branch) {
await runProgram("git", ["checkout", branch], {
logger: log.levelRoot.get("git:branch")
});
Expand Down

0 comments on commit 5c542a8

Please sign in to comment.