Merge branch 'ds/merge-tree-use-config'

Allow git forges to disable replace-refs feature while running "git
merge-tree".

* ds/merge-tree-use-config:
  merge-tree: load default git config
This commit is contained in:
Junio C Hamano 2023-05-15 13:59:06 -07:00
commit 80754c5cc0
2 changed files with 21 additions and 0 deletions

View file

@ -17,6 +17,7 @@
#include "merge-blobs.h"
#include "quote.h"
#include "tree.h"
#include "config.h"
static int line_termination = '\n';
@ -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);

View file

@ -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