1
0
silverbullet/plugs/git/git.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-04-01 15:07:08 +00:00
import { run } from "plugos-syscall/shell";
import { flashNotification, prompt } from "plugos-silverbullet-syscall/editor";
2022-04-05 15:02:17 +00:00
import { invokeFunction } from "plugos-silverbullet-syscall/system";
2022-03-25 11:03:06 +00:00
export async function commit(message?: string) {
if (!message) {
message = "Snapshot";
}
console.log(
"Snapshotting the current space to git with commit message",
message
);
2022-04-01 15:07:08 +00:00
await run("git", ["add", "./*.md"]);
2022-03-25 11:03:06 +00:00
try {
2022-04-01 15:07:08 +00:00
await run("git", ["commit", "-a", "-m", message]);
2022-03-25 11:03:06 +00:00
} catch (e) {
// We can ignore, this happens when there's no changes to commit
}
console.log("Done!");
}
export async function snapshotCommand() {
2022-04-01 15:07:08 +00:00
let revName = await prompt(`Revision name:`);
2022-03-25 11:03:06 +00:00
if (!revName) {
revName = "Snapshot";
}
console.log("Revision name", revName);
2022-04-05 15:02:17 +00:00
await invokeFunction("server", "commit", revName);
2022-03-25 11:03:06 +00:00
}
export async function syncCommand() {
2022-04-01 15:07:08 +00:00
await flashNotification("Syncing with git");
2022-04-05 15:02:17 +00:00
await invokeFunction("server", "sync");
2022-04-01 15:07:08 +00:00
await flashNotification("Git sync complete!");
2022-03-25 11:03:06 +00:00
}
export async function sync() {
console.log("Going to sync with git");
await commit();
console.log("Then pulling from remote");
2022-04-01 15:07:08 +00:00
await run("git", ["pull"]);
2022-03-25 11:03:06 +00:00
console.log("And then pushing to remote");
2022-04-01 15:07:08 +00:00
await run("git", ["push"]);
2022-03-25 11:03:06 +00:00
console.log("Done!");
}