{"thread":{"id":"1491","subject":"[PATCH] Add --signoff and --verify option to git commit.","startedAt":"2005-08-13T09:08:15Z","lastAt":"2005-08-16T00:13:38Z","messageCount":3,"participants":["Junio C Hamano","Josef Weidendorfer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"7179","messageId":"7vzmrmp5kw.fsf@assigned-by-dhcp.cox.net","threadId":"1491","inReplyTo":null,"subject":"[PATCH] Add --signoff and --verify option to git commit.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-13T09:08:15Z","receivedAt":"2005-08-13T09:08:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As brought up in the discussion which followed a patch to add a\nsigned-off-by line with the --sign flag to format-patch from\nJohannes Schindelin, add --signoff to the git commit command.\n\nAlso add --verify to make sure the lines you introduced are\nclean, which is more useful in commit but not very much in\nformat-patch as it was originally implemented, because finding\nbotches at format-patch time is too late.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n git-commit-script |   76 ++++++++++++++++++++++++++++++++++++++++++++++++++---\n 1 files changed, 72 insertions(+), 4 deletions(-)\n\n2f1c5b4fa572886646d9993129f7cd0a61fe4190\ndiff --git a/git-commit-script b/git-commit-script\n--- a/git-commit-script\n+++ b/git-commit-script\n@@ -9,7 +9,7 @@ usage () {\n \tdie 'git commit [-a]  [-m <message>] [-F <logfile>] [(-C|-c) <commit>] [<path>...]'\n }\n \n-all= logfile= use_commit= no_edit= log_given= log_message=\n+all= logfile= use_commit= no_edit= log_given= log_message= verify= signoff=\n while case \"$#\" in 0) break;; esac\n do\n   case \"$1\" in\n@@ -64,6 +64,12 @@ do\n     use_commit=\"$1\"\n     no_edit=t\n     shift ;;\n+  -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)\n+    signoff=t\n+    shift ;;\n+  -v|--v|--ve|--ver|--veri|--verif|--verify)\n+    verify=t\n+    shift ;;\n   --)\n     shift\n     break ;;\n@@ -86,6 +92,60 @@ t)\n esac\n git-update-cache -q --refresh -- \"$@\" || exit 1\n \n+case \"$verify\" in\n+t)\n+\t# This is slightly modified from Andrew Morton's Perfect Patch.\n+\t# Lines you introduce should not have trailing whitespace.\n+\t# Also check for an indentation that has SP before a TAB.\n+\tperl -e '\n+\t    my $fh;\n+\t    my $found_bad = 0;\n+\t    my $filename;\n+\t    my $reported_filename = \"\";\n+\t    my $lineno;\n+\t    sub bad_line {\n+\t\tmy ($why, $line) = @_;\n+\t\tif (!$found_bad) {\n+\t\t    print \"*\\n\";\n+\t\t    print \"* You have some suspicious patch lines:\\n\";\n+\t\t    print \"*\\n\";\n+\t\t    $found_bad = 1;\n+\t\t}\n+\t\tif ($reported_filename ne $filename) {\n+\t\t    print \"* In $filename\\n\";\n+\t\t    $reported_filename = $filename;\n+\t\t}\n+\t\tprint \"* $why (line $lineno)\\n$line\\n\";\n+\t    }\n+\t    open $fh, \"-|\", qw(git-diff-cache -p -M --cached HEAD);\n+\t    while (<$fh>) {\n+\t\tif (m|^diff --git a/(.*) b/\\1$|) {\n+\t\t    $filename = $1;\n+\t\t    next;\n+\t\t}\n+\t\tif (/^@@ -\\S+ \\+(\\d+)/) {\n+\t\t    $lineno = $1 - 1;\n+\t\t    next;\n+\t\t}\n+\t\tif (/^ /) {\n+\t\t    $lineno++;\n+\t\t    next;\n+\t\t}\n+\t\tif (s/^\\+//) {\n+\t\t    $lineno++;\n+\t\t    chomp;\n+\t\t    if (/\\s$/) {\n+\t\t\tbad_line(\"trailing whitespace\", $_);\n+\t\t    }\n+\t\t    if (/^\\s* \t/) {\n+\t\t\tbad_line(\"indent SP followed by a TAB\", $_);\n+\t\t    }\n+\t\t}\n+\t    }\n+\t    exit($found_bad);\n+\t' || exit ;;\n+esac\n+\n PARENTS=\"-p HEAD\"\n if [ ! -r \"$GIT_DIR/HEAD\" ]; then\n \tif [ -z \"$(git-ls-files)\" ]; then\n@@ -161,7 +221,14 @@ else\n \t\texport GIT_AUTHOR_DATE\n \t\tgit-cat-file commit \"$use_commit\" |\n \t\tsed -e '1,/^$/d'\n-\tfi >.editmsg\n+\tfi |\n+\tgit-stripspace >.editmsg\n+\tcase \"$signoff\" in\n+\tt)\n+\t\tgit-var GIT_COMMITTER_IDENT | sed -e '\n+\t\t\ts/>.*/>/\n+\t\t\ts/^/Signed-off-by: /' >>.editmsg ;;\n+\tesac\n \tgit-status-script >>.editmsg\n fi\n if [ \"$?\" != \"0\" -a ! -f $GIT_DIR/MERGE_HEAD ]\n@@ -176,7 +243,8 @@ case \"$no_edit\" in\n \t;;\n esac\n grep -v '^#' < .editmsg | git-stripspace > .cmitmsg\n-if test -s .cmitmsg\n+grep -v -i '^Signed-off-by' .cmitmsg >.cmitchk\n+if test -s .cmitchk\n then\n \ttree=$(git-write-tree) &&\n \tcommit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&\n@@ -187,5 +255,5 @@ else\n \tfalse\n fi\n ret=\"$?\"\n-rm -f .cmitmsg .editmsg\n+rm -f .cmitmsg .editmsg .cmitchk\n exit \"$ret\"\n"},{"id":"7316","messageId":"200508152321.17075.Josef.Weidendorfer@gmx.de","threadId":"1491","inReplyTo":"7vzmrmp5kw.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Add --signoff and --verify option to git commit.","fromName":"Josef Weidendorfer","fromEmail":"josef.weidendorfer@gmx.de","sentAt":"2005-08-15T21:21:16Z","receivedAt":"2005-08-15T21:21:16Z","isPatch":true,"sender":{"key":"josef.weidendorfer@gmx.de","avatar":null},"body":"On Saturday 13 August 2005 11:08, Junio C Hamano wrote:\n> Also add --verify to make sure the lines you introduced are\n> clean, which is more useful in commit but not very much in\n> format-patch as it was originally implemented, because finding\n> botches at format-patch time is too late.\n\nI think that verification of/commenting on commits at/before commit time is a \nperfect place for another hook script (or collection of verification \nscripts).\n\nPeople probably want to check a new commit on identation/coding style on a \nper-project manner. The hook also should be able to give warnings/hints by \nadding text to the commit message (e.g. \"please do not use 'fgetc'\" / \n\"doublecheck quoting in system()\", ...) without rejecting the commit as a \nwhole. It could even be allowed to edit the code before commit.\n\nThese verification scripts should be used per default, and git-commit should \nhave an option to force bypassing verification.\n\nIf I get some time, I can come up with a patch.\n\nJosef\n"},{"id":"7329","messageId":"7v3bpavivh.fsf@assigned-by-dhcp.cox.net","threadId":"1491","inReplyTo":"200508152321.17075.Josef.Weidendorfer@gmx.de","subject":"Re: [PATCH] Add --signoff and --verify option to git commit.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-16T00:13:38Z","receivedAt":"2005-08-16T00:13:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Josef Weidendorfer <Josef.Weidendorfer@gmx.de> writes:\n\n> These verification scripts should be used per default, and git-commit should \n> have an option to force bypassing verification.\n\nI agree that it would be a good place to do a hook.  Also it may\nnot be a bad idea, if you volunteer to come up with a patch, to\nlook at an earlier thread that talks about commit message\ntemplates and think about how these things should mesh together.\n\nBypassing can already be done by not giving '-v', so I do not\nthink you need to make things more complicated than necessary.\nYou can first try with a '-v', examine what it complains about,\nfix only what are applicable to your change, try with '-v' again\nto make sure the only complaints are from false positives, and\nthen you commit without '-v', bypassing the check.\n"}]}