@akiojin/claude-worktree
Version:
Interactive Git worktree manager for Claude Code with graphical branch selection
57 lines • 1.88 kB
JavaScript
import { execa } from 'execa';
import { WorktreeError } from '../worktree.js';
/**
* Git Worktree操作のための低レベルRepository
*/
export class WorktreeRepository {
async execute(args, options) {
try {
const { stdout } = await execa('git', ['worktree', ...args], options);
return stdout;
}
catch (error) {
throw new WorktreeError(`Worktree command failed: git worktree ${args.join(' ')}`, error);
}
}
async list() {
const stdout = await this.execute(['list', '--porcelain']);
const worktrees = [];
const lines = stdout.split('\n');
let currentWorktree = {};
for (const line of lines) {
if (line.startsWith('worktree ')) {
currentWorktree.path = line.substring(9);
}
else if (line.startsWith('HEAD ')) {
currentWorktree.head = line.substring(5);
}
else if (line.startsWith('branch ')) {
currentWorktree.branch = line.substring(7).replace('refs/heads/', '');
}
else if (line === '') {
if (currentWorktree.path) {
worktrees.push(currentWorktree);
currentWorktree = {};
}
}
}
if (currentWorktree.path) {
worktrees.push(currentWorktree);
}
return worktrees;
}
async add(worktreePath, branchName) {
await this.execute(['add', worktreePath, branchName]);
}
async remove(worktreePath, force = false) {
const args = ['remove'];
if (force)
args.push('--force');
args.push(worktreePath);
await this.execute(args);
}
async prune() {
await this.execute(['prune']);
}
}
//# sourceMappingURL=worktree.repository.js.map