git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-p4: Add hook p4-pre-pedit-changelist
@ 2020-01-20 21:17 Ben Keene via GitGitGadget
  2020-01-21 23:05 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 57+ messages in thread
From: Ben Keene via GitGitGadget @ 2020-01-20 21:17 UTC (permalink / raw)
  To: git; +Cc: Ben Keene, Ben Keene

From: Ben Keene <seraphire@gmail.com>

Add an additional hook to the git-p4 command to allow a hook to modify
the text of the changelist prior to displaying the p4editor command.

This hook will be called prior to checking for the flag
"--prepare-p4-only".

The hook is optional, if it does not exist, it will be skipped.

The hook takes a single parameter, the filename of the temporary file
that contains the P4 submit text.

The hook should return a zero exit code on success or a non-zero exit
code on failure.  If the hook returns a non-zero exit code, git-p4
will revert the P4 edits by calling p4_revert(f) on each file that was
flagged as edited and then it will return False so the calling method
may continue as it does in existing failure cases.

Signed-off-by: Ben Keene <seraphire@gmail.com>
---
    git-p4: Add hook p4-pre-pedit-changelist
    
    Our company's workflow requires that our P4 check-in messages have a
    specific format. A helpful feature in the GIT-P4 program would be a hook
    that occurs after the P4 change list is created but before it is
    displayed in the editor that would allow an external program to possibly
    edit the changelist text.
    
    My suggestion for the hook name is p4-pre-edit-changelist.
    
    It would take a single parameter, the full path of the temporary file.
    If the hook returns a non-zero exit code, it would cancel the current P4
    submit.
    
    The hook should be optional.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-698%2Fseraphire%2Fseraphire%2Fp4-hook-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-698/seraphire/seraphire/p4-hook-v1
Pull-Request: https://github.com/git/git/pull/698

 git-p4.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/git-p4.py b/git-p4.py
index 40d9e7c594..1f8c7383df 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -2026,6 +2026,17 @@ def applyCommit(self, id):
         tmpFile.write(submitTemplate)
         tmpFile.close()
 
+        # Run the pre-edit hook to allow programmatic update to the changelist
+        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-edit-changelist")
+        if os.path.isfile(hook_file) and os.access(hook_file, os.X_OK) and subprocess.call([hook_file, fileName]) != 0:
+            for f in editedFiles:
+                p4_revert(f)
+            return False
+
         if self.prepare_p4_only:
             #
             # Leave the p4 tree prepared, and the submit template around

base-commit: 232378479ee6c66206d47a9be175e3a39682aea6
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 57+ messages in thread

