]> git.r.bdr.sh - rbdr/blog/blame_incremental - lib/remotes/git.js
Update deps, fix broken update
[rbdr/blog] / lib / remotes / git.js
... / ...
CommitLineData
1const { exec } = require('child_process');
2const { promisify } = require('util');
3
4const internals = {
5 // Promisified functions
6 exec: promisify(exec),
7};
8
9module.exports = {
10 canHandle() {
11
12 // For the future: actually check if it's a valid git url
13 return true;
14 },
15
16 async syncUp(remote, blogDirectory) {
17
18 await internals.exec(`cd ${blogDirectory} && git init -b main`);
19 await internals.exec(`cd ${blogDirectory} && git add .`);
20 await internals.exec(`cd ${blogDirectory} && git commit --allow-empty -m blog-sync-up-${Date.now()}`);
21 await internals.exec(`cd ${blogDirectory} && git push ${remote} main --force`);
22 },
23
24 async syncDown(remote, blogDirectory) {
25
26 await internals.exec(`cd ${blogDirectory} && git init -b main`);
27 try {
28 await internals.exec(`cd ${blogDirectory} && git checkout .`);
29 }
30 catch {}
31 await internals.exec(`cd ${blogDirectory} && git clean . -f`);
32 await internals.exec(`cd ${blogDirectory} && git pull ${remote} main`);
33 }
34}