Skip to content

Commit 70b05f9

Browse files
Merge pull request #6 from Krishnachaitanyakc/main
2 parents fe71c44 + 7b24ae1 commit 70b05f9

File tree

8 files changed

+559
-5
lines changed

8 files changed

+559
-5
lines changed

package-lock.json

Lines changed: 150 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"wait-on": "^8.0.4"
5252
},
5353
"dependencies": {
54+
"@git-diff-view/react": "^0.0.30",
5455
"@radix-ui/react-dialog": "^1.0.5",
5556
"@radix-ui/react-dropdown-menu": "^2.1.15",
5657
"@radix-ui/react-popover": "^1.0.7",

src/main/index.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,98 @@ ipcMain.handle('git:worktree-list', async (_, projectPath: string) => {
8484
});
8585
});
8686

87+
// Git diff and status operations
88+
ipcMain.handle('git:status', async (_, worktreePath: string) => {
89+
return new Promise((resolve, reject) => {
90+
const child = spawn('git', ['status', '--porcelain=v1'], {
91+
cwd: worktreePath
92+
});
93+
94+
let stdout = '';
95+
let stderr = '';
96+
97+
child.stdout.on('data', (data) => {
98+
stdout += data.toString();
99+
});
100+
101+
child.stderr.on('data', (data) => {
102+
stderr += data.toString();
103+
});
104+
105+
child.on('close', (code) => {
106+
if (code === 0) {
107+
resolve(parseGitStatus(stdout));
108+
} else {
109+
reject(new Error(stderr || 'Failed to get git status'));
110+
}
111+
});
112+
});
113+
});
114+
115+
ipcMain.handle('git:diff', async (_, worktreePath: string, filePath?: string) => {
116+
return new Promise((resolve, reject) => {
117+
const args = ['diff'];
118+
if (filePath) {
119+
args.push(filePath);
120+
}
121+
122+
const child = spawn('git', args, {
123+
cwd: worktreePath
124+
});
125+
126+
let stdout = '';
127+
let stderr = '';
128+
129+
child.stdout.on('data', (data) => {
130+
stdout += data.toString();
131+
});
132+
133+
child.stderr.on('data', (data) => {
134+
stderr += data.toString();
135+
});
136+
137+
child.on('close', (code) => {
138+
if (code === 0) {
139+
resolve(stdout);
140+
} else {
141+
reject(new Error(stderr || 'Failed to get git diff'));
142+
}
143+
});
144+
});
145+
});
146+
147+
ipcMain.handle('git:diff-staged', async (_, worktreePath: string, filePath?: string) => {
148+
return new Promise((resolve, reject) => {
149+
const args = ['diff', '--staged'];
150+
if (filePath) {
151+
args.push(filePath);
152+
}
153+
154+
const child = spawn('git', args, {
155+
cwd: worktreePath
156+
});
157+
158+
let stdout = '';
159+
let stderr = '';
160+
161+
child.stdout.on('data', (data) => {
162+
stdout += data.toString();
163+
});
164+
165+
child.stderr.on('data', (data) => {
166+
stderr += data.toString();
167+
});
168+
169+
child.on('close', (code) => {
170+
if (code === 0) {
171+
resolve(stdout);
172+
} else {
173+
reject(new Error(stderr || 'Failed to get staged git diff'));
174+
}
175+
});
176+
});
177+
});
178+
87179
ipcMain.handle('git:worktree-add', async (_, projectPath: string, branchName: string) => {
88180
const worktreePath = path.join(projectPath, '..', `${path.basename(projectPath)}-${branchName}`);
89181

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

152244
return worktrees;
245+
}
246+
247+
function parseGitStatus(output: string): Array<{ path: string; status: string; staged: boolean; modified: boolean }> {
248+
const lines = output.trim().split('\n').filter(line => line.length > 0);
249+
return lines.map(line => {
250+
const status = line.substring(0, 2);
251+
const path = line.substring(3);
252+
return {
253+
path,
254+
status,
255+
staged: status[0] !== ' ' && status[0] !== '?',
256+
modified: status[1] !== ' ' && status[1] !== '?'
257+
};
258+
});
153259
}

src/preload/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ const api = {
66
ipcRenderer.invoke('git:worktree-list', projectPath),
77
addWorktree: (projectPath: string, branchName: string) =>
88
ipcRenderer.invoke('git:worktree-add', projectPath, branchName),
9+
status: (worktreePath: string) =>
10+
ipcRenderer.invoke('git:status', worktreePath),
11+
diff: (worktreePath: string, filePath?: string) =>
12+
ipcRenderer.invoke('git:diff', worktreePath, filePath),
13+
diffStaged: (worktreePath: string, filePath?: string) =>
14+
ipcRenderer.invoke('git:diff-staged', worktreePath, filePath),
915
},
1016
shell: {
1117
start: (worktreePath: string, cols?: number, rows?: number) =>

0 commit comments

Comments
 (0)