summaryrefslogtreecommitdiff
path: root/merge-recursive.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2019-08-17 18:41:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-08-19 17:08:04 (GMT)
commit45ef16f77ae5a14aa751d03c9c9fc2fa91804425 (patch)
tree6d231ea404c0fea6eb90067fccb413b9eb421ccb /merge-recursive.c
parentf3081dae014e08ece75cfb28a9844beb01b6d9f2 (diff)
downloadgit-45ef16f77ae5a14aa751d03c9c9fc2fa91804425.zip
git-45ef16f77ae5a14aa751d03c9c9fc2fa91804425.tar.gz
git-45ef16f77ae5a14aa751d03c9c9fc2fa91804425.tar.bz2
merge-recursive: add sanity checks for relevant merge_options
There are lots of options that callers can set, yet most have a limited range of valid values, some options are meant for output (e.g. opt->obuf, which is expected to start empty), and callers are expected to not set opt->priv. Add several sanity checks to ensure callers provide sane values. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-recursive.c')
-rw-r--r--merge-recursive.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/merge-recursive.c b/merge-recursive.c
index fa3f8eb..0231d7b 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -3615,6 +3615,30 @@ static int merge_start(struct merge_options *opt, struct tree *head)
{
struct strbuf sb = STRBUF_INIT;
+ /* Sanity checks on opt */
+ assert(opt->repo);
+
+ assert(opt->branch1 && opt->branch2);
+
+ assert(opt->detect_renames >= -1 &&
+ opt->detect_renames <= DIFF_DETECT_COPY);
+ assert(opt->detect_directory_renames >= MERGE_DIRECTORY_RENAMES_NONE &&
+ opt->detect_directory_renames <= MERGE_DIRECTORY_RENAMES_TRUE);
+ assert(opt->rename_limit >= -1);
+ assert(opt->rename_score >= 0 && opt->rename_score <= MAX_SCORE);
+ assert(opt->show_rename_progress >= 0 && opt->show_rename_progress <= 1);
+
+ assert(opt->xdl_opts >= 0);
+ assert(opt->recursive_variant >= MERGE_VARIANT_NORMAL &&
+ opt->recursive_variant <= MERGE_VARIANT_THEIRS);
+
+ assert(opt->verbosity >= 0 && opt->verbosity <= 5);
+ assert(opt->buffer_output <= 2);
+ assert(opt->obuf.len == 0);
+
+ assert(opt->priv == NULL);
+
+ /* Sanity check on repo state; index must match head */
if (repo_index_has_changes(opt->repo, head, &sb)) {
err(opt, _("Your local changes to the following files would be overwritten by merge:\n %s"),
sb.buf);