Re: [PATCH] git-p4: Add hook p4-pre-pedit-changelist
- From
Bryan Turner <bturner@atlassian.com>
- Date
- Jan 30, 2020, 01:51 UTC
- Message-ID
- <CAGyf7-FS8k4gXM-C+qhW8YNGKC57Gh-NY0hM0A08YoFDSETQzg@mail.gmail.com>
- In-Reply-To
- <pull.698.git.git.1579555036314.gitgitgadget@gmail.com>
On Mon, Jan 20, 2020 at 1:17 PM Ben Keene via GitGitGadget <gitgitgadget@gmail.com> wrote:
Show 59 quoted lines
>
> 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")The commit subject and the resulting email say "p4-pre-pedit", and I see Junio is asking about "p4-pre-pedit", but the actual code, and the scissors message, both say "p4-pre-edit". So which is it intended to be? "edit", or "pedit"?
Show 12 quoted lines
> + 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