yggtree 1.2.1 → 1.4.0
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 +118 -13
- package/dist/commands/wt/apply.js +7 -3
- package/dist/commands/wt/create-branch.js +40 -20
- package/dist/commands/wt/create-multi.js +13 -10
- package/dist/commands/wt/create-sandbox.js +63 -10
- package/dist/commands/wt/create.js +157 -57
- package/dist/commands/wt/delete.js +45 -17
- package/dist/commands/wt/enter.js +43 -31
- package/dist/commands/wt/exec.js +4 -17
- package/dist/commands/wt/list.js +29 -19
- package/dist/commands/wt/open.js +245 -0
- package/dist/commands/wt/path.js +4 -17
- package/dist/index.js +66 -25
- package/dist/lib/config.js +17 -4
- package/dist/lib/git.js +63 -13
- package/dist/lib/prompt.js +9 -0
- package/dist/lib/sandbox.js +19 -3
- package/dist/lib/ui.js +20 -0
- package/dist/lib/worktree.js +52 -0
- package/package.json +2 -1
- package/dist/commands/wt/leave.js +0 -13
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { WORKTREES_ROOT } from './paths.js';
|
|
5
|
+
import { getSandboxMetaPath } from './sandbox.js';
|
|
6
|
+
export const WORKTREE_TYPE_ORDER = {
|
|
7
|
+
MAIN: 0,
|
|
8
|
+
MANAGED: 1,
|
|
9
|
+
SANDBOX: 2,
|
|
10
|
+
LINKED: 3,
|
|
11
|
+
};
|
|
12
|
+
export function getWorktreeBranchName(worktree) {
|
|
13
|
+
return worktree.branch || worktree.HEAD || 'detached';
|
|
14
|
+
}
|
|
15
|
+
export function isManagedWorktreePath(worktreePath) {
|
|
16
|
+
return worktreePath.startsWith(WORKTREES_ROOT);
|
|
17
|
+
}
|
|
18
|
+
export function formatWorktreeDisplayPath(worktreePath) {
|
|
19
|
+
if (isManagedWorktreePath(worktreePath)) {
|
|
20
|
+
return path.relative(WORKTREES_ROOT, worktreePath);
|
|
21
|
+
}
|
|
22
|
+
return worktreePath.replace(process.env.HOME || '', '~');
|
|
23
|
+
}
|
|
24
|
+
export function findWorktreeByName(worktrees, worktreeName) {
|
|
25
|
+
return worktrees.find(worktree => {
|
|
26
|
+
const branchName = getWorktreeBranchName(worktree);
|
|
27
|
+
const relativePath = path.relative(WORKTREES_ROOT, worktree.path);
|
|
28
|
+
const basename = path.basename(worktree.path);
|
|
29
|
+
return branchName === worktreeName ||
|
|
30
|
+
relativePath === worktreeName ||
|
|
31
|
+
worktree.path === worktreeName ||
|
|
32
|
+
basename === worktreeName;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export async function detectWorktreeType(worktree, mainWorktreePath) {
|
|
36
|
+
const isManaged = isManagedWorktreePath(worktree.path);
|
|
37
|
+
if (!isManaged) {
|
|
38
|
+
return worktree.path === mainWorktreePath ? 'MAIN' : 'LINKED';
|
|
39
|
+
}
|
|
40
|
+
const hasSandboxMeta = await fs.pathExists(getSandboxMetaPath(worktree.path));
|
|
41
|
+
const isSandboxBranch = (worktree.branch || '').startsWith('sandbox-');
|
|
42
|
+
return hasSandboxMeta || isSandboxBranch ? 'SANDBOX' : 'MANAGED';
|
|
43
|
+
}
|
|
44
|
+
export function formatWorktreeType(type) {
|
|
45
|
+
if (type === 'SANDBOX')
|
|
46
|
+
return chalk.magenta('SANDBOX');
|
|
47
|
+
if (type === 'MANAGED')
|
|
48
|
+
return chalk.green('MANAGED');
|
|
49
|
+
if (type === 'MAIN')
|
|
50
|
+
return chalk.blue('MAIN ');
|
|
51
|
+
return chalk.cyan('LINKED ');
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yggtree",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Interactive CLI for managing git worktrees and configs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"fs-extra": "^11.2.0",
|
|
35
35
|
"gradient-string": "^2.0.2",
|
|
36
36
|
"inquirer": "^9.2.14",
|
|
37
|
+
"inquirer-autocomplete-prompt": "^3.0.1",
|
|
37
38
|
"ora": "^8.0.1",
|
|
38
39
|
"zod": "^3.22.4"
|
|
39
40
|
},
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { log } from '../../lib/ui.js';
|
|
2
|
-
export async function leaveCommand() {
|
|
3
|
-
if (process.env.YGGTREE_SHELL === 'true') {
|
|
4
|
-
log.info('Leaving worktree sub-shell...');
|
|
5
|
-
// SIGHUP is standard for closing shells
|
|
6
|
-
process.kill(process.ppid, 'SIGHUP');
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
log.warning('You are not in a yggtree sub-shell.');
|
|
10
|
-
log.dim('Try using "yggtree wt enter" first.');
|
|
11
|
-
process.exit(0);
|
|
12
|
-
}
|
|
13
|
-
}
|