@@ -2243,13 +2243,20 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: {
22432243 { timeoutMs : 10_000 , allowNonZeroExit : true } ,
22442244 ) ;
22452245 } ) ;
2246+ const readStashList = ( ) =>
2247+ runGitStdout ( "GitCore.stashAndCheckout.stashList" , input . cwd , [ "stash" , "list" ] ) . pipe (
2248+ Effect . map ( ( stdout ) => stdout . trim ( ) ) ,
2249+ ) ;
2250+
2251+ const stashListBefore = yield * readStashList ( ) ;
22462252
22472253 yield * executeGit (
22482254 "GitCore.stashAndCheckout.stash" ,
22492255 input . cwd ,
22502256 [ "stash" , "push" , "-u" , "-m" , `t3code: stash before switching to ${ input . branch } ` ] ,
22512257 { timeoutMs : 15_000 , fallbackErrorMessage : "git stash failed" } ,
22522258 ) ;
2259+ const stashEntryCreated = ( yield * readStashList ( ) ) !== stashListBefore ;
22532260
22542261 const checkoutExit = yield * Effect . exit (
22552262 checkoutBranch ( input ) . pipe (
@@ -2266,6 +2273,10 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: {
22662273 ) ,
22672274 ) ;
22682275 if ( Exit . isFailure ( checkoutExit ) ) {
2276+ if ( ! stashEntryCreated ) {
2277+ return yield * Effect . failCause ( checkoutExit . cause ) ;
2278+ }
2279+
22692280 const restoreResult = yield * executeGit (
22702281 "GitCore.stashAndCheckout.restoreOriginalBranch" ,
22712282 input . cwd ,
@@ -2286,6 +2297,10 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: {
22862297 return yield * Effect . failCause ( checkoutExit . cause ) ;
22872298 }
22882299
2300+ if ( ! stashEntryCreated ) {
2301+ return ;
2302+ }
2303+
22892304 const popResult = yield * executeGit (
22902305 "GitCore.stashAndCheckout.stashPop" ,
22912306 input . cwd ,
0 commit comments