File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -389,9 +389,13 @@ static void ensure_gitattributes(const char *repo_path) {
389389 } else {
390390 FILE * fp = fdopen (fd , "w" );
391391 if (fp ) {
392+ /* Order matters: attributes apply left to right and the `binary`
393+ * macro expands to `-diff -merge -text`, so a trailing `binary`
394+ * unsets `merge=ours` and the conflict prevention this file
395+ * exists for never engages. The macro must come first. */
392396 (void )fputs ("# Auto-generated by codebase-memory-mcp\n"
393397 "# Prevent merge conflicts on compressed artifact\n" CBM_ARTIFACT_FILENAME
394- " merge=ours binary \n" ,
398+ " binary merge=ours\n" ,
395399 fp );
396400 (void )fclose (fp );
397401 } else {
Original file line number Diff line number Diff line change @@ -310,6 +310,20 @@ TEST(artifact_gitattributes_created) {
310310 struct stat st ;
311311 ASSERT_EQ (stat (ga , & st ), 0 );
312312
313+ /* Attribute ORDER is load-bearing: gitattributes apply left to right and
314+ * the `binary` macro expands to `-diff -merge -text`, so a trailing
315+ * `binary` unsets a preceding `merge=ours` (git check-attr merge reports
316+ * "unset" and concurrent artifact refreshes produce binary conflicts
317+ * instead of auto-resolving). The driver must come after the macro. */
318+ FILE * gaf = fopen (ga , "r" );
319+ ASSERT_NOT_NULL (gaf );
320+ char content [512 ] = {0 };
321+ size_t rd = fread (content , 1 , sizeof (content ) - 1 , gaf );
322+ (void )fclose (gaf );
323+ ASSERT_TRUE (rd > 0 );
324+ ASSERT_NOT_NULL (strstr (content , CBM_ARTIFACT_FILENAME " binary merge=ours" ));
325+ ASSERT_TRUE (strstr (content , "merge=ours binary" ) == NULL );
326+
313327 cleanup_dir (g_tmpdir );
314328 PASS ();
315329}
You can’t perform that action at this time.
0 commit comments