]> git.r.bdr.sh - rbdr/blog/blame - lib/remotes/git.js
Fixes for remote setup
[rbdr/blog] / lib / remotes / git.js
CommitLineData
c5cbbd38
RBR
1const { exec } = require('child_process');
2const { debuglog, promisify } = require('util');
3
4const internals = {
5 // Promisified functions
6 exec: promisify(exec),
7
8 debuglog: debuglog('blog'),
9};
10
11module.exports = {
12 canHandle() {
13 // For the future: actually check if it's a valid git url
14 return true;
15 },
16
17 async syncUp(remote, blogDirectory) {
bd8c1fa2
RBR
18 let output = null;
19
20 output = await internals.exec(`cd ${blogDirectory} && git init`);
21 internals.debuglog(output.stderr);
22
23 output = await internals.exec(`cd ${blogDirectory} && git add .`);
24 internals.debuglog(output.stderr);
25
26 output = await internals.exec(`cd ${blogDirectory} && git commit --allow-empty -m blog-sync-up-${Date.now()}`);
27 internals.debuglog(output.stderr);
28
29 output = await internals.exec(`cd ${blogDirectory} && git push ${remote} main --force`);
30 internals.debuglog(output.stderr);
c5cbbd38
RBR
31 },
32
33 async syncDown(remote, blogDirectory) {
bd8c1fa2
RBR
34 let output = null;
35
36 output = await internals.exec(`cd ${blogDirectory} && git init`);
37 internals.debuglog(output.stderr);
38
39 output = await internals.exec(`cd ${blogDirectory} && git checkout .`);
40 internals.debuglog(output.stderr);
41
42 output = await internals.exec(`cd ${blogDirectory} && git clean . -f`);
43 internals.debuglog(output.stderr);
44
45 output = await internals.exec(`cd ${blogDirectory} && git pull ${remote} main`);
46 internals.debuglog(output.stderr);
c5cbbd38
RBR
47 }
48}