Skip to content

Commit

Permalink
feat: improve repo update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Nov 9, 2018
1 parent 0e5a7ac commit ab1fc26
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/setup-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,31 @@ module.exports = async (path, repoUrl, options = {}) => {
if (await isDirectory(path)) {
if (options.skipGitUpdate) return false;
// Confirm directory is clean
const { stdout } = await runProgram("git", ["status", "--porcelain"], { cwd: path });
if (stdout) {
let { stdout: localStatus } = await runProgram("git", ["status", "--porcelain"], {
cwd: path
});
if (localStatus) {
throw new DevPackageError(
`Cannot proceed with update, repository ${ path } is not clean:\n${
stdout.split("\n").map(line => ` ${ line }`).join("\n")
`Cannot proceed with update, repository at ${ path } is not clean:\n${
localStatus.split("\n").map(line => ` ${ line }`).join("\n")
}`
);
}

// Update
log.info("update repository %s", path);
await runProgram("git", ["pull"], { cwd: path, logger: log.levelRoot.get("git:pull") });
await runProgram("git", ["remote", "update"], {
cwd: path,
logger: log.levelRoot.get("git:remote")
});

({ stdout: localStatus } = await runProgram("git", ["status"], { cwd: path }));
if (localStatus.includes("Your branch is behind")) {
await runProgram("git", ["merge", "FETCH_HEAD"], {
cwd: path,
logger: log.levelRoot.get("git:merge")
});
}
return false;
}
log.info("clone repository %s from %s", path, repoUrl);
Expand Down

0 comments on commit ab1fc26

Please sign in to comment.