Skip to content

Commit 3ea4bb0

Browse files
authored
Merge pull request DeusData#916 from alex-plosceac/fix/artifact-gitattributes-merge-ours
fix(artifact): put binary macro before merge=ours in generated .gitattributes
2 parents fb21514 + 5f454dd commit 3ea4bb0

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/pipeline/artifact.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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 {

‎tests/test_artifact.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)