Client side pre-commit hook #238
stefanzugal
started this conversation in
Ideas
Replies: 1 comment
-
Hi, in case anyone else looking for a solution - here is how we hacked it. Apparently, neither nice not particularly stable - but in our case, it does the job. The basic idea:
And here is the code (validation and closing of shell omitted): import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IStartup;
public class PreCommitValidationHook implements IStartup {
private class PreCommitValidationHookRunnable implements Runnable {
/**
* The last seen commit shell.
*/
private Shell lastProcessedShell;
@Override
public void run() {
while (true) {
Display.getDefault().asyncExec(() -> {
Shell activeShell = Display.getDefault().getActiveShell();
if (activeShell != null && activeShell.getText().equals("Commit")) {
if (lastProcessedShell == null || !lastProcessedShell.equals(activeShell)) {
lastProcessedShell = activeShell;
// perform the desired validation here; close the shell in case the user shall not proceed
validate(lastProcessedShell);
}
}
});
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
}
}
}
@Override
public void earlyStartup() {
Thread thread = new Thread(new PreCommitValidationHookRunnable());
thread.setDaemon(true);
thread.start();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
we have been using Subversive so far and now switched to Subclipse. In Subversive, we have had a pre-commit validation on the client side that runs in the workspace before committing any resources (see: https://www.eclipse.org/forums/index.php?t=msg&th=173903&goto=1726585&#msg_1726585).
I am wondering whether similar functionality is possible with Subclipse as well? I browsed through the extension points and code, but did not find any place where I could hook code that is executed before the commit. I am fully aware that SVN provides server-side pre-commit hooks, but we would like to run the code in the local workspace. Particularly, we validate our code before committing, e.g., checking for code that violates our coding rules.
Looking forward to any ideas and pointers,
Stefan
Beta Was this translation helpful? Give feedback.
All reactions