Skip to content

Commit 7906b5c

Browse files
committed
Merge branch 'jc/merge-ort-attr-index-fix'
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
2 parents cc7d718 + e95bafc commit 7906b5c

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
@@ -1902,6 +1902,7 @@ static void initialize_attr_index(struct merge_options *opt)
19021902
struct index_state *attr_index = &opt->priv->attr_index;
19031903
struct cache_entry *ce;
19041904

1905+
attr_index->repo = opt->repo;
19051906
attr_index->initialized = 1;
19061907

19071908
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)