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>
This commit is contained in:
16
git-p4.py
16
git-p4.py
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user