]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/merge-ort-attr-index-fix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Oct 2023 20:25:42 +0000 (13:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Oct 2023 20:25:42 +0000 (13:25 -0700)
Fix "git merge-tree" to stop segfaulting when the --attr-source
option is used.

* jc/merge-ort-attr-index-fix:
  merge-ort: initialize repo in index state

merge-ort.c
t/t4300-merge-tree.sh

index 7857ce9fbd18e5575ae998c710a8b6c4e5f67427..36537256613b5d18aff7b4b0d6e45ca7b921d146 100644 (file)
@@ -1902,6 +1902,7 @@ static void initialize_attr_index(struct merge_options *opt)
        struct index_state *attr_index = &opt->priv->attr_index;
        struct cache_entry *ce;
 
+       attr_index->repo = opt->repo;
        attr_index->initialized = 1;
 
        if (!opt->renormalize)
index 57c4f26e4613a97644ad5822b1f6a0c4572a33a4..9c197260d5bbf54d3ad578c27f54e278d88ab97b 100755 (executable)
@@ -86,6 +86,33 @@ EXPECTED
        test_cmp expected actual
 '
 
+test_expect_success '3-way merge with --attr-source' '
+       test_when_finished rm -rf 3-way &&
+       git init 3-way &&
+       (
+               cd 3-way &&
+               test_commit initial file1 foo &&
+               base=$(git rev-parse HEAD) &&
+               git checkout -b brancha &&
+               echo bar >>file1 &&
+               git commit -am "adding bar" &&
+               source=$(git rev-parse HEAD) &&
+               git checkout @{-1} &&
+               git checkout -b branchb &&
+               echo baz >>file1 &&
+               git commit -am "adding baz" &&
+               merge=$(git rev-parse HEAD) &&
+               git checkout -b gitattributes &&
+               test_commit "gitattributes" .gitattributes "file1 merge=union" &&
+               git checkout @{-1} &&
+               tree=$(git --attr-source=gitattributes merge-tree --write-tree \
+               --merge-base "$base" --end-of-options "$source" "$merge") &&
+               test_write_lines foo bar baz >expect &&
+               git cat-file -p "$tree:file1" >actual &&
+               test_cmp expect actual
+       )
+'
+
 test_expect_success 'file change A, B (same)' '
        git reset --hard initial &&
        test_commit "change-a-b-same-A" "initial-file" "AAA" &&