mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
make GitCommitTool accept git instance
This commit is contained in:
5 files changed
+12
-16
No files matched your search
@@ -92,7 +92,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
const customTools = useMemo(() => {
|
||||
const git = new Git(fs);
|
||||
const baseTools = {
|
||||
git_commit: new GitCommitTool(fs, cwd),
|
||||
git_commit: new GitCommitTool(fs, cwd, git),
|
||||
text_editor_view: new TextEditorViewTool(fs, cwd),
|
||||
text_editor_write: new TextEditorWriteTool(fs, cwd),
|
||||
text_editor_str_replace: new TextEditorStrReplaceTool(fs, cwd),
|
||||
|
||||
@@ -57,15 +57,10 @@ export class GitCloneCommand implements GitSubcommand {
|
||||
|
||||
// Clone the repository
|
||||
await this.git.clone({
|
||||
|
||||
http,
|
||||
dir: targetPath,
|
||||
url: repository,
|
||||
singleBranch: options.singleBranch,
|
||||
depth: options.depth,
|
||||
corsProxy: (url.hostname === 'github.com' || url.hostname === 'gitlab.com')
|
||||
? 'https://cors.isomorphic-git.org'
|
||||
: undefined,
|
||||
});
|
||||
|
||||
return createSuccessResult(`Cloning into '${targetDir}'...\ndone.\n`);
|
||||
|
||||
@@ -56,12 +56,12 @@ export class GitCommitCommand implements GitSubcommand {
|
||||
|
||||
try {
|
||||
const configName = await this.git.getConfig({
|
||||
|
||||
|
||||
dir: this.pwd,
|
||||
path: 'user.name',
|
||||
});
|
||||
const configEmail = await this.git.getConfig({
|
||||
|
||||
|
||||
dir: this.pwd,
|
||||
path: 'user.email',
|
||||
});
|
||||
@@ -76,7 +76,7 @@ export class GitCommitCommand implements GitSubcommand {
|
||||
// Get the last commit message if amending
|
||||
try {
|
||||
const commits = await this.git.log({
|
||||
|
||||
|
||||
dir: this.pwd,
|
||||
depth: 1,
|
||||
});
|
||||
@@ -95,7 +95,7 @@ export class GitCommitCommand implements GitSubcommand {
|
||||
let currentBranch = 'main';
|
||||
try {
|
||||
currentBranch = await this.git.currentBranch({
|
||||
|
||||
|
||||
dir: this.pwd,
|
||||
}) || 'main';
|
||||
} catch {
|
||||
@@ -103,8 +103,7 @@ export class GitCommitCommand implements GitSubcommand {
|
||||
}
|
||||
|
||||
// Create the commit
|
||||
const commitOptions: {
|
||||
fs: JSRuntimeFS;
|
||||
let commitOptions: {
|
||||
dir: string;
|
||||
message: string;
|
||||
author: { name: string; email: string };
|
||||
@@ -121,7 +120,6 @@ export class GitCommitCommand implements GitSubcommand {
|
||||
// For amend, we need to reset to the parent of the current commit
|
||||
try {
|
||||
const commits = await this.git.log({
|
||||
|
||||
dir: this.pwd,
|
||||
depth: 2,
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { GitCommitTool } from './GitCommitTool';
|
||||
import { Git } from '../git';
|
||||
import type { JSRuntimeFS } from '../JSRuntime';
|
||||
|
||||
// Mock the Git class
|
||||
@@ -33,10 +34,12 @@ const mockFS: JSRuntimeFS = {
|
||||
|
||||
describe('GitCommitTool', () => {
|
||||
let tool: GitCommitTool;
|
||||
let mockGit: Git;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
tool = new GitCommitTool(mockFS, '/test/project');
|
||||
mockGit = mockGitInstance as unknown as Git;
|
||||
tool = new GitCommitTool(mockFS, '/test/project', mockGit);
|
||||
|
||||
// Setup default mocks
|
||||
mockGitInstance.statusMatrix.mockResolvedValue([
|
||||
|
||||
@@ -19,9 +19,9 @@ export class GitCommitTool implements Tool<GitCommitParams> {
|
||||
message: z.string().describe('Commit message text'),
|
||||
});
|
||||
|
||||
constructor(fs: JSRuntimeFS, cwd: string) {
|
||||
constructor(fs: JSRuntimeFS, cwd: string, git: Git) {
|
||||
this.fs = fs;
|
||||
this.git = new Git(fs);
|
||||
this.git = git;
|
||||
this.cwd = cwd;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user