Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 150 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"wait-on": "^8.0.4"
},
"dependencies": {
"@git-diff-view/react": "^0.0.30",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.1.15",
"@radix-ui/react-popover": "^1.0.7",
Expand Down
106 changes: 106 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,98 @@ ipcMain.handle('git:worktree-list', async (_, projectPath: string) => {
});
});

// Git diff and status operations
ipcMain.handle('git:status', async (_, worktreePath: string) => {
return new Promise((resolve, reject) => {
const child = spawn('git', ['status', '--porcelain=v1'], {
cwd: worktreePath
});

let stdout = '';
let stderr = '';

child.stdout.on('data', (data) => {
stdout += data.toString();
});

child.stderr.on('data', (data) => {
stderr += data.toString();
});

child.on('close', (code) => {
if (code === 0) {
resolve(parseGitStatus(stdout));
} else {
reject(new Error(stderr || 'Failed to get git status'));
}
});
});
});

ipcMain.handle('git:diff', async (_, worktreePath: string, filePath?: string) => {
return new Promise((resolve, reject) => {
const args = ['diff'];
if (filePath) {
args.push(filePath);
}

const child = spawn('git', args, {
cwd: worktreePath
});

let stdout = '';
let stderr = '';

child.stdout.on('data', (data) => {
stdout += data.toString();
});

child.stderr.on('data', (data) => {
stderr += data.toString();
});

child.on('close', (code) => {
if (code === 0) {
resolve(stdout);
} else {
reject(new Error(stderr || 'Failed to get git diff'));
}
});
});
});

ipcMain.handle('git:diff-staged', async (_, worktreePath: string, filePath?: string) => {
return new Promise((resolve, reject) => {
const args = ['diff', '--staged'];
if (filePath) {
args.push(filePath);
}

const child = spawn('git', args, {
cwd: worktreePath
});

let stdout = '';
let stderr = '';

child.stdout.on('data', (data) => {
stdout += data.toString();
});

child.stderr.on('data', (data) => {
stderr += data.toString();
});

child.on('close', (code) => {
if (code === 0) {
resolve(stdout);
} else {
reject(new Error(stderr || 'Failed to get staged git diff'));
}
});
});
});

ipcMain.handle('git:worktree-add', async (_, projectPath: string, branchName: string) => {
const worktreePath = path.join(projectPath, '..', `${path.basename(projectPath)}-${branchName}`);

Expand Down Expand Up @@ -150,4 +242,18 @@ function parseWorktrees(output: string): Array<{ path: string; branch: string; h
}

return worktrees;
}

function parseGitStatus(output: string): Array<{ path: string; status: string; staged: boolean; modified: boolean }> {
const lines = output.trim().split('\n').filter(line => line.length > 0);
return lines.map(line => {
const status = line.substring(0, 2);
const path = line.substring(3);
return {
path,
status,
staged: status[0] !== ' ' && status[0] !== '?',
modified: status[1] !== ' ' && status[1] !== '?'
};
});
}
6 changes: 6 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const api = {
ipcRenderer.invoke('git:worktree-list', projectPath),
addWorktree: (projectPath: string, branchName: string) =>
ipcRenderer.invoke('git:worktree-add', projectPath, branchName),
status: (worktreePath: string) =>
ipcRenderer.invoke('git:status', worktreePath),
diff: (worktreePath: string, filePath?: string) =>
ipcRenderer.invoke('git:diff', worktreePath, filePath),
diffStaged: (worktreePath: string, filePath?: string) =>
ipcRenderer.invoke('git:diff-staged', worktreePath, filePath),
},
shell: {
start: (worktreePath: string, cols?: number, rows?: number) =>
Expand Down
Loading