Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👍 add fixup actions to gin-log (fixup, amend, reword) #114

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions denops/gin/action/fixup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Denops } from "https://deno.land/x/denops_std@v5.0.1/mod.ts";
import * as batch from "https://deno.land/x/denops_std@v5.0.1/batch/mod.ts";
import { alias, define, GatherCandidates, Range } from "./core.ts";

export type Candidate = { commit: string };

export async function init(
denops: Denops,
bufnr: number,
gatherCandidates: GatherCandidates<Candidate>,
): Promise<void> {
await batch.batch(denops, async (denops) => {
await define(
denops,
bufnr,
"fixup:fixup",
(denops, bufnr, range) =>
doFixup(denops, bufnr, range, "fixup", gatherCandidates),
);
await define(
denops,
bufnr,
"fixup:amend",
(denops, bufnr, range) =>
doFixup(denops, bufnr, range, "amend", gatherCandidates),
);
await define(
denops,
bufnr,
"fixup:reword",
(denops, bufnr, range) =>
doFixup(denops, bufnr, range, "reword", gatherCandidates),
);
await alias(
denops,
bufnr,
"fixup",
"fixup:fixup",
);
});
}

async function doFixup(
denops: Denops,
bufnr: number,
range: Range,
kind: "fixup" | "amend" | "reword",
gatherCandidates: GatherCandidates<Candidate>,
): Promise<void> {
const xs = await gatherCandidates(denops, bufnr, range);
const commit = xs.map((v) => v.commit).join("\n");
const target = kind === "fixup" ? commit : `${kind}:${commit}`;
// Do not block Vim so that users can edit commit message
denops
.dispatch("gin", "command", "", ["commit", `--fixup=${target}`])
.catch((e) => console.error(`failed to execute git commit: ${e}`));
atusy marked this conversation as resolved.
Show resolved Hide resolved
}
5 changes: 5 additions & 0 deletions denops/gin/command/log/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { init as initActionBrowse } from "../../action/browse.ts";
import { init as initActionCherryPick } from "../../action/cherry_pick.ts";
import { init as initActionCore, Range } from "../../action/core.ts";
import { init as initActionEcho } from "../../action/echo.ts";
import { init as initActionFixup } from "../../action/fixup.ts";
import { init as initActionMerge } from "../../action/merge.ts";
import { init as initActionRebase } from "../../action/rebase.ts";
import { init as initActionReset } from "../../action/reset.ts";
Expand Down Expand Up @@ -94,6 +95,10 @@ export async function exec(
await initActionBrowse(denops, bufnr, gatherCandidates);
await initActionCherryPick(denops, bufnr, gatherCandidates);
await initActionEcho(denops, bufnr, gatherCandidates);
await initActionFixup(denops, bufnr, async (denops, bufnr, range) => {
const xs = await gatherCandidates(denops, bufnr, range);
return xs.map((x) => ({ commit: x.commit }));
});
await initActionMerge(denops, bufnr, gatherCandidates);
await initActionRebase(denops, bufnr, gatherCandidates);
await initActionReset(denops, bufnr, gatherCandidates);
Expand Down