@matheusbsbs / matheus-bagliano / commits / 4935c458c2
Fork 0

git-p4: add --no-verify option

Add new command line option --no-verify: Add a new command line option "--no-verify" to the Submit command of git-p4.py. This option will function in the spirit of the existing --no-verify command line option found in git commit. It will cause the P4 Submit function to ignore the existing p4-pre-submit. Change the execution of the existing trigger p4-pre-submit to honor the --no-verify option. Before exiting on failure of this hook, display text to the user explaining which hook has failed and the impact of using the --no-verify option. Change the call of the p4-pre-submit hook to use the new run_git_hook function. This is in preparation of additional hooks to be added. Signed-off-by: Ben Keene <seraphire@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ben Keene committed Feb 11, 2020 at 18:58 UTC 4935c458c2ef301d720980eb94de4b631fe47128
3 files changed +31 -16
Documentation/git-p4.txt
+8 -2
@@ -374,14 +374,20 @@ These options can be used to modify 'git p4 submit' behavior.
374 been submitted. Implies --disable-rebase. Can also be set with
375 git-p4.disableP4Sync. Sync with origin/master still goes ahead if possible.
376
377 -Hook for submit
378 -~~~~~~~~~~~~~~~
377 +Hooks for submit
378 +----------------
379 +
380 +p4-pre-submit
381 +~~~~~~~~~~~~~
382 +
383 The `p4-pre-submit` hook is executed if it exists and is executable.
384 The hook takes no parameters and nothing from standard input. Exiting with
385 non-zero status from this script prevents `git-p4 submit` from launching.
386 +It can be bypassed with the `--no-verify` command line option.
387
388 One usage scenario is to run unit tests in the hook.
389
390 +
391 Rebase options
392 ~~~~~~~~~~~~~~
393 These options can be used to modify 'git p4 rebase' behavior.
Documentation/githooks.txt
+4 -1
@@ -520,7 +520,10 @@ p4-pre-submit
520
521 This hook is invoked by `git-p4 submit`. It takes no parameters and nothing
522 from standard input. Exiting with non-zero status from this script prevent
523 -`git-p4 submit` from launching. Run `git-p4 submit --help` for details.
523 +`git-p4 submit` from launching. It can be bypassed with the `--no-verify`
524 +command line option. Run `git-p4 submit --help` for details.
525 +
526 +
527
528 post-index-change
529 ~~~~~~~~~~~~~~~~~
git-p4.py
+19 -13
@@ -1588,13 +1588,17 @@ class P4Submit(Command, P4UserMap):
1588 "work from a local git branch that is not master"),
1589 optparse.make_option("--disable-p4sync", dest="disable_p4sync", action="store_true",
1590 help="Skip Perforce sync of p4/master after submit or shelve"),
1591 + optparse.make_option("--no-verify", dest="no_verify", action="store_true",
1592 + help="Bypass p4-pre-submit"),
1593 ]
1594 self.description = """Submit changes from git to the perforce depot.\n
1593 - The `p4-pre-submit` hook is executed if it exists and is executable.
1594 - The hook takes no parameters and nothing from standard input. Exiting with
1595 - non-zero status from this script prevents `git-p4 submit` from launching.
1595 + The `p4-pre-submit` hook is executed if it exists and is executable. It
1596 + can be bypassed with the `--no-verify` command line option. The hook takes
1597 + no parameters and nothing from standard input. Exiting with a non-zero status
1598 + from this script prevents `git-p4 submit` from launching.
1599
1597 - One usage scenario is to run unit tests in the hook."""
1600 + One usage scenario is to run unit tests in the hook.
1601 + """
1602
1603 self.usage += " [name of git branch to submit into perforce depot]"
1604 self.origin = ""
@@ -1612,6 +1616,7 @@ class P4Submit(Command, P4UserMap):
1616 self.exportLabels = False
1617 self.p4HasMoveCommand = p4_has_move_command()
1618 self.branch = None
1619 + self.no_verify = False
1620
1621 if gitConfig('git-p4.largeFileSystem'):
1622 die("Large file system not supported for git-p4 submit command. Please remove it from config.")
@@ -2405,16 +2410,17 @@ class P4Submit(Command, P4UserMap):
2410 sys.exit("number of commits (%d) must match number of shelved changelist (%d)" %
2411 (len(commits), num_shelves))
2412
2408 - try:
2409 - if not run_git_hook("p4-pre-submit"):
2410 - print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nYou can skip " \
2411 - "this pre-submission check by adding\nthe command line option '--no-verify', " \
2412 - "however,\nthis will also skip the p4-changelist hook as well.")
2413 + if not self.no_verify:
2414 + try:
2415 + if not run_git_hook("p4-pre-submit"):
2416 + print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nYou can skip " \
2417 + "this pre-submission check by adding\nthe command line option '--no-verify', " \
2418 + "however,\nthis will also skip the p4-changelist hook as well.")
2419 + sys.exit(1)
2420 + except Exception as e:
2421 + print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nThe hook failed "\
2422 + "with the error '{0}'".format(e.message) )
2423 sys.exit(1)
2414 - except Exception as e:
2415 - print("\nThe p4-pre-submit hook failed, aborting the submit.\n\nThe hook failed "\
2416 - "with the error '{0}'".format(e.message) )
2417 - sys.exit(1)
2424
2425 #
2426 # Apply the commits, one at a time. On failure, ask if should