UNPKG

@akiojin/claude-worktree

Version:

Interactive Git worktree manager for Claude Code with graphical branch selection

95 lines 3.21 kB
/** * Git操作のビジネスロジックを管理するService */ export class GitService { repository; constructor(repository) { this.repository = repository; } async isValidRepository() { return await this.repository.isRepository(); } async getAllBranches() { const [localBranches, remoteBranches, currentBranch] = await Promise.all([ this.getLocalBranchesInfo(), this.getRemoteBranchesInfo(), this.repository.getCurrentBranch() ]); // 現在のブランチ情報を設定 if (currentBranch) { localBranches.forEach(branch => { if (branch.name === currentBranch) { branch.isCurrent = true; } }); } return [...localBranches, ...remoteBranches]; } async getLocalBranchesInfo() { const branches = await this.repository.getBranches({ remote: false }); return branches.map(name => ({ name, type: 'local', branchType: this.getBranchType(name), isCurrent: false })); } async getRemoteBranchesInfo() { const branches = await this.repository.getBranches({ remote: true }); return branches.map(name => ({ name, type: 'remote', branchType: this.getBranchType(name.replace(/^origin\//, '')), isCurrent: false })); } getBranchType(branchName) { if (branchName.startsWith('feature/')) return 'feature'; if (branchName.startsWith('hotfix/')) return 'hotfix'; if (branchName.startsWith('release/')) return 'release'; if (branchName === 'main' || branchName === 'master') return 'main'; if (branchName === 'develop' || branchName === 'dev') return 'develop'; return 'other'; } async createFeatureBranch(taskName, baseBranch) { const branchName = `feature/${taskName}`; await this.repository.createBranch(branchName, baseBranch); return branchName; } async deleteBranch(branchName, options) { if (options?.remote) { await this.repository.deleteRemoteBranch(branchName); } else { await this.repository.deleteBranch(branchName, options?.force); } } async hasUncommittedChanges(workdir) { return await this.repository.hasChanges(workdir); } async getChangedFilesCount(workdir) { return await this.repository.getChangedFilesCount(workdir); } async commitAllChanges(message) { await this.repository.add('.'); await this.repository.commit(message, { all: true }); } async pushChanges(branchName) { await this.repository.push({ upstream: true, branch: branchName }); } async stashChanges(message) { await this.repository.stash(message); } async discardAllChanges() { await this.repository.checkout('.'); } async fetchRemoteUpdates() { await this.repository.fetch({ all: true, prune: true }); } } //# sourceMappingURL=git.service.js.map