end of thread, other threads:[~2020-02-14 14:45 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-20 21:17 [PATCH] git-p4: Add hook p4-pre-pedit-changelist Ben Keene via GitGitGadget
2020-01-21 23:05 ` Junio C Hamano
2020-01-29 10:13   ` Luke Diamand
2020-01-29 19:05     ` Junio C Hamano
2020-01-29 21:23       ` Luke Diamand
2020-01-30  1:37       ` Junio C Hamano
2020-01-30 14:20         ` Ben Keene
2020-01-30 18:39           ` Junio C Hamano
2020-01-30  1:51 ` Bryan Turner
2020-01-30 13:45   ` Ben Keene
2020-01-31 21:58 ` [PATCH v2 0/4] git-p4: add hook p4-pre-edit-changelist Ben Keene via GitGitGadget
2020-01-31 21:58   ` [PATCH v2 1/4] git-p4: rewrite prompt to be Windows compatible Ben Keene via GitGitGadget
2020-01-31 21:58   ` [PATCH v2 2/4] git-p4: create new method gitRunHook Ben Keene via GitGitGadget
2020-02-04 20:40     ` Junio C Hamano
2020-02-05 19:56       ` Ben Keene
2020-02-05 21:42         ` Junio C Hamano
2020-02-06 14:00           ` Ben Keene
2020-02-06 18:26             ` Junio C Hamano
2020-01-31 21:58   ` [PATCH v2 3/4] git-p4: add hook p4-pre-edit-changelist Ben Keene via GitGitGadget
2020-01-31 21:58   ` [PATCH v2 4/4] git-p4: add p4 submit hooks Ben Keene via GitGitGadget
2020-02-04 20:50     ` Junio C Hamano
2020-02-06 15:15   ` [PATCH v3 0/5] git-p4: add hook p4-pre-edit-changelist Ben Keene via GitGitGadget
2020-02-06 15:15     ` [PATCH v3 1/5] git-p4: rewrite prompt to be Windows compatible Ben Keene via GitGitGadget
2020-02-06 19:28       ` Junio C Hamano
2020-02-10 15:49         ` Ben Keene
2020-02-06 15:15     ` [PATCH v3 2/5] git-p4: create new function run_git_hook Ben Keene via GitGitGadget
2020-02-06 19:42       ` Junio C Hamano
2020-02-10 19:03         ` Ben Keene
2020-02-06 15:15     ` [PATCH v3 3/5] git-p4: add --no-verify option Ben Keene via GitGitGadget
2020-02-06 19:42       ` Junio C Hamano
2020-02-10 16:21         ` Ben Keene
2020-02-06 15:15     ` [PATCH v3 4/5] git-p4: restructure code in submit Ben Keene via GitGitGadget
2020-02-06 15:15     ` [PATCH v3 5/5] git-p4: add p4 submit hooks Ben Keene via GitGitGadget
2020-02-10 22:06     ` [PATCH v4 0/6] git-p4: add hooks for p4-changelist Ben Keene via GitGitGadget
2020-02-10 22:06       ` [PATCH v4 1/6] git-p4: rewrite prompt to be Windows compatible Ben Keene via GitGitGadget
2020-02-10 22:06       ` [PATCH v4 2/6] git-p4: create new function run_git_hook Ben Keene via GitGitGadget
2020-02-10 22:24         ` Junio C Hamano
2020-02-10 22:06       ` [PATCH v4 3/6] git-p4: add --no-verify option Ben Keene via GitGitGadget
2020-02-10 22:06       ` [PATCH v4 4/6] git-p4: restructure code in submit Ben Keene via GitGitGadget
2020-02-10 22:06       ` [PATCH v4 5/6] git-p4: add p4 submit hooks Ben Keene via GitGitGadget
2020-02-10 22:06       ` [PATCH v4 6/6] git-4: add RCS keyword status message Ben Keene via GitGitGadget
2020-02-11 18:57       ` [PATCH v5 0/7] git-p4: add hooks for p4-changelist Ben Keene via GitGitGadget
2020-02-11 18:57         ` [PATCH v5 1/7] git-p4: rewrite prompt to be Windows compatible Ben Keene via GitGitGadget
2020-02-11 18:57         ` [PATCH v5 2/7] git-p4: create new function run_git_hook Ben Keene via GitGitGadget
2020-02-11 18:58         ` [PATCH v5 3/7] git-p4: add p4-pre-submit exit text Ben Keene via GitGitGadget
2020-02-11 18:58         ` [PATCH v5 4/7] git-p4: add --no-verify option Ben Keene via GitGitGadget
2020-02-11 18:58         ` [PATCH v5 5/7] git-p4: restructure code in submit Ben Keene via GitGitGadget
2020-02-11 18:58         ` [PATCH v5 6/7] git-p4: add p4 submit hooks Ben Keene via GitGitGadget
2020-02-11 18:58         ` [PATCH v5 7/7] git-p4: add RCS keyword status message Ben Keene via GitGitGadget
2020-02-14 14:44         ` [PATCH v6 0/7] git-p4: add hooks for p4-changelist Ben Keene via GitGitGadget
2020-02-14 14:44           ` [PATCH v6 1/7] git-p4: rewrite prompt to be Windows compatible Ben Keene via GitGitGadget
2020-02-14 14:44           ` [PATCH v6 2/7] git-p4: create new function run_git_hook Ben Keene via GitGitGadget
2020-02-14 14:44           ` [PATCH v6 3/7] git-p4: add p4-pre-submit exit text Ben Keene via GitGitGadget
2020-02-14 14:44           ` [PATCH v6 4/7] git-p4: add --no-verify option Ben Keene via GitGitGadget
2020-02-14 14:44           ` [PATCH v6 5/7] git-p4: restructure code in submit Ben Keene via GitGitGadget
2020-02-14 14:44           ` [PATCH v6 6/7] git-p4: add p4 submit hooks Ben Keene via GitGitGadget
2020-02-14 14:44           ` [PATCH v6 7/7] git-p4: add RCS keyword status message Ben Keene via GitGitGadget

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).