开发者

Automatic SVN sync Eclipse

开发者 https://www.devze.com 2023-03-20 02:27 出处:网络
I\'m st开发者_C百科arting with SVN. Is there any way of configuring subclipse to automatically sync with the repo in order to know when a file was modified as soon as possible?In case of Subversive (a

I'm st开发者_C百科arting with SVN. Is there any way of configuring subclipse to automatically sync with the repo in order to know when a file was modified as soon as possible?


In case of Subversive (and I believe, the same option should be available in case of Subclipse as well) the Synchronize view allows automatic synchronization.

Initialize a synchronization using either Team/Synchronize from the context menu of some projects, or open the Team Synchronizing perspective, and select the set of synchronized projects using the Synchronize button of the Synchronize view (the button is the first button of the view toolbar).

Then the synchronization is performed, and the changes are displayed there. At this point, you could select the Schedule... option from the view menu (down-pointing triangle icon near the top right corner of the Synchronize view), and there you could set the synchronization.

AFAIK this synchronization does not update your workspace automatically (that is a sound idea, e.g. conflict resolution must happen manually), but at least you can look at the changes when needed.


You really do not want to do this. Synchronization with repository is a heavy operation with a lot of side effects. For example you can change file that is being changed in repository now. You do not want to get mismatch of your and other's changes while you are working. You wish to work and then update all files together and resolve conflicts (if any)


In the context menu (right-click on project) there should be an option "Team>Synchronize with repository".

I did find this tutorial useful.


As far as I know, subclipse provides no such option. You could write a cron job that uses the SVN command-line tools to perform an update at regular intervals, but I wouldn't recommend this. You can't automate synchronizing with SVN because updating may cause conflicts which cannot be automatically merged.


Although I agree that in some situations it might be a bad idea to have an automated commit feature, there might be some reasons why you could want to have this option anyway.

I created a small EASE-script that replaced my regular save key binding (ctrl+s). It first saves the file, tries to update the file (which also automatically merges the versions if possible or creates conflicts in which case the script terminates) and commits the file at last.

// ********************************************************************************
// name                 : SaveUpdateCommit
// keyboard             : CTRL+S
// toolbar              : PHP Explorer
// script-type          : JavaScript
// description          : Save a file, update from the repository and commit automatically
// ********************************************************************************

var UI = loadModule("/System/UI");


UI.executeUI(function(){
var editor = UI.getActiveEditor();
editor.doSave(null);

var site = editor.getSite();
var commandService = site.getService(org.eclipse.ui.commands.ICommandService);
var handlerService = site.getService(org.eclipse.ui.handlers.IHandlerService);

var subclipse = org.tigris.subversion.subclipse.core.SVNProviderPlugin.getPlugin();

try
{
var file = editor.getEditorInput().getFile();
}
catch(e)
{
    return;
}
var filePath = file.getFullPath();
var project = file.getProject();
var projectPath = project.getWorkingLocation(subclipse.toString());
var workspace = project.getWorkspace();

var localFile = org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot.getSVNFileFor(file);
localFile.refreshStatus();
if(localFile.isDirty()){
    var remoteFile = localFile.getBaseResource();

    var empty = java.lang.reflect.Array.newInstance(org.eclipse.core.resources.IResource, 0);
    var commitFiles = java.lang.reflect.Array.newInstance(org.eclipse.core.resources.IResource, 1); 
    commitFiles[0] = remoteFile.getResource();

    var update = new org.tigris.subversion.subclipse.ui.operations.UpdateOperation(editor, remoteFile.getResource(), org.tigris.subversion.svnclientadapter.SVNRevision.HEAD);
    update.run(null);

    var commit = new org.tigris.subversion.subclipse.ui.operations.CommitOperation(editor, empty, empty, empty, commitFiles, "AutoCommit", false);
    commit.run(null);
}

For this, you need to install Eclipse EASE (http://download.eclipse.org/ease/update/release) and to make this script available through the settings. Also, the script needs UI-access, again this needs to be configured in the settings.

So for your needs you may want to change that behavior to frequent updates. I never played around with timers in eclipse, but i guess it is possible though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号