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"),
1592
+ help="Bypass p4-pre-submit and p4-changelist hooks"),
1593
]
1594
self.description = """Submit changes from git to the perforce depot.\n
1595
The `p4-pre-submit` hook is executed if it exists and is executable. It
1598
from this script prevents `git-p4 submit` from launching.
1599
1600
One usage scenario is to run unit tests in the hook.
1601
+
1602
+ The `p4-prepare-changelist` hook is executed right after preparing the default
1603
+ changelist message and before the editor is started. It takes one parameter,
1604
+ the name of the file that contains the changelist text. Exiting with a non-zero
1605
+ status from the script will abort the process.
1606
+
1607
+ The purpose of the hook is to edit the message file in place, and it is not
1608
+ supressed by the `--no-verify` option. This hook is called even if
1609
+ `--prepare-p4-only` is set.
1610
+
1611
+ The `p4-changelist` hook is executed after the changelist message has been
1612
+ edited by the user. It can be bypassed with the `--no-verify` option. It
1613
+ takes a single parameter, the name of the file that holds the proposed
1614
+ changelist text. Exiting with a non-zero status causes the command to abort.
1615
+
1616
+ The hook is allowed to edit the changelist file and can be used to normalize
1617
+ the text into some project standard format. It can also be used to refuse the
1618
+ Submit after inspect the message file.
1619
+
1620
+ The `p4-post-changelist` hook is invoked after the submit has successfully
1621
+ occured in P4. It takes no parameters and is meant primarily for notification
1622
+ and cannot affect the outcome of the git p4 submit action.
1623
"""
1624
1625
self.usage += " [name of git branch to submit into perforce depot]"
2127
submitted = False
2128
2129
try:
2130
+ # Allow the hook to edit the changelist text before presenting it
2131
+ # to the user.
2132
+ if not run_git_hook("p4-prepare-changelist", [fileName]):
2133
+ return False
2134
2135
if self.prepare_p4_only:
2136
#
2170
return True
2171
2172
if self.edit_template(fileName):
2173
+ if not self.no_verify:
2174
+ if not run_git_hook("p4-changelist", [fileName]):
2175
+ print("The p4-changelist hook failed.")
2176
+ sys.stdout.flush()
2177
+ return False
2178
+
2179
# read the edited message and submit
2180
tmpFile = open(fileName, "rb")
2181
message = tmpFile.read()
2213
2214
submitted = True
2215
2216
+ run_git_hook("p4-post-changelist")
2217
finally:
2218
# Revert changes if we skip this patch
2219
if not submitted or self.shelve: