feat: commit push/pull/fetch and others
This commit is contained in:
@@ -98,6 +98,11 @@ export interface GitLfsPruneResult {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface GitActionResult {
|
||||
success: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
let gitEngineInstance: GitEngine | null = null;
|
||||
|
||||
export function getGitEngine(): GitEngine {
|
||||
@@ -274,6 +279,67 @@ export class GitEngine {
|
||||
}));
|
||||
}
|
||||
|
||||
async fetch(projectPath: string): Promise<GitActionResult> {
|
||||
const git = simpleGit(projectPath);
|
||||
try {
|
||||
await git.fetch(['--prune']);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to fetch remote updates.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async pull(projectPath: string): Promise<GitActionResult> {
|
||||
const git = simpleGit(projectPath);
|
||||
try {
|
||||
await git.pull();
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to pull remote changes.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async push(projectPath: string): Promise<GitActionResult> {
|
||||
const git = simpleGit(projectPath);
|
||||
try {
|
||||
await git.push();
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to push local commits.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async commitAll(projectPath: string, message: string): Promise<GitActionResult> {
|
||||
const normalizedMessage = message.trim();
|
||||
if (!normalizedMessage) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Commit message is required.',
|
||||
};
|
||||
}
|
||||
|
||||
const git = simpleGit(projectPath);
|
||||
try {
|
||||
await git.add(['-A']);
|
||||
await git.commit(normalizedMessage);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to create commit.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async ensureGitignore(projectPath: string): Promise<GitIgnoreEnsureResult> {
|
||||
const gitignorePath = path.join(projectPath, '.gitignore');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user