Skip to content

Commit e95bafc

Browse files
john-caigitster
authored andcommitted
merge-ort: initialize repo in index state
initialize_attr_index() does not initialize the repo member of attr_index. Starting in 44451a2 (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 <[email protected]> Helped-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb7d80e commit e95bafc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

merge-ort.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,7 @@ static void initialize_attr_index(struct merge_options *opt)
19161916
struct index_state *attr_index = &opt->priv->attr_index;
19171917
struct cache_entry *ce;
19181918

1919+
attr_index->repo = opt->repo;
19191920
attr_index->initialized = 1;
19201921

19211922
if (!opt->renormalize)

t/t4300-merge-tree.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,33 @@ EXPECTED
8686
test_cmp expected actual
8787
'
8888

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+
89116
test_expect_success 'file change A, B (same)' '
90117
git reset --hard initial &&
91118
test_commit "change-a-b-same-A" "initial-file" "AAA" &&

0 commit comments

Comments
 (0)