Skip to content

Commit

Permalink
Merge branch 'ds/merge-tree-use-config' into jch
Browse files Browse the repository at this point in the history
Allow git forges to disable replace-refs feature while running "git
merge-tree".

* ds/merge-tree-use-config:
  merge-tree: load default git config
  • Loading branch information
gitster committed May 12, 2023
2 parents 58c879c + b6551fe commit 1a08cb6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builtin/merge-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "merge-blobs.h"
#include "quote.h"
#include "tree.h"
#include "config.h"

static int line_termination = '\n';

Expand Down Expand Up @@ -628,6 +629,8 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
if (argc != expected_remaining_argc)
usage_with_options(merge_tree_usage, mt_options);

git_config(git_default_config, NULL);

/* Do the relevant type of merge */
if (o.mode == MODE_REAL)
return real_merge(&o, merge_base, argv[0], argv[1], prefix);
Expand Down
18 changes: 18 additions & 0 deletions t/t4300-merge-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,22 @@ test_expect_success 'turn tree to file' '
test_cmp expect actual
'

test_expect_success 'merge-tree respects core.useReplaceRefs=false' '
test_commit merge-to &&
test_commit valid base &&
git reset --hard HEAD^ &&
test_commit malicious base &&
test_when_finished "git replace -d $(git rev-parse valid^0)" &&
git replace valid^0 malicious^0 &&
tree=$(git -c core.useReplaceRefs=true merge-tree --write-tree merge-to valid) &&
merged=$(git cat-file -p $tree:base) &&
test malicious = $merged &&
tree=$(git -c core.useReplaceRefs=false merge-tree --write-tree merge-to valid) &&
merged=$(git cat-file -p $tree:base) &&
test valid = $merged
'

test_done

0 comments on commit 1a08cb6

Please sign in to comment.