Skip to content

Commit c6ed225

Browse files
zhanbapochi-agent
andauthored
refactor(vscode): change latestCheckpoint to worktree scope (#1007)
- Scope checkpoint commit messages with current working directory - Update ShadowGitRepo to filter latest commit by grep pattern - Remove unused getLatestCommitHash from CheckpointService 🤖 Generated with [Pochi](https://getpochi.com) Co-authored-by: Pochi <[email protected]>
1 parent d80918b commit c6ed225

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

packages/vscode/src/integrations/checkpoint/checkpoint-service.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { filterGitChanges, processGitChangesToFileEdits } from "./util";
2020

2121
const logger = getLogger("CheckpointService");
2222

23+
const checkpointCommitPrefix = (cwd: string) => `checkpoint-${cwd}-msg-`;
24+
2325
@scoped(Lifecycle.ContainerScoped)
2426
@injectable()
2527
export class CheckpointService implements vscode.Disposable {
@@ -60,7 +62,9 @@ export class CheckpointService implements vscode.Disposable {
6062
const gitPath = await this.getShadowGitPath();
6163
this.shadowGit = await ShadowGitRepo.getOrCreate(gitPath, this.cwd);
6264
logger.trace("Shadow Git repository initialized at", gitPath);
63-
this.latestCheckpoint.value = await this.shadowGit.getLatestCommitHash();
65+
this.latestCheckpoint.value = await this.shadowGit.getLatestCommitHash(
66+
checkpointCommitPrefix(this.cwd),
67+
);
6468
this.readyDefer.resolve();
6569
} catch (error) {
6670
const errorMessage = toErrorMessage(error);
@@ -94,7 +98,7 @@ export class CheckpointService implements vscode.Disposable {
9498
return null;
9599
}
96100
await this.shadowGit.stageAll();
97-
const commitMessage = `checkpoint-${message}`;
101+
const commitMessage = `${checkpointCommitPrefix(this.cwd)}${message}`;
98102
const commitHash = await this.shadowGit.commit(commitMessage);
99103
logger.trace(
100104
`Successfully saved checkpoint with message: ${message}, commit hash: ${commitHash}`,
@@ -182,14 +186,6 @@ export class CheckpointService implements vscode.Disposable {
182186
return checkpointDir;
183187
}
184188

185-
async getLatestCommitHash() {
186-
await this.ensureInitialized();
187-
if (!this.shadowGit) {
188-
throw new Error("Shadow Git repository not initialized");
189-
}
190-
return this.shadowGit.getLatestCommitHash();
191-
}
192-
193189
getCheckpointChanges = async (
194190
from: string,
195191
to?: string,

packages/vscode/src/integrations/checkpoint/shadow-git-repo.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,16 @@ export class ShadowGitRepo implements vscode.Disposable {
120120
}
121121

122122
// Get the latest commit hash in short form
123-
async getLatestCommitHash(): Promise<string | null> {
123+
async getLatestCommitHash(search: string): Promise<string | null> {
124124
try {
125-
const hash = await this.git.raw(["log", "-1", "--format=%h"]);
126-
const trimmedHash = hash.trim();
125+
const result = await this.git.raw([
126+
"log",
127+
"-1",
128+
"--oneline",
129+
"--grep",
130+
search,
131+
]);
132+
const trimmedHash = result.split(/\s+/)[0].trim();
127133
logger.debug(`Latest commit hash: ${trimmedHash}`);
128134
return trimmedHash || null;
129135
} catch (error) {

0 commit comments

Comments
 (0)