Skip to content

Commit a5922b5

Browse files
authored
Merge pull request #141 from lambdalisue/refine-gin-chaperon-patch
👍 Make `path` of `GinChaperon` and `GinPatch` optional
2 parents 741b6a3 + 035ff18 commit a5922b5

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

denops/gin/command/chaperon/main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
validateOpts,
99
} from "jsr:@denops/std@^7.0.0/argument";
1010
import { fillCmdArgs, normCmdArgs, parseSilent } from "../../util/cmd.ts";
11+
import { ensurePath } from "../../util/ensure_path.ts";
1112
import { exec } from "./command.ts";
1213

1314
export function main(denops: Denops): void {
@@ -46,8 +47,8 @@ async function command(
4647
...builtinOpts,
4748
]);
4849

49-
const [abspath] = parseResidue(residue);
50-
await exec(denops, abspath, {
50+
const [rawpath] = parseResidue(residue);
51+
await exec(denops, await ensurePath(denops, rawpath), {
5152
worktree: opts.worktree,
5253
opener: opts.opener,
5354
noOurs: "no-ours" in opts,
@@ -60,9 +61,12 @@ async function command(
6061

6162
function parseResidue(
6263
residue: string[],
63-
): [string] {
64-
// GinChaperon [{options}] {path}
64+
): [string | undefined] {
6565
switch (residue.length) {
66+
// GinChaperon [{options}]
67+
case 0:
68+
return [undefined];
69+
// GinChaperon [{options}] {path}
6670
case 1:
6771
return [residue[0]];
6872
default:

denops/gin/command/patch/main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
validateOpts,
99
} from "jsr:@denops/std@^7.0.0/argument";
1010
import { fillCmdArgs, normCmdArgs, parseSilent } from "../../util/cmd.ts";
11+
import { ensurePath } from "../../util/ensure_path.ts";
1112
import { exec } from "./command.ts";
1213

1314
export function main(denops: Denops): void {
@@ -46,8 +47,8 @@ async function command(
4647
...builtinOpts,
4748
]);
4849

49-
const [abspath] = parseResidue(residue);
50-
await exec(denops, abspath, {
50+
const [rawpath] = parseResidue(residue);
51+
await exec(denops, await ensurePath(denops, rawpath), {
5152
worktree: opts.worktree,
5253
noHead: "no-head" in opts,
5354
noWorktree: "no-worktree" in opts,
@@ -60,9 +61,12 @@ async function command(
6061

6162
function parseResidue(
6263
residue: string[],
63-
): [string] {
64-
// GinPatch [{options}] {path}
64+
): [string | undefined] {
6565
switch (residue.length) {
66+
// GinPatch [{options}]
67+
case 0:
68+
return [undefined];
69+
// GinPatch [{options}] {path}
6670
case 1:
6771
return [residue[0]];
6872
default:

denops/gin/util/ensure_path.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { Denops } from "jsr:@denops/std@^7.0.0";
2+
import * as fn from "jsr:@denops/std@^7.0.0/function";
3+
4+
/**
5+
* Ensure the path is absolute.
6+
*
7+
* It returns the absolute path of the given path. If the path is not given, it
8+
* returns the absolute path of the current buffer.
9+
*
10+
* @param denops Denops instance.
11+
* @param path Path to ensure.
12+
* @returns Absolute path.
13+
*/
14+
export async function ensurePath(
15+
denops: Denops,
16+
path?: string,
17+
): Promise<string> {
18+
const bufname = await fn.expand(denops, path ?? "%") as string;
19+
const abspath = await fn.fnamemodify(denops, bufname, ":p");
20+
return abspath;
21+
}

doc/gin.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ COMMANDS *gin-commands*
217217
directory. Commands call |cd|, |lcd|, and |tcd| respectively.
218218

219219
*:GinChaperon*
220-
:GinChaperon[!] [++{option}...] {path}
220+
:GinChaperon[!] [++{option}...] [{path}]
221221
Open three main buffers (THEIRS, WORKTREE, and OURS) and three
222-
supplemental buffers to solve conflicts on {path}.
222+
supplemental buffers to solve conflicts on {path}. If no {path} is
223+
specified, the default value is the current buffer.
223224

224225
The following options are valid as {++option}:
225226

@@ -343,9 +344,10 @@ COMMANDS *gin-commands*
343344
Use a bang (!) to forcibly open a buffer.
344345

345346
*:GinPatch*
346-
:GinPatch[!] [{++option}...] {path}
347+
:GinPatch[!] [{++option}...] [{path}]
347348
Open three buffers (HEAD, INDEX, and WORKTREE) to patch changes of
348-
{path}.
349+
{path}. If no {path} is specified, the default value is the current
350+
buffer.
349351

350352
The following options are valid as {++option}:
351353

0 commit comments

Comments
 (0)