@solaqua/gji 0.2.3 → 0.2.4

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/dist/go.js CHANGED
@@ -3,7 +3,7 @@ import { isCancel, select } from '@clack/prompts';
3
3
  import { loadEffectiveConfig } from './config.js';
4
4
  import { isHeadless } from './headless.js';
5
5
  import { extractHooks, runHook } from './hooks.js';
6
- import { detectRepository, listWorktrees } from './repo.js';
6
+ import { detectRepository, listWorktrees, sortByCurrentFirst } from './repo.js';
7
7
  import { writeShellOutput } from './shell-handoff.js';
8
8
  const GO_OUTPUT_FILE_ENV = 'GJI_GO_OUTPUT_FILE';
9
9
  export function createGoCommand(dependencies = {}) {
@@ -17,7 +17,7 @@ export function createGoCommand(dependencies = {}) {
17
17
  options.stderr('gji go: branch argument is required in non-interactive mode (GJI_NO_TUI=1)\n');
18
18
  return 1;
19
19
  }
20
- const prompted = options.branch ? null : await prompt(worktrees);
20
+ const prompted = options.branch ? null : await prompt(sortByCurrentFirst(worktrees));
21
21
  const resolvedPath = options.branch
22
22
  ? worktrees.find((entry) => entry.branch === options.branch)?.path
23
23
  : prompted ?? undefined;
@@ -46,7 +46,7 @@ async function promptForWorktree(worktrees) {
46
46
  options: worktrees.map((worktree) => ({
47
47
  value: worktree.path,
48
48
  label: worktree.branch ?? '(detached)',
49
- hint: worktree.path,
49
+ hint: worktree.isCurrent ? `${worktree.path} (current)` : worktree.path,
50
50
  })),
51
51
  });
