Skip to content

Commit ecae0ca

Browse files
committed
lib: implement git node sync
1 parent 340ac88 commit ecae0ca

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

components/git/sync.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const CLI = require('../../lib/cli');
4+
const { runPromise } = require('../../lib/run');
5+
const SyncSession = require('../../lib/sync_session');
6+
7+
function builder(yargs) {
8+
return yargs
9+
.wrap(90);
10+
}
11+
12+
async function main() {
13+
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
14+
const cli = new CLI(logStream);
15+
const dir = process.cwd();
16+
const session = new SyncSession(cli, dir);
17+
await session.sync();
18+
}
19+
20+
function handler(argv) {
21+
return runPromise(main());
22+
}
23+
24+
module.exports = {
25+
command: 'sync',
26+
describe: 'Sync the branch specified by ncu-config',
27+
builder,
28+
handler
29+
};

lib/sync_session.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const Session = require('./session');
4+
5+
class SyncSession extends Session {
6+
constructor(cli, dir) {
7+
// eslint-disable-next-line no-useless-constructor
8+
super(cli, dir);
9+
}
10+
11+
async sync() {
12+
if (this.warnForMissing()) {
13+
return;
14+
}
15+
if (this.warnForWrongBranch()) {
16+
return;
17+
}
18+
return this.tryResetHead();
19+
}
20+
}
21+
22+
module.exports = SyncSession;

0 commit comments

Comments
 (0)