Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/commands/common-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,12 @@ module.exports.fileOptions = {
describe: 'File containing JSON data',
},
};

module.exports.pullOptions = {
warningUndoChangesAndCheckoutMain: {
type: 'boolean',
describe: 'Undo all uncommited changes and checkout main repo branch',
default: false,
group: 'Pull options:',
},
};
21 changes: 18 additions & 3 deletions lib/commands/platform/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@
const simpleGit = importLazy('simple-git');
const DevelopmentEnvironment = importLazy('../../environment/development');

const { pullOptions } = require('../common-options');

function isClean(status) {
const check = ['conflicted', 'created', 'deleted', 'modified', 'renamed'];
return check.reduce((sum, name) => sum + status[name].length, 0) === 0;
}

function pullRepository(dir) {
function pullRepository(dir, undoChangesAndCheckoutMain) {
const git = simpleGit(dir);

// Rejects if repo is not is suitable for pulling
const okToPull = () => new Promise((resolve, reject) => {
git.status()
.then((status) => {
.then(async (status) => {

Check failure on line 20 in lib/commands/platform/pull.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Expected to return a value at the end of async arrow function

Check failure on line 20 in lib/commands/platform/pull.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Expected to return a value at the end of async arrow function
if (undoChangesAndCheckoutMain) {
await git.raw('add', '-A'); // add all changes, including new files, deleted files so they are tracked by git
await git.raw('reset', '--hard', 'HEAD'); // and undo them all muahahaha ψ(`∇´)ψ
try {
await git.checkout('main');
} catch (e) {} // if we can't checkout main - then ignore the error and checkout master

Check failure on line 26 in lib/commands/platform/pull.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Empty block statement

Check failure on line 26 in lib/commands/platform/pull.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Empty block statement

Check failure on line 27 in lib/commands/platform/pull.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Trailing spaces not allowed

Check failure on line 27 in lib/commands/platform/pull.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Trailing spaces not allowed
await git.checkout('master');

return resolve(status);
}

if (!isClean(status)) {
reject(new Error('Branch contains changes.'));
}
Expand Down Expand Up @@ -85,7 +99,7 @@
return new Promise((resolve) => {
let pulls;
moduleDirs.forEach((dir) => {
pulls = pulls ? pulls.then(() => pullRepository(dir)) : pullRepository(dir);
pulls = pulls ? pulls.then(() => pullRepository(dir, argv.warningUndoChangesAndCheckoutMain)) : pullRepository(dir, argv.warningUndoChangesAndCheckoutMain);
});

pulls.then(() => {
Expand All @@ -103,6 +117,7 @@
.middleware([
contextMiddleware(),
])
.options(Object.assign({}), pullOptions)
.example('$0 platform pull', 'Pull all clean repositories including aliases');
return yargs;
},
Expand Down
Loading