@@ -5,6 +5,7 @@ import { publicProcedure, router } from "../trpc";
55import { isUpstreamMissingError } from "./git-utils" ;
66import { assertRegisteredWorktree } from "./security" ;
77import { fetchGitHubPRStatus } from "./github" ;
8+ import { gitCache } from "./cache" ;
89import {
910 createGit ,
1011 createGitForNetwork ,
@@ -31,6 +32,12 @@ async function hasUpstreamBranch(
3132/** Protected branches that should not be force-pushed to */
3233const PROTECTED_BRANCHES = [ "main" , "master" , "develop" , "production" , "staging" ] ;
3334
35+ function invalidateGitStateCaches ( worktreePath : string ) : void {
36+ gitCache . invalidateStatus ( worktreePath ) ;
37+ gitCache . invalidateParsedDiff ( worktreePath ) ;
38+ gitCache . invalidateAllFileContents ( worktreePath ) ;
39+ }
40+
3441export const createGitOperationsRouter = ( ) => {
3542 return router ( {
3643 // NOTE: saveFile is defined in file-contents.ts with hardened path validation
@@ -50,6 +57,7 @@ export const createGitOperationsRouter = () => {
5057 await withLockRetry ( input . worktreePath , ( ) =>
5158 git . fetch ( [ "--all" , "--prune" ] )
5259 ) ;
60+ invalidateGitStateCaches ( input . worktreePath ) ;
5361 return { success : true } ;
5462 } ) ;
5563 } ) ,
@@ -76,6 +84,7 @@ export const createGitOperationsRouter = () => {
7684 await withLockRetry ( input . worktreePath , ( ) =>
7785 git . checkout ( input . branch )
7886 ) ;
87+ invalidateGitStateCaches ( input . worktreePath ) ;
7988 return { success : true } ;
8089 } ) ;
8190 } ) ,
@@ -98,6 +107,7 @@ export const createGitOperationsRouter = () => {
98107 author : string ;
99108 email : string ;
100109 date : Date ;
110+ tags : string [ ] ;
101111 } >
102112 > => {
103113 assertRegisteredWorktree ( input . worktreePath ) ;
@@ -106,7 +116,7 @@ export const createGitOperationsRouter = () => {
106116 const logOutput = await git . raw ( [
107117 "log" ,
108118 `-${ input . limit } ` ,
109- "--format=%H|%h|%s|%an|%ae|%aI" ,
119+ "--format=%H|%h|%s|%an|%ae|%aI|%D " ,
110120 ] ) ;
111121
112122 if ( ! logOutput . trim ( ) ) return [ ] ;
@@ -115,15 +125,22 @@ export const createGitOperationsRouter = () => {
115125 . trim ( )
116126 . split ( "\n" )
117127 . map ( ( line ) => {
118- const [ hash , shortHash , message , author , email , dateStr ] =
128+ const [ hash , shortHash , message , author , email , dateStr , refs ] =
119129 line . split ( "|" ) ;
130+ // Extract tags from ref names (format: "HEAD -> main, tag: v1.0.0, origin/main")
131+ const tags = ( refs || "" )
132+ . split ( "," )
133+ . map ( ( r ) => r . trim ( ) )
134+ . filter ( ( r ) => r . startsWith ( "tag: " ) )
135+ . map ( ( r ) => r . replace ( "tag: " , "" ) ) ;
120136 return {
121137 hash : hash || "" ,
122138 shortHash : shortHash || "" ,
123139 message : message || "" ,
124140 author : author || "" ,
125141 email : email || "" ,
126142 date : new Date ( dateStr || "" ) ,
143+ tags,
127144 } ;
128145 } ) ;
129146 } ,
@@ -157,6 +174,7 @@ export const createGitOperationsRouter = () => {
157174 const result = await withLockRetry ( input . worktreePath , ( ) =>
158175 git . commit ( input . message )
159176 ) ;
177+ invalidateGitStateCaches ( input . worktreePath ) ;
160178 return { success : true , hash : result . commit } ;
161179 } ) ;
162180 } ,
@@ -209,6 +227,7 @@ export const createGitOperationsRouter = () => {
209227 git . commit ( input . message )
210228 ) ;
211229
230+ invalidateGitStateCaches ( input . worktreePath ) ;
212231 return { success : true , hash : result . commit } ;
213232 } ) ;
214233 } ,
@@ -237,6 +256,7 @@ export const createGitOperationsRouter = () => {
237256 await withLockRetry ( input . worktreePath , ( ) => git . push ( ) ) ;
238257 }
239258 await git . fetch ( ) ;
259+ invalidateGitStateCaches ( input . worktreePath ) ;
240260 return { success : true } ;
241261 } ) ;
242262 } ) ,
@@ -309,6 +329,7 @@ export const createGitOperationsRouter = () => {
309329 }
310330 throw error ;
311331 }
332+ invalidateGitStateCaches ( input . worktreePath ) ;
312333 return { success : true } ;
313334 } ) ;
314335 } ) ,
@@ -369,6 +390,7 @@ export const createGitOperationsRouter = () => {
369390 git . push ( [ "--set-upstream" , "origin" , branch . trim ( ) ] )
370391 ) ;
371392 await git . fetch ( ) ;
393+ invalidateGitStateCaches ( input . worktreePath ) ;
372394 return { success : true } ;
373395 }
374396 // Check for rebase conflicts
@@ -382,6 +404,7 @@ export const createGitOperationsRouter = () => {
382404 }
383405 await withLockRetry ( input . worktreePath , ( ) => git . push ( ) ) ;
384406 await git . fetch ( ) ;
407+ invalidateGitStateCaches ( input . worktreePath ) ;
385408 return { success : true } ;
386409 } ) ;
387410 } ) ,
@@ -413,6 +436,7 @@ export const createGitOperationsRouter = () => {
413436 git . push ( [ "--force-with-lease" ] )
414437 ) ;
415438 await git . fetch ( ) ;
439+ invalidateGitStateCaches ( input . worktreePath ) ;
416440 return { success : true } ;
417441 } ) ;
418442 } ) ,
@@ -496,6 +520,7 @@ export const createGitOperationsRouter = () => {
496520 throw error ;
497521 }
498522
523+ invalidateGitStateCaches ( input . worktreePath ) ;
499524 return { success : true } ;
500525 } ) ;
501526 } ) ,
@@ -513,6 +538,7 @@ export const createGitOperationsRouter = () => {
513538 return withGitLock ( input . worktreePath , async ( ) => {
514539 const git = createGit ( input . worktreePath ) ;
515540 await git . rebase ( [ "--abort" ] ) ;
541+ invalidateGitStateCaches ( input . worktreePath ) ;
516542 return { success : true } ;
517543 } ) ;
518544 } ) ,
@@ -530,6 +556,7 @@ export const createGitOperationsRouter = () => {
530556 return withGitLock ( input . worktreePath , async ( ) => {
531557 const git = createGit ( input . worktreePath ) ;
532558 await git . merge ( [ "--abort" ] ) ;
559+ invalidateGitStateCaches ( input . worktreePath ) ;
533560 return { success : true } ;
534561 } ) ;
535562 } ) ,
@@ -586,6 +613,7 @@ export const createGitOperationsRouter = () => {
586613
587614 await shell . openExternal ( url ) ;
588615 await git . fetch ( ) ;
616+ invalidateGitStateCaches ( input . worktreePath ) ;
589617
590618 return { success : true , url } ;
591619 } ) ;
0 commit comments