2023-02-26 11:34:26 +00:00
|
|
|
import { Command } from "./dependencies.ts";
|
2023-06-07 13:43:02 +00:00
|
|
|
import { runAndReturnStdout, runCommand } from "./utilities.ts";
|
2022-12-09 11:26:08 +00:00
|
|
|
|
|
|
|
async function main(): Promise<void> {
|
|
|
|
const { args } = await new Command()
|
|
|
|
.name("simple-git-push")
|
|
|
|
.description("Git push with some extra semantics.")
|
|
|
|
.arguments("[...args:string]")
|
|
|
|
.parse(Deno.args);
|
|
|
|
|
|
|
|
const availableRemotes = await gitRemote();
|
|
|
|
|
|
|
|
if (availableRemotes.length === 0) {
|
|
|
|
console.log("No remotes found");
|
2023-07-28 18:17:18 +00:00
|
|
|
return;
|
2022-12-09 11:26:08 +00:00
|
|
|
}
|
|
|
|
|
2023-06-17 10:04:05 +00:00
|
|
|
const remotesToPush = ["origin", "github", "gitlab"];
|
2022-12-09 11:26:08 +00:00
|
|
|
for (const remote of availableRemotes) {
|
|
|
|
if (remotesToPush.includes(remote)) {
|
|
|
|
await gitPush(remote, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function gitPush(remote: string, args: string[]): Promise<void> {
|
2023-06-07 13:43:02 +00:00
|
|
|
await runCommand("git", {
|
2023-06-05 11:27:29 +00:00
|
|
|
args: [
|
2022-12-09 11:26:08 +00:00
|
|
|
"push",
|
|
|
|
"--follow-tags",
|
|
|
|
remote,
|
|
|
|
...args,
|
|
|
|
],
|
2023-06-07 13:43:02 +00:00
|
|
|
});
|
2022-12-09 11:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function gitRemote(): Promise<string[]> {
|
2023-06-05 11:27:29 +00:00
|
|
|
const output = await runAndReturnStdout("git", { args: ["remote"] });
|
2022-12-09 11:26:08 +00:00
|
|
|
return output.trim().split("\n").filter((remote) => remote.length > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (import.meta.main) {
|
|
|
|
void main();
|
|
|
|
}
|