Skip to content

Commit

Permalink
👍 add fixup actions to gin-log (fixup, amend, reword)
Browse files Browse the repository at this point in the history
adds

- <Plug>(gin-action-fixup)
- <Plug>(gin-action-fixup:fixup)
- <Plug>(gin-action-fixup:amend)
- <Plug>(gin-action-fixup:reword)
  • Loading branch information
atusy committed Dec 6, 2023
1 parent e737a4b commit bdefa8c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
58 changes: 58 additions & 0 deletions denops/gin/action/fixup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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
await denops.call("denops#notify", "gin", "command", ["", [
"commit",
`--fixup=${target}`,
]]);
}
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

0 comments on commit bdefa8c

Please sign in to comment.