@@ -5,7 +5,9 @@ import * as Duration from "effect/Duration";
55import * as Deferred from "effect/Deferred" ;
66import * as Effect from "effect/Effect" ;
77import * as Fiber from "effect/Fiber" ;
8+ import * as FileSystem from "effect/FileSystem" ;
89import * as Layer from "effect/Layer" ;
10+ import * as Path from "effect/Path" ;
911import * as Queue from "effect/Queue" ;
1012import * as Ref from "effect/Ref" ;
1113import { TestClock } from "effect/testing" ;
@@ -50,6 +52,91 @@ const captureProcessResult = (
5052 ) ;
5153
5254describe ( "VcsProcess.run" , ( ) => {
55+ it . effect . each ( [
56+ {
57+ name : "Windows index lock" ,
58+ stderr : "fatal: Unable to create 'C:\\private\\repo\\.git\\index.lock': File exists.\n" ,
59+ locked : true ,
60+ } ,
61+ {
62+ name : "index permission error" ,
63+ stderr : "fatal: Unable to create '/private/repo/.git/index.lock': Permission denied\n" ,
64+ locked : false ,
65+ } ,
66+ {
67+ name : "a different Git lock" ,
68+ stderr : "fatal: Unable to create '/private/repo/.git/config.lock': File exists.\n" ,
69+ locked : false ,
70+ } ,
71+ ] ) ( "distinguishes $name without retaining raw stderr" , ( { stderr, locked } ) =>
72+ Effect . gen ( function * ( ) {
73+ const error = yield * captureProcessResult (
74+ Effect . succeed ( {
75+ code : ChildProcessSpawner . ExitCode ( 128 ) ,
76+ stdout : "" ,
77+ stderr,
78+ stdoutTruncated : false ,
79+ stderrTruncated : false ,
80+ stdoutInvalidUtf8 : false ,
81+ stderrInvalidUtf8 : false ,
82+ timedOut : false ,
83+ } ) ,
84+ ) ;
85+ expect ( error ) . toMatchObject ( {
86+ failureKind : "command-failed" ,
87+ detail : locked
88+ ? "Git's index is locked. Wait for other Git operations to finish, then try again."
89+ : "Process exited with a non-zero status." ,
90+ } ) ;
91+ expect ( error . message ) . not . toContain ( "private" ) ;
92+ expect ( error ) . not . toHaveProperty ( "stderr" ) ;
93+ } ) ,
94+ ) ;
95+
96+ it . effect ( "explains a locked Git index and allows restore after the lock is released" , ( ) =>
97+ Effect . gen ( function * ( ) {
98+ const fs = yield * FileSystem . FileSystem ;
99+ const path = yield * Path . Path ;
100+ const cwd = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-index-lock-" } ) ;
101+ const git = ( args : readonly string [ ] ) =>
102+ run ( { operation : "test.checkpoint.restore" , command : "git" , cwd, args } ) ;
103+ yield * git ( [ "init" ] ) ;
104+ const file = path . join ( cwd , "README.md" ) ;
105+ yield * fs . writeFileString ( file , "before\n" ) ;
106+ yield * git ( [ "add" , "README.md" ] ) ;
107+ yield * git ( [
108+ "-c" ,
109+ "user.name=Test" ,
110+ "-c" ,
111+ 112+ "commit" ,
113+ "-m" ,
114+ "initial" ,
115+ ] ) ;
116+ yield * fs . writeFileString ( file , "after\n" ) ;
117+ const lock = path . join ( cwd , ".git" , "index.lock" ) ;
118+ yield * fs . writeFileString ( lock , "" ) ;
119+ const restore = [ "restore" , "--source=HEAD" , "--worktree" , "--staged" , "--" , "README.md" ] ;
120+
121+ const error = yield * Effect . flip ( git ( restore ) ) ;
122+ expect ( error ) . toBeInstanceOf ( VcsProcessExitError ) ;
123+ expect ( error ) . toMatchObject ( {
124+ exitCode : 128 ,
125+ failureKind : "command-failed" ,
126+ detail : "Git's index is locked. Wait for other Git operations to finish, then try again." ,
127+ } ) ;
128+ expect ( error . message ) . not . toContain ( "index.lock" ) ;
129+ expect ( error . message ) . toContain ( "Git's index is locked." ) ;
130+ expect ( error ) . not . toHaveProperty ( "stderr" ) ;
131+ expect ( yield * fs . readFileString ( file ) ) . toBe ( "after\n" ) ;
132+ expect ( yield * fs . exists ( lock ) ) . toBe ( true ) ;
133+
134+ yield * fs . remove ( lock ) ;
135+ yield * git ( restore ) ;
136+ expect ( yield * fs . readFileString ( file ) ) . toBe ( "before\n" ) ;
137+ } ) . pipe ( provideLive , Effect . provide ( NodeServices . layer ) , Effect . scoped ) ,
138+ ) ;
139+
53140 it . effect ( "bounds a synthetic burst of GitHub API processes" , ( ) =>
54141 Effect . gen ( function * ( ) {
55142 const gate = yield * Deferred . make < void > ( ) ;
0 commit comments