52
52
  if (isCancel(choice)) {
package/dist/ls.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { listWorktrees } from './repo.js';
2
2
  import { comparePaths } from './paths.js';
3
3
  export async function runLsCommand(options) {
4
- const worktrees = sortWorktreesByPath(await listWorktrees(options.cwd));
4
+ const worktrees = sortWorktrees(await listWorktrees(options.cwd));
5
5
  if (options.json) {
6
6
  options.stdout(`${JSON.stringify(worktrees, null, 2)}\n`);
7
7
  return 0;
@@ -12,15 +12,22 @@ export async function runLsCommand(options) {
12
12
  export function formatWorktreeTable(worktrees) {
13
13
  const rows = worktrees.map((worktree) => ({
14
14
  branch: worktree.branch ?? '(detached)',
15
+ isCurrent: worktree.isCurrent,
15
16
  path: worktree.path,
16
17
  }));
17
18
  const branchWidth = Math.max('BRANCH'.length, ...rows.map((row) => row.branch.length));
18
- const lines = ['BRANCH'.padEnd(branchWidth, ' ') + ' PATH'];
19
+ const lines = [' ' + 'BRANCH'.padEnd(branchWidth, ' ') + ' PATH'];
19
20
  for (const row of rows) {
20
- lines.push(`${row.branch.padEnd(branchWidth, ' ')} ${row.path}`);
21
+ lines.push(`${row.isCurrent ? '*' : ' '} ${row.branch.padEnd(branchWidth, ' ')} ${row.path}`);
21
22
  }
22
23
  return lines.join('\n');
23
24
  }
24
- function sortWorktreesByPath(worktrees) {
25
- return [...worktrees].sort((left, right) => comparePaths(left.path, right.path));
25
+ function sortWorktrees(worktrees) {
26
+ return [...worktrees].sort((left, right) => {
27
+ if (left.isCurrent && !right.isCurrent)
28
+ return -1;
29
+ if (!left.isCurrent && right.isCurrent)
30
+ return 1;
31
+ return comparePaths(left.path, right.path);
32
+ });
26
33
  }
package/dist/remove.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { WorktreeEntry } from './repo.js';
1
+ import { type WorktreeEntry } from './repo.js';
2
2
  export interface RemoveCommandOptions {
3
3
  branch?: string;
4
4
  cwd: string;
package/dist/remove.js CHANGED
@@ -3,6 +3,7 @@ import { confirm, isCancel, select } from '@clack/prompts';
3
3
  import { loadEffectiveConfig } from './config.js';
4
4
  import { extractHooks, runHook } from './hooks.js';
5
5
  import { isHeadless } from './headless.js';
6
+ import { sortByCurrentFirst } from './repo.js';
6
7
  import { deleteBranch, forceDeleteBranch, forceRemoveWorktree, isBranchUnmergedError, isWorktreeDirtyError, loadLinkedWorktrees, removeWorktree, } from './worktree-management.js';
7
8
  import { defaultConfirmForceDeleteBranch, defaultConfirmForceRemoveWorktree } from './worktree-prompts.js';
8
9
  import { writeShellOutput } from './shell-handoff.js';
@@ -28,7 +29,7 @@ export function createRemoveCommand(dependencies = {}) {
28
29
  }
29
30
  return 1;
30
31
  }
31
- const selection = options.branch ?? (await promptForWorktree(linkedWorktrees));
32
+ const selection = options.branch ?? (await promptForWorktree(sortByCurrentFirst(linkedWorktrees)));
32
33
  if (!selection) {
33
34
  options.stderr('Aborted\n');
34
35
  return 1;
@@ -119,7 +120,7 @@ async function defaultPromptForWorktree(worktrees) {
119
120
  const choice = await select({
120
121
  message: 'Choose a worktree to finish',
121
122
  options: worktrees.map((worktree) => ({
122
- hint: worktree.path,
123
+ hint: worktree.isCurrent ? `${worktree.path} (current)` : worktree.path,
123
124
  label: worktree.branch ?? '(detached)',
124
125
  value: worktree.path,
125
126
  })),
package/dist/repo.d.ts CHANGED
@@ -7,8 +7,10 @@ export interface RepositoryContext {
7
7
  }
8
8
  export interface WorktreeEntry {
9
9
  branch: string | null;
10
+ isCurrent: boolean;
10
11
  path: string;
11
12
  }
12
13
  export declare function detectRepository(cwd: string): Promise<RepositoryContext>;
13
14
  export declare function resolveWorktreePath(repoRoot: string, branch: string): string;
14
15
  export declare function listWorktrees(cwd: string): Promise<WorktreeEntry[]>;
16
+ export declare function sortByCurrentFirst(worktrees: WorktreeEntry[]): WorktreeEntry[];
package/dist/repo.js CHANGED
@@ -26,17 +26,30 @@ export function resolveWorktreePath(repoRoot, branch) {
26
26
  return join(dirname(repoRoot), 'worktrees', basename(repoRoot), ...segments);
27
27
  }
28
28
  export async function listWorktrees(cwd) {
29
- const output = await runGit(cwd, ['worktree', 'list', '--porcelain']);
29
+ const [output, currentRoot] = await Promise.all([
30
+ runGit(cwd, ['worktree', 'list', '--porcelain']),
31
+ runGit(cwd, ['rev-parse', '--show-toplevel']),
32
+ ]);
30
33
  const entries = output.split('\n\n').filter(Boolean);
31
34
  return entries.map((entry) => {
32
35
  const path = findPorcelainValue(entry, 'worktree');
33
36
  const branchRef = findOptionalPorcelainValue(entry, 'branch');
34
37
  return {
35
38
  branch: branchRef ? branchRef.replace('refs/heads/', '') : null,
39
+ isCurrent: path === currentRoot,
36
40
  path,
37
41
  };
38
42
  });
39
43
  }
44
+ export function sortByCurrentFirst(worktrees) {
45
+ return [...worktrees].sort((a, b) => {
46
+ if (a.isCurrent && !b.isCurrent)
47
+ return -1;
48
+ if (!a.isCurrent && b.isCurrent)
49
+ return 1;
50
+ return 0;
51
+ });
52
+ }
40
53
  function findPorcelainValue(block, key) {
41
54
  const value = findOptionalPorcelainValue(block, key);
42
55
  if (!value) {
package/dist/status.js CHANGED
@@ -4,7 +4,7 @@ import { comparePaths } from './paths.js';
4
4
  export async function runStatusCommand(options) {
5
5
  const repository = await detectRepository(options.cwd);
6
6
  const worktrees = sortWorktreesByPath(await listWorktrees(options.cwd));
7
- const rows = await Promise.all(worktrees.map(async (worktree) => buildStatusRow(worktree, repository.currentRoot)));
7
+ const rows = await Promise.all(worktrees.map(async (worktree) => buildStatusRow(worktree)));
8
8
  if (options.json) {
9
9
  options.stdout(`${JSON.stringify(formatStatusJson(repository.repoRoot, repository.currentRoot, rows), null, 2)}\n`);
10
10
  return 0;
@@ -35,11 +35,11 @@ export function formatStatusJson(repoRoot, currentRoot, rows) {
35
35
  worktrees: rows,
36
36
  };
37
37
  }
38
- async function buildStatusRow(worktree, currentRoot) {
38
+ async function buildStatusRow(worktree) {
39
39
  const health = await readWorktreeHealth(worktree.path);
40
40
  return {
41
41
  branch: worktree.branch,
42
- current: worktree.path === currentRoot,
42
+ current: worktree.isCurrent,
43
43
  path: worktree.path,
44
44
  status: health.status,
45
45
  upstream: buildUpstreamState(worktree.branch, health),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solaqua/gji",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Git worktree CLI for fast context switching.",
5
5
  "license": "MIT",
6
6
  "author": "sjquant",