@solaqua/gji 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -11
- package/dist/clean.d.ts +1 -0
- package/dist/clean.js +103 -13
- package/dist/cli.js +62 -4
- package/dist/completion.d.ts +6 -0
- package/dist/completion.js +11 -0
- package/dist/config.js +1 -0
- package/dist/git.d.ts +3 -0
- package/dist/git.js +38 -0
- package/dist/gji +5 -0
- package/dist/gji-bundle.mjs +16536 -0
- package/dist/index.js +25 -1
- package/dist/init.d.ts +12 -2
- package/dist/init.js +100 -37
- package/dist/ls.d.ts +3 -0
- package/dist/ls.js +46 -2
- package/dist/pr.js +43 -1
- package/dist/shell-completion.d.ts +1 -0
- package/dist/shell-completion.js +284 -0
- package/dist/shell.d.ts +2 -0
- package/dist/shell.js +21 -0
- package/dist/sync.js +2 -13
- package/dist/worktree-info.d.ts +33 -0
- package/dist/worktree-info.js +105 -0
- package/man/man1/gji-clean.1 +22 -0
- package/man/man1/gji-completion.1 +9 -0
- package/man/man1/gji-config.1 +19 -0
- package/man/man1/gji-go.1 +13 -0
- package/man/man1/gji-init.1 +13 -0
- package/man/man1/gji-ls.1 +16 -0
- package/man/man1/gji-new.1 +22 -0
- package/man/man1/gji-pr.1 +16 -0
- package/man/man1/gji-remove.1 +19 -0
- package/man/man1/gji-root.1 +13 -0
- package/man/man1/gji-status.1 +13 -0
- package/man/man1/gji-sync.1 +16 -0
- package/man/man1/gji-trigger-hook.1 +9 -0
- package/man/man1/gji.1 +71 -0
- package/package.json +17 -3
package/dist/git.js
CHANGED
|
@@ -19,6 +19,39 @@ export async function isDirtyWorktree(cwd) {
|
|
|
19
19
|
const health = await readWorktreeHealth(cwd);
|
|
20
20
|
return health.status === 'dirty';
|
|
21
21
|
}
|
|
22
|
+
export async function isBranchMergedInto(cwd, branch, base = 'HEAD') {
|
|
23
|
+
try {
|
|
24
|
+
await execFileAsync('git', ['merge-base', '--is-ancestor', branch, base], { cwd });
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (hasExitCode(error, 1)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export async function resolveRemoteDefaultBranch(cwd, remote) {
|
|
35
|
+
const { stdout } = await execFileAsync('git', ['ls-remote', '--symref', remote, 'HEAD'], { cwd });
|
|
36
|
+
const refLine = stdout
|
|
37
|
+
.split('\n')
|
|
38
|
+
.find((line) => line.startsWith('ref: refs/heads/'));
|
|
39
|
+
if (!refLine) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const match = /^ref: refs\/heads\/(.+)\tHEAD$/.exec(refLine);
|
|
43
|
+
return match?.[1] ?? null;
|
|
44
|
+
}
|
|
45
|
+
export async function readBranchLastCommitTimestamp(cwd, branch) {
|
|
46
|
+
try {
|
|
47
|
+
const { stdout } = await execFileAsync('git', ['log', '-1', '--format=%ct', branch], { cwd });
|
|
48
|
+
const timestamp = Number(stdout.trim());
|
|
49
|
+
return Number.isFinite(timestamp) ? timestamp : null;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
22
55
|
function parseWorktreeHealth(output) {
|
|
23
56
|
let ahead = 0;
|
|
24
57
|
let behind = 0;
|
|
@@ -52,3 +85,8 @@ function parseWorktreeHealth(output) {
|
|
|
52
85
|
status: dirty ? 'dirty' : 'clean',
|
|
53
86
|
};
|
|
54
87
|
}
|
|
88
|
+
function hasExitCode(error, code) {
|
|
89
|
+
return error instanceof Error
|
|
90
|
+
&& 'code' in error
|
|
91
|
+
&& error.code === code;
|
|
92
|
+
}
|