merge-ort: initialize repo in index state

initialize_attr_index() does not initialize the repo member of attr_index. Starting in 44451a2e5e (attr: teach "--attr-source=<tree>" global option to "git", 2023-05-06), this became a problem because istate->repo gets passed down the call chain starting in git_check_attr(). This gets passed all the way down to replace_refs_enabled(), which segfaults when accessing r->gitdir. Fix this by initializing the repository in the index state. Signed-off-by: John Cai <johncai86@gmail.com> Helped-by: Christian Couder <christian.couder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Cai committed Oct 9, 2023 at 13:21 UTC e95bafc52f095b33b5a283179e08a44279c293d0
2 files changed +28
merge-ort.c
+1
@@ -1916,6 +1916,7 @@ static void initialize_attr_index(struct merge_options *opt)
1916 struct index_state *attr_index = &opt->priv->attr_index;
1917 struct cache_entry *ce;
1918
1919 + attr_index->repo = opt->repo;
1920 attr_index->initialized = 1;
1921
1922 if (!opt->renormalize)
t/t4300-merge-tree.sh
+27
@@ -86,6 +86,33 @@ EXPECTED
86 test_cmp expected actual
87 '
88
89 +test_expect_success '3-way merge with --attr-source' '
90 + test_when_finished rm -rf 3-way &&
91 + git init 3-way &&
92 + (
93 + cd 3-way &&
94 + test_commit initial file1 foo &&
95 + base=$(git rev-parse HEAD) &&
96 + git checkout -b brancha &&
97 + echo bar >>file1 &&
98 + git commit -am "adding bar" &&
99 + source=$(git rev-parse HEAD) &&
100 + git checkout @{-1} &&
101 + git checkout -b branchb &&
102 + echo baz >>file1 &&
103 + git commit -am "adding baz" &&
104 + merge=$(git rev-parse HEAD) &&
105 + git checkout -b gitattributes &&
106 + test_commit "gitattributes" .gitattributes "file1 merge=union" &&
107 + git checkout @{-1} &&
108 + tree=$(git --attr-source=gitattributes merge-tree --write-tree \
109 + --merge-base "$base" --end-of-options "$source" "$merge") &&
110 + test_write_lines foo bar baz >expect &&
111 + git cat-file -p "$tree:file1" >actual &&
112 + test_cmp expect actual
113 + )
114 +'
115 +
116 test_expect_success 'file change A, B (same)' '
117 git reset --hard initial &&
118 test_commit "change-a-b-same-A" "initial-file" "AAA" &&