Skip to content

Commit

Permalink
Merge pull request twosigma#877 from geeli123/fix-implement-verbose
Browse files Browse the repository at this point in the history
fix jshint issues
  • Loading branch information
tsiq-shu authored Dec 15, 2022
2 parents 0b215bd + 27a0822 commit 2a69a9f
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions node/lib/util/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const UserError = require("./user_error");
* @param {NodeGit.Repository} repo
* @param {String []} paths
*/
exports.stagePaths = co.wrap(function *(repo, paths, stageMetaChanges, update, verbose) {
exports.stagePaths = co.wrap(function *(repo,
paths,
stageMetaChanges,
update,
verbose) {
assert.instanceOf(repo, NodeGit.Repository);
assert.isArray(paths);
assert.isBoolean(stageMetaChanges);
Expand All @@ -70,6 +74,12 @@ exports.stagePaths = co.wrap(function *(repo, paths, stageMetaChanges, update, v
}
}));

function log_verbose(name, filename, op) {
if (verbose) {
process.stdout.write(`${name}: ${op} '${filename}'\n`);
}
}

const repoStatus = yield StatusUtil.getRepoStatus(repo, {
showMetaChanges: stageMetaChanges,
paths: paths,
Expand All @@ -88,34 +98,25 @@ exports.stagePaths = co.wrap(function *(repo, paths, stageMetaChanges, update, v
yield Object.keys(workdir).map(filename => {
// if -u flag is provided, update tracked files only.
if (RepoStatus.FILESTATUS.REMOVED === workdir[filename]) {
if (verbose) {
process.stdout.write(`${name}: remove '${filename}'\n`)
}
log_verbose(name, filename, "remove");
return index.removeByPath(filename);
} else if (update) {
if (RepoStatus.FILESTATUS.ADDED !== workdir[filename]) {
if (verbose) {
process.stdout.write(`${name}: add '${filename}'\n`)
}
return index.addByPath(filename);
log_verbose(name, filename, "modify");
return index.addByPath(filename);
}
} else {
if (verbose) {
process.stdout.write(`${name}: add '${filename}'\n`)
}
log_verbose(name, filename, "add");
return index.addByPath(filename);
}
});

// Add conflicted files.

const staged = subStat.workdir.status.staged;
yield Object.keys(staged).map(co.wrap(function *(filename) {
const change = staged[filename];
if (change instanceof RepoStatus.Conflict) {
if (verbose) {
process.stdout.write(`${name}: add '${filename}'\n`)
}
log_verbose(name, filename, "add");
yield index.addByPath(filename);
}
}));
Expand Down

0 comments on commit 2a69a9f

Please sign in to comment.