mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
fix: serialize git status/stage/commit/log results for IPC transfer
simple-git returns objects with Map/Set fields that cannot be cloned over Electron IPC. Flatten all git operation results into plain JSON-serializable objects to fix 'An object could not be cloned' error.
This commit is contained in:
@@ -7,9 +7,20 @@ function getGitInstance(dir) {
|
|||||||
async function getStatus(dir) {
|
async function getStatus(dir) {
|
||||||
try {
|
try {
|
||||||
const git = getGitInstance(dir);
|
const git = getGitInstance(dir);
|
||||||
return await git.status();
|
const result = await git.status();
|
||||||
|
const files = [];
|
||||||
|
for (const [filePath, status] of Object.entries(result.files || {})) {
|
||||||
|
files.push({
|
||||||
|
filePath,
|
||||||
|
status: status.working_dir === 'M' ? 'modified'
|
||||||
|
: status.working_dir === 'A' || status.index === 'A' ? 'added'
|
||||||
|
: status.working_dir === 'D' || status.index === 'D' ? 'deleted'
|
||||||
|
: 'untracked',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { files };
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
return { error: 'Not a git repository' };
|
return { files: [], error: 'Not a git repository' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,16 +28,25 @@ async function stage(dir, files) {
|
|||||||
try {
|
try {
|
||||||
const git = getGitInstance(dir);
|
const git = getGitInstance(dir);
|
||||||
await git.add(files);
|
await git.add(files);
|
||||||
return await git.status();
|
const result = await git.status();
|
||||||
|
const staged = [];
|
||||||
|
for (const [filePath, status] of Object.entries(result.files || {})) {
|
||||||
|
staged.push({
|
||||||
|
filePath,
|
||||||
|
status: status.index === 'A' ? 'added' : status.index === 'M' ? 'modified' : status.index === 'D' ? 'deleted' : 'untracked',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { files: staged };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { error: err.message };
|
return { files: [], error: err.message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function commit(dir, message) {
|
async function commit(dir, message) {
|
||||||
try {
|
try {
|
||||||
const git = getGitInstance(dir);
|
const git = getGitInstance(dir);
|
||||||
return await git.commit(message);
|
const result = await git.commit(message);
|
||||||
|
return { summary: result?.summary || 'Committed' };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { error: err.message };
|
return { error: err.message };
|
||||||
}
|
}
|
||||||
@@ -35,9 +55,18 @@ async function commit(dir, message) {
|
|||||||
async function log(dir, maxCount = 20) {
|
async function log(dir, maxCount = 20) {
|
||||||
try {
|
try {
|
||||||
const git = getGitInstance(dir);
|
const git = getGitInstance(dir);
|
||||||
return await git.log({ maxCount });
|
const result = await git.log({ maxCount });
|
||||||
|
return {
|
||||||
|
latest: result?.latest || null,
|
||||||
|
all: (result?.all || []).map((entry) => ({
|
||||||
|
hash: entry.hash,
|
||||||
|
message: entry.message,
|
||||||
|
author: entry.author_name,
|
||||||
|
date: entry.date,
|
||||||
|
})),
|
||||||
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { error: err.message };
|
return { all: [], error: err.message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user