@@ -116,15 +116,18 @@ func TestBuildFileCandidates(t *testing.T) {
116116 t .Fatalf ("write unresolved: %v" , err )
117117 }
118118
119- candidates , err := buildFileCandidates (context . Background (), tmpDir , []string {"resolved.txt" , "unresolved.txt" })
119+ candidates , err := buildFileCandidates (tmpDir , []string {"resolved.txt" , "unresolved.txt" })
120120 if err != nil {
121121 t .Fatalf ("buildFileCandidates error: %v" , err )
122122 }
123123 if len (candidates ) != 2 {
124124 t .Fatalf ("candidates len = %d, want 2" , len (candidates ))
125125 }
126- if ! candidates [0 ].Resolved || ! candidates [1 ].Resolved {
127- t .Fatalf ("expected non-repo candidates to default to resolved status" )
126+ if ! candidates [0 ].Resolved {
127+ t .Fatalf ("expected marker-free file to be resolved" )
128+ }
129+ if candidates [1 ].Resolved {
130+ t .Fatalf ("expected marker-containing file to be unresolved" )
128131 }
129132}
130133
@@ -172,15 +175,69 @@ func TestBuildFileCandidatesDoesNotFailOnMalformedMergedFile(t *testing.T) {
172175 t .Fatalf ("write malformed conflict file: %v" , err )
173176 }
174177
175- candidates , err := buildFileCandidates (context . Background (), repoDir , []string {"conflict.txt" })
178+ candidates , err := buildFileCandidates (repoDir , []string {"conflict.txt" })
176179 if err != nil {
177180 t .Fatalf ("buildFileCandidates error: %v" , err )
178181 }
179182 if len (candidates ) != 1 {
180183 t .Fatalf ("candidates len = %d, want 1" , len (candidates ))
181184 }
182185 if candidates [0 ].Resolved {
183- t .Fatalf ("expected malformed merged conflict to remain unresolved based on index stages" )
186+ t .Fatalf ("expected malformed merged conflict to remain unresolved" )
187+ }
188+ }
189+
190+ func TestBuildFileCandidatesResolvedFromMergedContentWithoutGitAdd (t * testing.T ) {
191+ if testing .Short () {
192+ t .Skip ("skipping git integration test in short mode" )
193+ }
194+ if _ , err := exec .LookPath ("git" ); err != nil {
195+ t .Skip ("git not found in PATH" )
196+ }
197+
198+ repoDir := t .TempDir ()
199+ runGit (t , repoDir , "init" )
200+ runGit (t , repoDir , "config" , "user.email" , "test@example.com" )
201+ runGit (t , repoDir , "config" , "user.name" , "Test User" )
202+
203+ conflictPath := filepath .Join (repoDir , "conflict.txt" )
204+ if err := os .WriteFile (conflictPath , []byte ("a\n Z\n b\n " ), 0o644 ); err != nil {
205+ t .Fatalf ("write base: %v" , err )
206+ }
207+ runGit (t , repoDir , "add" , "conflict.txt" )
208+ runGit (t , repoDir , "commit" , "-m" , "base" )
209+
210+ runGit (t , repoDir , "checkout" , "-b" , "feature" )
211+ if err := os .WriteFile (conflictPath , []byte ("a\n Y\n Z\n b\n " ), 0o644 ); err != nil {
212+ t .Fatalf ("write theirs: %v" , err )
213+ }
214+ runGit (t , repoDir , "commit" , "-am" , "theirs" )
215+
216+ runGit (t , repoDir , "checkout" , "-" )
217+ if err := os .WriteFile (conflictPath , []byte ("a\n X\n Z\n b\n " ), 0o644 ); err != nil {
218+ t .Fatalf ("write ours: %v" , err )
219+ }
220+ runGit (t , repoDir , "commit" , "-am" , "ours" )
221+
222+ mergeCmd := exec .Command ("git" , "merge" , "feature" )
223+ mergeCmd .Dir = repoDir
224+ if output , err := mergeCmd .CombinedOutput (); err == nil {
225+ t .Fatalf ("expected merge conflict, got success: %s" , string (output ))
226+ }
227+
228+ if err := os .WriteFile (conflictPath , []byte ("a\n X\n Z\n b\n " ), 0o644 ); err != nil {
229+ t .Fatalf ("write resolved content: %v" , err )
230+ }
231+
232+ candidates , err := buildFileCandidates (repoDir , []string {"conflict.txt" })
233+ if err != nil {
234+ t .Fatalf ("buildFileCandidates error: %v" , err )
235+ }
236+ if len (candidates ) != 1 {
237+ t .Fatalf ("candidates len = %d, want 1" , len (candidates ))
238+ }
239+ if ! candidates [0 ].Resolved {
240+ t .Fatalf ("expected resolved merged content to be shown as resolved without git add" )
184241 }
185242}
186243
0 commit comments