{"thread":{"id":"15133","subject":"[PATCH] add --no-verify to git-merge and git-pull","startedAt":"2008-08-21T13:00:34Z","lastAt":"2008-08-21T13:00:34Z","messageCount":1,"participants":["Paolo Bonzini"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"87979","messageId":"E1KW9wI-0005K5-1y@fencepost.gnu.org","threadId":"15133","inReplyTo":null,"subject":"[PATCH] add --no-verify to git-merge and git-pull","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-08-21T13:00:34Z","receivedAt":"2008-08-21T13:00:34Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"This patch adds the --no-verify option to skip the pre-merge hook.\nThe corresponding testcase is also updated to test the new option.\n\nSigned-off-by: Paolo Bonzini <bonzini@gnu.org>\n---\n Documentation/git-merge.txt     |    2 +-\n Documentation/merge-options.txt |    3 +++\n builtin-merge.c                 |   15 +++++++++------\n git-pull.sh                     |    9 ++++++---\n t/t5407-pre-merge-hook.sh       |   15 ++++++++++-----\n 5 files changed, 29 insertions(+), 15 deletions(-)\n\n\tI'm submitting this separately because it touches a substantially\n\tdisjoint set of files (besides builtin-merge.c).\n\n\tAs an aside, I'm not particularly attached to this set of\n\tpatches as long as there is a way to achieve what I wanted,\n\ti.e. blocking merge commits.  One way would be with\n\tbranch.<name>.mergeoptions and the fast forward strategies\n\tpatch from Sverre.\n\ndiff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt\nindex 17a15ac..5a0f398 100644\n--- a/Documentation/git-merge.txt\n+++ b/Documentation/git-merge.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git merge' [-n] [--stat] [--no-commit] [--squash] [-s <strategy>]...\n-\t[-m <msg>] <remote> <remote>...\n+\t[-m <msg>] [--no-verify] <remote> <remote>...\n 'git merge' <msg> HEAD <remote>...\n \n DESCRIPTION\ndiff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt\nindex 007909a..9a4f0bb 100644\n--- a/Documentation/merge-options.txt\n+++ b/Documentation/merge-options.txt\n@@ -51,6 +51,9 @@\n \ta fast-forward, only update the branch pointer. This is\n \tthe default behavior of git-merge.\n \n+--no-verify::\n+\tBypasses the pre-merge hook.  See also linkgit:githooks[5].\n+\n -s <strategy>::\n --strategy=<strategy>::\n \tUse the given merge strategy; can be supplied more than\ndiff --git a/builtin-merge.c b/builtin-merge.c\nindex e7f3ece..0999dca 100644\n--- a/builtin-merge.c\n+++ b/builtin-merge.c\n@@ -42,7 +42,7 @@ static const char * const builtin_merge_usage[] = {\n \n static int show_diffstat = 1, option_log, squash;\n static int option_commit = 1, allow_fast_forward = 1;\n-static int allow_trivial = 1, have_message;\n+static int allow_trivial = 1, have_message, no_verify;\n static struct strbuf merge_msg;\n static struct commit_list *remoteheads;\n static unsigned char head[20], stash[20];\n@@ -166,6 +166,8 @@ static struct option builtin_merge_options[] = {\n \t\t\"create a single commit instead of doing a merge\"),\n \tOPT_BOOLEAN(0, \"commit\", &option_commit,\n \t\t\"perform a commit if the merge succeeds (default)\"),\n+\tOPT_BOOLEAN(0, \"no-verify\", &no_verify,\n+\t\t\"bypass the pre-merge hook\"),\n \tOPT_BOOLEAN(0, \"ff\", &allow_fast_forward,\n \t\t\"allow fast forward (default)\"),\n \tOPT_CALLBACK('s', \"strategy\", &use_strategies, \"strategy\",\n@@ -905,8 +907,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\tremote_head = peel_to_type(argv[0], 0, NULL, OBJ_COMMIT);\n \t\tif (!remote_head)\n \t\t\tdie(\"%s - not something we can merge\", argv[0]);\n-\t\tif (run_hook(\"pre-merge\", NULL, \"ff\", \"--\",\n-\t\t\t     remote_head->sha1, NULL))\n+\t\tif (!no_verify && run_hook(\"pre-merge\", NULL, \"ff\", \"--\",\n+\t\t\t\t\t   remote_head->sha1, NULL))\n \t\t\treturn 1;\n \n \t\tupdate_ref(\"initial pull\", \"HEAD\", remote_head->sha1, NULL, 0,\n@@ -1006,7 +1008,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \n \t\tstrcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));\n \n-\t\tif (run_pre_merge_hook(\"ff\"))\n+\t\tif (!no_verify && run_pre_merge_hook(\"ff\"))\n \t\t\treturn 1;\n \n \t\tprintf(\"Updating %s..%s\\n\",\n@@ -1047,7 +1049,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\tprintf(\"Trying really trivial in-index merge...\\n\");\n \t\t\tif (!read_tree_trivial(common->item->object.sha1,\n \t\t\t\t\thead, remoteheads->item->object.sha1)) {\n-\t\t\t\tif (run_pre_merge_hook(\"trivial\"))\n+\t\t\t\tif (!no_verify && run_pre_merge_hook(\"trivial\"))\n \t\t\t\t\treturn 1;\n \t\t\t\treturn merge_trivial();\n \t\t\t}\n@@ -1083,7 +1085,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tif (run_pre_merge_hook(remoteheads->next ? \"octopus\" : \"merge\"))\n+\tif (!no_verify &&\n+\t    run_pre_merge_hook(remoteheads->next ? \"octopus\" : \"merge\"))\n \t\treturn 1;\n \n \t/* We are going to make a new commit. */\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 429d02c..52aaea9 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -4,7 +4,7 @@\n #\n # Fetch one or more remote refs and merge it/them into the current HEAD.\n \n-USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s strategy]... [<fetch-options>] <repo> <head>...'\n+USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [--no-verify] [-s strategy]... [<fetch-options>] <repo> <head>...'\n LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'\n SUBDIRECTORY_OK=Yes\n OPTIONS_SPEC=\n@@ -16,7 +16,7 @@ cd_to_toplevel\n test -z \"$(git ls-files -u)\" ||\n \tdie \"You are in the middle of a conflicted merge.\"\n \n-strategy_args= no_stat= no_commit= squash= no_ff= log_arg=\n+strategy_args= no_stat= no_commit= squash= no_ff= no_verify= log_arg=\n curr_branch=$(git symbolic-ref -q HEAD)\n curr_branch_short=$(echo \"$curr_branch\" | sed \"s|refs/heads/||\")\n rebase=$(git config --bool branch.$curr_branch_short.rebase)\n@@ -41,6 +41,8 @@ do\n \t\tno_ff=--ff ;;\n \t--no-ff)\n \t\tno_ff=--no-ff ;;\n+\t--no-verify)\n+\t\tno_verify=--no-verify ;;\n \t-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\\\n \t\t--strateg=*|--strategy=*|\\\n \t-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)\n@@ -181,5 +183,6 @@ merge_name=$(git fmt-merge-msg $log_arg <\"$GIT_DIR/FETCH_HEAD\") || exit\n test true = \"$rebase\" &&\n \texec git-rebase $strategy_args --onto $merge_head \\\n \t${oldremoteref:-$merge_head}\n-exec git-merge $no_stat $no_commit $squash $no_ff $log_arg $strategy_args \\\n+exec git-merge $no_stat $no_commit $squash $no_ff $no_verify \\\n+\t$log_arg $strategy_args \\\n \t\"$merge_name\" HEAD $merge_head\ndiff --git a/t/t5407-pre-merge-hook.sh b/t/t5407-pre-merge-hook.sh\nindex b7029ce..961040f 100755\n--- a/t/t5407-pre-merge-hook.sh\n+++ b/t/t5407-pre-merge-hook.sh\n@@ -117,14 +117,19 @@ test_expect_success 'pre-merge does not run for up-to-date octopus ' '\n \t! test -f .git/pre-merge.args\n '\n \n-cat >.git/hooks/pre-merge <<'EOF'\n-#!/bin/sh\n-exit 1\n-EOF\n+echo 'exit 1' >>.git/hooks/pre-merge\n chmod u+x .git/hooks/pre-merge\n \n test_expect_success 'pre-merge can stop merge ' '\n-        ! git merge --no-ff branch4\n+\trm -f .git/pre-merge.args &&\n+        ! git merge --no-ff branch4 &&\n+\ttest -f .git/pre-merge.args\n+'\n+\n+test_expect_success 'pre-merge is not invoked with --no-verify' '\n+\trm -f .git/pre-merge.args &&\n+        git merge --no-ff --no-verify branch4 &&\n+\t! test -f .git/pre-merge.args\n '\n \n test_done\n-- \n1.5.5\n"}]}