diff options
author | Chen Bin <chenbin.sh@gmail.com> | 2018-07-27 21:22:22 +1000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-08-01 13:37:18 -0700 |
commit | 251c8c501faf7a7910edb7c9e19692988dcac6a8 (patch) | |
tree | abdf73ddbb55bae86391f683b7a9eeb2a6c9b4db /git-p4.py | |
parent | Fourth batch for 2.19 cycle (diff) | |
download | tgif-251c8c501faf7a7910edb7c9e19692988dcac6a8.tar.xz |
git-p4: add the `p4-pre-submit` hook
The `p4-pre-submit` hook is executed before git-p4 submits code.
If the hook exits with non-zero value, submit process not start.
Signed-off-by: Chen Bin <chenbin.sh@gmail.com>
Reviewed-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-p4.py')
-rwxr-xr-x | git-p4.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -1494,7 +1494,13 @@ class P4Submit(Command, P4UserMap): optparse.make_option("--disable-p4sync", dest="disable_p4sync", action="store_true", help="Skip Perforce sync of p4/master after submit or shelve"), ] - self.description = "Submit changes from git to the perforce depot." + self.description = """Submit changes from git to the perforce depot.\n + The `p4-pre-submit` hook is executed if it exists and is executable. + The hook takes no parameters and nothing from standard input. Exiting with + non-zero status from this script prevents `git-p4 submit` from launching. + + One usage scenario is to run unit tests in the hook.""" + self.usage += " [name of git branch to submit into perforce depot]" self.origin = "" self.detectRenames = False @@ -2303,6 +2309,14 @@ class P4Submit(Command, P4UserMap): sys.exit("number of commits (%d) must match number of shelved changelist (%d)" % (len(commits), num_shelves)) + hooks_path = gitConfig("core.hooksPath") + if len(hooks_path) <= 0: + hooks_path = os.path.join(os.environ.get("GIT_DIR", ".git"), "hooks") + + hook_file = os.path.join(hooks_path, "p4-pre-submit") + if os.path.isfile(hook_file) and os.access(hook_file, os.X_OK) and subprocess.call([hook_file]) != 0: + sys.exit(1) + # # Apply the commits, one at a time. On failure, ask if should # continue to try the rest of the patches, or quit. |