Bug 430523 - Provide an Extension point which allows a plugin from stopping a commit
Summary: Provide an Extension point which allows a plugin from stopping a commit
Status: NEW
Alias: None
Product: EGit
Classification: Technology
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-17 09:58 EDT by Fabio Zadrozny CLA
Modified: 2021-10-03 14:57 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabio Zadrozny CLA 2014-03-17 09:58:33 EDT
I'd like to do some checks in a plugin (to check that the user is not committing things it shouldn't). Is there a way to have an extension point called (with details on what's about to be committed) so that I can give a message and stop such a commit from happening? (i.e.: which'd be a sort of pre-commit hook which plugins can act on)
Comment 1 Andrey Loskutov CLA 2014-07-15 08:58:34 EDT
I'm second to request this: We want enforce validity check for Jira ticket numbers if commit message contains something like "RESOLVED: JIRA-123".

What we need is something similar to the "wizard page" validating style where 3rd party can contribute validation check(s) for the upcoming operation.

The most obvious place to integrate such pre commit check would be in

org.eclipse.egit.ui.internal.commit.CommitUI.performCommit(Repository, CommitOperation, boolean)

code.

To do this, CommitOperation could extend BaseOperation and CommitUI would add pre/post commit tasks read from extension registry. Unfortunately   IEGitOperation.PreExecuteTask does not have access to the actual operation which makes this API unusable for our needs.

However, IEGitOperation can define PreExecuteValidator interface with the following signature:

    /**
     * Validator which will be asked for confirmation before execution begins
     */
    interface PreExecuteValidator<T extends IEGitOperation> {

        /**
         * Validates given task before execution
         *
         * @param operation
         *            the task to validate upfront
         *
         * @param repository
         *            the git repository
         *
         * @param monitor
         *            a progress monitor, or <code>null</code> if progress
         *            reporting and cancellation are not desired
         * @return   
         *            status object with the result of the validation. The
         *            operation will be executed only of the status is OK.
         */
        IStatus preExecute(T operation, Repository repository, IProgressMonitor monitor);
    }

The extension would expect clients contributing PreExecuteValidator for commit (or possibly other operation).

Additionally to the use in the CommitUI.performCommit() code,it would be nice to have something validating commit messages "on typing" in the staging view/commit dialog, but this is for another bug.