diff options
| author | Junio C Hamano <gitster@pobox.com> | 2018-08-15 15:08:27 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2018-08-15 15:08:27 -0700 |
| commit | dd4ab3eaaa46e896ccbada61799f825011601cb0 (patch) | |
| tree | 8099fbdfa0ecd8c3430441fbb671e7cd6882410c /git-p4.py | |
| parent | Merge branch 'js/vscode' (diff) | |
| parent | git-p4: add the `p4-pre-submit` hook (diff) | |
| download | git-dd4ab3eaaa46e896ccbada61799f825011601cb0.tar.gz git-dd4ab3eaaa46e896ccbada61799f825011601cb0.zip | |
Merge branch 'cb/p4-pre-submit-hook'
"git p4 submit" learns to ask its own pre-submit hook if it should
continue with submitting.
* cb/p4-pre-submit-hook:
git-p4: add the `p4-pre-submit` hook
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. |
