Skip to content

Commit 7adf526

Browse files
derrickstoleegitster
authored andcommitted
merge: check config before loading commits
Now that we use generation numbers from the commit-graph, we must ensure that all commits that exist in the commit-graph are loaded from that file instead of from the object database. Since the commit-graph file is only checked if core.commitGraph is true, we must check the default config before we load any commits. In the merge builtin, the config was checked after loading the HEAD commit. This was due to the use of the global 'branch' when checking merge-specific config settings. Move the config load to be between the initialization of 'branch' and the commit lookup. Without this change, a fast-forward merge would hit a BUG("bad generation skip") statement in commit.c during paint_down_to_common(). This is because the HEAD commit would be loaded with "infinite" generation but then reached by commits with "finite" generation numbers. Add a test to t5318-commit-graph.sh that exercises this code path to prevent a regression. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04bc8d1 commit 7adf526

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

builtin/merge.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,14 +1148,15 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11481148
branch = branch_to_free = resolve_refdup("HEAD", 0, &head_oid, NULL);
11491149
if (branch)
11501150
skip_prefix(branch, "refs/heads/", &branch);
1151+
1152+
init_diff_ui_defaults();
1153+
git_config(git_merge_config, NULL);
1154+
11511155
if (!branch || is_null_oid(&head_oid))
11521156
head_commit = NULL;
11531157
else
11541158
head_commit = lookup_commit_or_die(&head_oid, "HEAD");
11551159

1156-
init_diff_ui_defaults();
1157-
git_config(git_merge_config, NULL);
1158-
11591160
if (branch_mergeoptions)
11601161
parse_branch_merge_options(branch_mergeoptions);
11611162
argc = parse_options(argc, argv, prefix, builtin_merge_options,

t/t5318-commit-graph.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,13 @@ test_expect_success 'write graph in bare repo' '
221221
graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
222222
graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
223223

224+
test_expect_success 'perform fast-forward merge in full repo' '
225+
cd "$TRASH_DIRECTORY/full" &&
226+
git checkout -b merge-5-to-8 commits/5 &&
227+
git merge commits/8 &&
228+
git show-ref -s merge-5-to-8 >output &&
229+
git show-ref -s commits/8 >expect &&
230+
test_cmp expect output
231+
'
232+
224233
test_done

0 commit comments

Comments
 (0)