Skip to content

Commit

Permalink
feat: send report from setupRepository
Browse files Browse the repository at this point in the history
Report states which operations were pursued,
possible options are: clone, pull, push

BREAKING CHANGE:
setupRepository instead of boolean now returns set
that states which operations were pursued
  • Loading branch information
medikoo committed Nov 13, 2018
1 parent ca5c4f2 commit 7a3fde4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/setup-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const isObject = require("es5-ext/object/is-object")

module.exports = async (path, repoUrl, options = {}) => {
if (!isObject(options)) options = {};
const report = new Set();
if (await isDirectory(path)) {
const tryPull = options.pull, tryPush = options.push;

if (!tryPull && !tryPush) return false;
if (!tryPull && !tryPush) return report;

if (tryPull) {
// Confirm directory is clean
Expand Down Expand Up @@ -44,17 +45,20 @@ module.exports = async (path, repoUrl, options = {}) => {
cwd: path,
logger: log.levelRoot.get("git:merge")
});
report.add("pull");
}

if (
tryPush &&
(localStatus.includes("Your branch is ahead") || localStatus.includes("have diverged"))
) {
await runProgram("git", ["push"], { cwd: path, logger: log.levelRoot.get("git:push") });
report.add("push");
}
return false;
return report;
}
log.info("clone repository %s from %s", path, repoUrl);
await runProgram("git", ["clone", repoUrl, path], { logger: log.levelRoot.get("git:clone") });
return true;
report.add("clone");
return report;
};

0 comments on commit 7a3fde4

Please sign in to comment.