From 087a8bcdf0de43bc196ccdf83c2f572fef604f75 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Thu, 9 Nov 2017 07:54:22 -0800 Subject: [PATCH] disable all checks on revert commits For QB08-047. --- hooks/git.py | 19 ++++ hooks/updates/__init__.py | 13 ++- .../bare_repo_config | 4 + .../QB08-047__push_revert_commit/cvs_check.py | 16 +++ .../git-repos.tar.bz2 | Bin 0 -> 5645 bytes .../QB08-047__push_revert_commit/hooks_config | 4 + .../QB08-047__push_revert_commit/test.py | 96 ++++++++++++++++++ 7 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/QB08-047__push_revert_commit/bare_repo_config create mode 100755 testsuite/tests/QB08-047__push_revert_commit/cvs_check.py create mode 100644 testsuite/tests/QB08-047__push_revert_commit/git-repos.tar.bz2 create mode 100644 testsuite/tests/QB08-047__push_revert_commit/hooks_config create mode 100644 testsuite/tests/QB08-047__push_revert_commit/test.py diff --git a/hooks/git.py b/hooks/git.py index ec68d1a..ea45b36 100644 --- a/hooks/git.py +++ b/hooks/git.py @@ -504,3 +504,22 @@ def diff_tree(*args, **kwargs): filename)) return result + + +def is_revert_commit(rev): + """Return True if the given commit appears to be a revert commit. + + PARAMETERS + rev: A commit revision (string with the commit's SHA1 or reference + name). + """ + # We detect such commits by searching for specific patterns that + # the "git revert" command automatically includes in the default + # revision log of such commits, hoping that a user is not deleting + # them afterwards. + raw_revlog = git.log('-1', rev, pretty='format:%B') + if 'This reverts commit' in raw_revlog: + return True + + # No recognizable pattern. Probably not a revert commit. + return False diff --git a/hooks/updates/__init__.py b/hooks/updates/__init__.py index 577d2a5..c5d8181 100644 --- a/hooks/updates/__init__.py +++ b/hooks/updates/__init__.py @@ -3,7 +3,7 @@ from config import git_config, SUBJECT_MAX_SUBJECT_CHARS from errors import InvalidUpdate from git import (git, get_object_type, is_null_rev, commit_parents, - commit_rev) + commit_rev, is_revert_commit) from os.path import expanduser, isfile, getmtime from pre_commit_checks import (check_revision_history, style_check_commit, check_filename_collisions, @@ -231,7 +231,18 @@ class AbstractUpdate(object): # handled by the __no_cvs_check_user_override method. return + # Create a list of commits that were added, but with revert + # commits being filtered out. We have decided that revert commits + # should not be subject to any check (QB08-047). This allows + # users to quickly revert a commit if need be, without having + # to worry about bumping into any check of any kind. added = self.added_commits + for commit in added: + if is_revert_commit(commit.rev): + debug('revert commit detected,' + ' all checks disabled for this commit: %s' % commit.rev) + added.remove(commit) + if not added: # There are no new commits, so nothing further to check. return diff --git a/testsuite/tests/QB08-047__push_revert_commit/bare_repo_config b/testsuite/tests/QB08-047__push_revert_commit/bare_repo_config new file mode 100644 index 0000000..07d359d --- /dev/null +++ b/testsuite/tests/QB08-047__push_revert_commit/bare_repo_config @@ -0,0 +1,4 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true diff --git a/testsuite/tests/QB08-047__push_revert_commit/cvs_check.py b/testsuite/tests/QB08-047__push_revert_commit/cvs_check.py new file mode 100755 index 0000000..0b71aa0 --- /dev/null +++ b/testsuite/tests/QB08-047__push_revert_commit/cvs_check.py @@ -0,0 +1,16 @@ +#! /usr/bin/env python +"""A dummy cvs_check program that FAILs all files. +""" +import sys + +# To help with testing, print a trace containing the name of the module +# and the names of the files being checked. +print "cvs_check: %s < %s" % ( + ' '.join(["`%s'" % arg for arg in sys.argv[1:]]), + ' '.join(["`%s'" % arg for arg in sys.stdin.read().splitlines(False)])) + +filenames = sys.stdin.read().splitlines(False) + +print >> sys.stderr, \ + 'ERROR: %s: Copyright year in header is not up to date' % filenames[0] +sys.exit(1) diff --git a/testsuite/tests/QB08-047__push_revert_commit/git-repos.tar.bz2 b/testsuite/tests/QB08-047__push_revert_commit/git-repos.tar.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..11f90e77d998e77e18a625cec208646526125f99 GIT binary patch literal 5645 zcmZ>Y%CIzaj8qGby!ou8oyz7SDXtjWUw``IsRJg%dEh_z#zrez`KIYftRfT#db~u6fP!*Nt1<%bAs9| z6Q-n$8U7+X%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pP!sr2a?=NPpCCx%-e3g0&^Z(EL{?o$5x*_SUvE78H zAJui6_02R);=g`~o%mEEKaZm-vr*~O-Z#hQ9?zel=J5S)>D&q)&bz;5ZTD+Gn%7>F z*F3r0_?5CqaD1;(Da*`+OvVR#ug)87J8?>4@t(hq$INPjWWImpmp^m<)BU4i51;94 z6hwbl{5_Mgh2>zF)74XaCW+@NmR-2+*D}|5Ze}FclE3*Ov!ajGEqN+%IKp=#TNFEU z;N58!Qyk3<^p4Hd^jrAQReF=k!mn?2&J^UH(O7ik}~@cKXtl6#%?XnzBdaSw(F)|%6L9Yd*)?v*{H*>O|uS*zB9Ssa3*}_8OiJ? zdD?#%3wBKM+;d*^t6oMQO+?v@+9Hxxf)ea+_g+`D42_Vjz}-a31} zI(@X8mu>s!beoc@pTgEl-g~5bU*uh;6DG}9`(aI79LN98mDZ1SZ}Oj$W%oT7)A{t& z`7bFpobeYdZ!h0e{qf;fX^%tKq#s`Dx!w0nd4i|y^qS3~)6QQCeHgZWqtPFE$D3?n z>n@&F_^ZbIqkqM>gR2cbCR_H3edDT?EVPYLeJYr_%y9AH3-6_TXB4f@7E13r>zQ1@ z6FA?z-C^QYhd%bB|0j7*WcHrPrjhx^d$q5!)MeR2mcX!|QZTrq7HMjT3U%vC7I#<4vwrx`KG zKi|-Kv*vO`+S%gF2AKtxEsX3cm-qcHoILmX!EIX_Hq master (hook declined) +error: failed to push some refs to '../bare/repo.git' +""" + + self.assertNotEqual(p.status, 0, p.image) + self.assertRunOutputEqual(p, expected_out) + + def test_push_commit_on_revert(self): + """Try pushing one single-file commit on revert. + + This verifies that all checks are disabled when pushing + a commit which has been created using "git revert". In + particular, this commit violates a number of requirements + in the revision log. And the cvs_check.py script is also + set up to always return an error, so this will allow us + to verify that no file is style-checked. + """ + cd ('%s/repo' % TEST_DIR) + + # Push master to the `origin' remote. The delta should be one + # commit with one file being modified. + p = Run('git push origin revert'.split()) + expected_out = """\ +remote: DEBUG: Content-Type: text/plain; charset="us-ascii" +remote: MIME-Version: 1.0 +remote: Content-Transfer-Encoding: 7bit +remote: From: Test Suite +remote: To: git-hooks-ci@example.com +remote: Bcc: file-ci@gnat.com +remote: Subject: [repo/revert] Revert "New file: a." +remote: X-Act-Checkin: repo +remote: X-Git-Author: Joel Brobecker +remote: X-Git-Refname: refs/heads/revert +remote: X-Git-Oldrev: d065089ff184d97934c010ccd0e7e8ed94cb7165 +remote: X-Git-Newrev: d669d669fcbdeab1eedf9756ce1ef5a62c4f97db +remote: +remote: commit d669d669fcbdeab1eedf9756ce1ef5a62c4f97db +remote: Author: Joel Brobecker +remote: Date: Thu Nov 9 06:05:21 2017 -0800 +remote: +remote: Revert "New file: a." +remote: +remote: This reverts commit d065089ff184d97934c010ccd0e7e8ed94cb7165. +remote: +remote: No TN included as we want to verify that revert commits don't go through any check of any kind (including lines too long like this one). +remote: +remote: Diff: +remote: --- +remote: a | 3 --- +remote: 1 file changed, 3 deletions(-) +remote: +remote: diff --git a/a b/a +remote: deleted file mode 100644 +remote: index 01d0f12..0000000 +remote: --- a/a +remote: +++ /dev/null +remote: @@ -1,3 +0,0 @@ +remote: -Some file. +remote: -Second line. +remote: -Third line. +To ../bare/repo.git + d065089..d669d66 revert -> revert +""" + + self.assertEqual(p.status, 0, p.image) + self.assertRunOutputEqual(p, expected_out) + +if __name__ == '__main__': + runtests()