# HG changeset patch # User yannick@valuya.be # Date 1359066608 -3600 # Node ID 78a01116b802b98dea10360a46e58a98b75eed11 # Parent 7a0c84058ab03b5e3ef06ccddf708e4675944f8f http://netbeans.org/bugzilla/show_bug.cgi?id=221661 diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/Annotator.java --- a/git/src/org/netbeans/modules/git/Annotator.java Sat Jan 12 22:41:09 2013 +0100 +++ b/git/src/org/netbeans/modules/git/Annotator.java Thu Jan 24 23:30:08 2013 +0100 @@ -80,6 +80,10 @@ import org.netbeans.modules.git.ui.menu.TagMenu; import org.netbeans.modules.git.ui.merge.MergeRevisionAction; import org.netbeans.modules.git.ui.output.OpenOutputAction; +import org.netbeans.modules.git.ui.rebase.AbortRebaseAction; +import org.netbeans.modules.git.ui.rebase.ContinueRebaseAction; +import org.netbeans.modules.git.ui.rebase.RebaseAction; +import org.netbeans.modules.git.ui.rebase.SkipRebaseAction; import org.netbeans.modules.git.ui.repository.RepositoryBrowserAction; import org.netbeans.modules.git.ui.repository.RepositoryInfo; import org.netbeans.modules.git.ui.reset.ResetAction; @@ -172,6 +176,22 @@ actions.add(new TagMenu(ActionDestination.MainMenu, null)); actions.add(new CheckoutMenu(ActionDestination.MainMenu, null)); actions.add(SystemAction.get(MergeRevisionAction.class)); + RebaseAction rebaseAction = SystemAction.get(RebaseAction.class); + if (rebaseAction.isEnabled()) { + actions.add(rebaseAction); + } + ContinueRebaseAction continueRebaseAction = SystemAction.get(ContinueRebaseAction.class); + if (continueRebaseAction.isEnabled()) { + actions.add(continueRebaseAction); + } + SkipRebaseAction skipRebaseAction = SystemAction.get(SkipRebaseAction.class); + if (skipRebaseAction.isEnabled()) { + actions.add(skipRebaseAction); + } + AbortRebaseAction abortRebaseAction = SystemAction.get(AbortRebaseAction.class); + if (abortRebaseAction.isEnabled()) { + actions.add(abortRebaseAction); + } ResolveConflictsAction a = SystemAction.get(ResolveConflictsAction.class); if (a.isEnabled()) { actions.add(null); diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/client/GitClient.java --- a/git/src/org/netbeans/modules/git/client/GitClient.java Sat Jan 12 22:41:09 2013 +0100 +++ b/git/src/org/netbeans/modules/git/client/GitClient.java Thu Jan 24 23:30:08 2013 +0100 @@ -63,6 +63,7 @@ import org.netbeans.libs.git.GitMergeResult; import org.netbeans.libs.git.GitPullResult; import org.netbeans.libs.git.GitPushResult; +import org.netbeans.libs.git.GitRebaseResult; import org.netbeans.libs.git.GitRemoteConfig; import org.netbeans.libs.git.GitRepositoryState; import org.netbeans.libs.git.GitRevertResult; @@ -72,6 +73,7 @@ import org.netbeans.libs.git.GitTransportUpdate; import org.netbeans.libs.git.GitUser; import org.netbeans.libs.git.SearchCriteria; +import org.netbeans.libs.git.jgit.commands.RebaseCommand.Operation; import org.netbeans.libs.git.progress.NotificationListener; import org.netbeans.libs.git.progress.ProgressMonitor; import org.netbeans.modules.git.Git; @@ -579,6 +581,16 @@ }, "merge"); //NOI18N } + public GitRebaseResult rebase (final String revision, final Operation operation, final ProgressMonitor monitor) throws GitException.CheckoutConflictException, GitException { + return new CommandInvoker().runMethod(new Callable() { + + @Override + public GitRebaseResult call () throws Exception { + return delegate.rebase(revision, operation, monitor); + } + }, "rebase"); //NOI18N + } + public GitPullResult pull (final String remote, final List fetchRefSpecifications, final String branchToMerge, final ProgressMonitor monitor) throws GitException.AuthorizationException, GitException.CheckoutConflictException, GitException.MissingObjectException, GitException { return new CommandInvoker().runMethod(new Callable() { diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/AbortRebaseAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/AbortRebaseAction.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,60 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import org.netbeans.libs.git.jgit.commands.RebaseCommand.Operation; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; + +/** + * + * @author ymajoros + */ +@ActionID(id = "org.netbeans.modules.git.ui.rebase.AbortRebaseAction", category = "Git") +@ActionRegistration(displayName = "#LBL_AbortRebaseAction_Name") +public class AbortRebaseAction extends AbstractEndRebaseAction { + + public AbortRebaseAction() { + super(Operation.ABORT); + } + +} \ No newline at end of file diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/AbstractEndRebaseAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/AbstractEndRebaseAction.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,114 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import java.io.File; +import java.util.Set; +import org.netbeans.libs.git.GitBranch; +import org.netbeans.libs.git.GitException; +import org.netbeans.libs.git.GitRepositoryState; +import org.netbeans.libs.git.jgit.commands.RebaseCommand.Operation; +import org.netbeans.modules.git.Git; +import org.netbeans.modules.git.client.GitClient; +import org.netbeans.modules.git.client.GitClientExceptionHandler; +import org.netbeans.modules.git.client.GitProgressSupport; +import org.netbeans.modules.git.ui.actions.SingleRepositoryAction; +import org.netbeans.modules.git.ui.repository.RepositoryInfo; +import org.netbeans.modules.git.utils.GitUtils; +import org.netbeans.modules.versioning.spi.VCSContext; +import org.openide.nodes.Node; +import org.openide.util.NbBundle; + +/** + * + * @author Yannick + */ +abstract class AbstractEndRebaseAction extends SingleRepositoryAction { + + protected final Operation operation; + + public AbstractEndRebaseAction(Operation operation) { + this.operation = operation; + } + + @Override + protected boolean enable(Node[] activatedNodes) { + return isRebasing(activatedNodes); + } + + @Override + protected void performAction(File repository, File[] roots, VCSContext context) { + RepositoryInfo info = RepositoryInfo.getInstance(repository); + endRebase(repository, info, operation); + } + + protected boolean isRebasing(Node[] activatedNodes) { + VCSContext context = getCurrentContext(activatedNodes); + Set roots = GitUtils.getRepositoryRoots(context); + if (roots.size() == 1) { + return isRebasing(roots); + } + return false; + } + + protected boolean isRebasing(Set roots) { + try { + File[] repositoryArray = roots.toArray(new File[0]); + File repository = repositoryArray[0]; + GitClient client = Git.getInstance().getClient(repository, null); + GitRepositoryState repositoryState = client.getRepositoryState(GitUtils.NULL_PROGRESS_MONITOR); + return repositoryState == GitRepositoryState.REBASING; + } catch (GitException ex) { + GitClientExceptionHandler.notifyException(ex, true); + return false; + } + } + + protected void endRebase(File repository, RepositoryInfo info, Operation operation) { + endRebase(repository, info.getActiveBranch().getName().equals(GitBranch.NO_BRANCH) ? GitUtils.HEAD : info.getActiveBranch().getName(), operation); + } + + public void endRebase(final File repository, String preselectedRevision, Operation operation) { + GitProgressSupport gitProgressSupport = new EndRebaseGitProgressSupport(repository, operation); + gitProgressSupport.start(Git.getInstance().getRequestProcessor(repository), repository, NbBundle.getMessage(RebaseAction.class, "LBL_RebaseAction.progressName")); + } +} diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/Bundle.properties Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,58 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2010 Oracle and/or its affiliates. All rights reserved. +# +# Oracle and Java are registered trademarks of Oracle and/or its affiliates. +# Other names may be trademarks of their respective owners. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +# +# Contributor(s): +# +# Portions Copyrighted 2010 Sun Microsystems, Inc. + +LBL_RebaseAction_Name=R&ebase... +LBL_ContinueRebaseAction_Name=Continue rebase +LBL_SkipRebaseAction_Name=Skip rebase +LBL_AbortRebaseAction_Name=Abort rebase +LBL_RebaseAction_PopupName=Rebase Revision... +LBL_RebaseAction.progressName=Rebasing HEAD +MSG_RebaseAction.result=Rebase Result: {0}\n +MSG_RebaseAction.result.upToDate=HEAD already contains revision {0}. +MSG_RebaseAction.result.fastForward=Rebase of HEAD with {0} resulted in fast-forward; +MSG_RebaseAction.result.ok=Rebase of HEAD with {0}: ok. +MSG_RebaseAction.result.failed=Rebase of HEAD with {0} failed, HEAD was restored. For more information see the output. +MSG_RebaseAction.result.failedFiles=Rebase of HEAD with {0} failed because of these files, HEAD was restored: +MSG_RebaseAction.result.aborted=Rebase of HEAD with {0} was aborted, HEAD was restored. +MSG_RebaseAction.result.stopped=Rebase of HEAD with {0} was stopped due to a conflict, either abort or resolve or skip. +MSG_RebaseAction.result.unsupported=Rebase unsupported. +LBL_Rebase.OKButton.text=Reba&se +LBL_Rebase.title=Rebase +RebasePanel.jLabel1.text=Select a revision to rebase HEAD onto \ No newline at end of file diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/ContinueRebaseAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/ContinueRebaseAction.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,60 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import org.netbeans.libs.git.jgit.commands.RebaseCommand.Operation; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; + +/** + * + * @author ymajoros + */ +@ActionID(id = "org.netbeans.modules.git.ui.rebase.ContinueRebaseAction", category = "Git") +@ActionRegistration(displayName = "#LBL_ContinueRebaseAction_Name") +public class ContinueRebaseAction extends AbstractEndRebaseAction { + + public ContinueRebaseAction() { + super(Operation.CONTINUE); + } + +} \ No newline at end of file diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/EnableRebaseGitProgressSupport.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/EnableRebaseGitProgressSupport.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,72 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import org.netbeans.libs.git.GitException; +import org.netbeans.libs.git.GitRepositoryState; +import org.netbeans.modules.git.client.GitClient; +import org.netbeans.modules.git.client.GitClientExceptionHandler; +import org.netbeans.modules.git.client.GitProgressSupport; + +/** + * + * @author Yannick + */ +class EnableRebaseGitProgressSupport extends GitProgressSupport { + private boolean rebasePossible; + + @Override + protected void perform() { + try { + GitClient client = getClient(); + GitRepositoryState repositoryState = client.getRepositoryState(getProgressMonitor()); + rebasePossible = repositoryState.canRebase(); + } catch (GitException ex) { + GitClientExceptionHandler.notifyException(ex, true); + } + } + + public boolean isRebasePossible() { + return rebasePossible; + } + +} diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/EndRebaseGitProgressSupport.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/EndRebaseGitProgressSupport.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,105 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import java.io.File; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.libs.git.GitException; +import org.netbeans.libs.git.GitRebaseResult; +import org.netbeans.libs.git.jgit.commands.RebaseCommand.Operation; +import org.netbeans.modules.git.Git; +import org.netbeans.modules.git.client.GitClient; +import org.netbeans.modules.git.client.GitClientExceptionHandler; +import org.netbeans.modules.git.client.GitProgressSupport; +import org.netbeans.modules.git.ui.actions.GitAction; +import org.netbeans.modules.git.utils.GitUtils; +import org.openide.util.NbBundle; + +/** + * + * @author Yannick + */ +class EndRebaseGitProgressSupport extends GitProgressSupport { + + private static final Logger LOG = Logger.getLogger(EndRebaseGitProgressSupport.class.getName()); + private final File repository; + private final Operation operation; + + public EndRebaseGitProgressSupport(File repository, Operation operation) { + this.repository = repository; + this.operation = operation; + } + private String revision; + + @Override + protected void perform() { + try { + GitClient client = getClient(); + client.addNotificationListener(new DefaultFileListener(new File[]{repository})); + LOG.log(Level.FINE, "Merging revision {0} into HEAD", revision); //NOI18N + boolean cont; + RebaseResultProcessor mrp = new RebaseResultProcessor(client, repository, revision, getLogger(), getProgressMonitor()); + do { + cont = false; + try { + GitRebaseResult result = client.rebase(revision, operation, getProgressMonitor()); + mrp.processResult(result); + } catch (GitException.CheckoutConflictException ex) { + if (LOG.isLoggable(Level.FINE)) { + LOG.log(Level.FINE, "Local modifications in WT during rebase: {0} - {1}", new Object[]{repository, Arrays.asList(ex.getConflicts())}); //NOI18N + } + cont = mrp.resolveLocalChanges(ex.getConflicts()); + } + } while (cont); + } catch (GitException ex) { + GitClientExceptionHandler.notifyException(ex, true); + } finally { + setDisplayName(NbBundle.getMessage(GitAction.class, "LBL_Progress.RefreshingStatuses")); //NOI18N + Git.getInstance().getFileStatusCache().refreshAllRoots(Collections.>singletonMap(repository, Git.getInstance().getSeenRoots(repository))); + GitUtils.headChanged(repository); + } + } +} diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/Rebase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/Rebase.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,104 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import java.awt.Dialog; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import javax.swing.JButton; +import org.netbeans.modules.git.ui.repository.RevisionDialogController; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; + +/** + * + * @author ymajoros + */ +public class Rebase { + + private RebasePanel panel; + private RevisionDialogController revisionPicker; + private JButton okButton; + private DialogDescriptor dd; + private boolean valid = true; + + Rebase(File repository, File[] roots, String initialRevision) { + revisionPicker = new RevisionDialogController(repository, roots, initialRevision); + panel = new RebasePanel(revisionPicker.getPanel()); + } + + String getRevision() { + return revisionPicker.getRevision(); + } + + boolean show() { + okButton = new JButton(NbBundle.getMessage(Rebase.class, "LBL_Rebase.OKButton.text")); //NOI18N + org.openide.awt.Mnemonics.setLocalizedText(okButton, okButton.getText()); + dd = new DialogDescriptor(panel, NbBundle.getMessage(Rebase.class, "LBL_Rebase.title"), true, //NOI18N + new Object[]{okButton, DialogDescriptor.CANCEL_OPTION}, okButton, DialogDescriptor.DEFAULT_ALIGN, new HelpCtx(Rebase.class), null); + enableRevisionPanel(); + revisionPicker.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName() == RevisionDialogController.PROP_VALID) { + setValid(Boolean.TRUE.equals(evt.getNewValue())); + } + } + }); + Dialog d = DialogDisplayer.getDefault().createDialog(dd); + d.setVisible(true); + return okButton == dd.getValue(); + } + + private void enableRevisionPanel() { + setValid(valid); + } + + private void setValid(boolean flag) { + this.valid = flag; + okButton.setEnabled(flag); + dd.setValid(flag); + } +} diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/RebaseAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/RebaseAction.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,101 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import org.netbeans.modules.git.client.GitClientExceptionHandler; +import java.io.File; +import java.util.Set; +import org.netbeans.libs.git.GitBranch; +import org.netbeans.modules.git.client.GitClient; +import org.netbeans.libs.git.GitException; +import org.netbeans.libs.git.GitRepositoryState; +import org.netbeans.modules.git.Git; +import org.netbeans.modules.git.client.GitProgressSupport; +import org.netbeans.modules.git.ui.actions.SingleRepositoryAction; +import org.netbeans.modules.git.ui.repository.RepositoryInfo; +import org.netbeans.modules.git.utils.GitUtils; +import org.netbeans.modules.versioning.spi.VCSContext; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; +import org.openide.nodes.Node; +import org.openide.util.NbBundle; + +/** + * + * @author ymajoros + */ +@ActionID(id = "org.netbeans.modules.git.ui.rebase.RebaseAction", category = "Git") +@ActionRegistration(displayName = "#LBL_RebaseAction_Name") +public class RebaseAction extends SingleRepositoryAction { + + @Override + protected boolean enable(Node[] activatedNodes) { + VCSContext context = getCurrentContext(activatedNodes); + Set roots = GitUtils.getRepositoryRoots(context); + if (roots.size() == 1) { + try { + File[] repositoryArray = roots.toArray(new File[0]); + File repository = repositoryArray[0]; + GitClient client = Git.getInstance().getClient(repository, null); + GitRepositoryState repositoryState = client.getRepositoryState(GitUtils.NULL_PROGRESS_MONITOR); + return repositoryState == GitRepositoryState.SAFE; + } catch (GitException ex) { + GitClientExceptionHandler.notifyException(ex, true); + } + } + return false; + } + + @Override + protected void performAction(File repository, File[] roots, VCSContext context) { + RepositoryInfo info = RepositoryInfo.getInstance(repository); + rebase(repository, info.getActiveBranch().getName().equals(GitBranch.NO_BRANCH) ? GitUtils.HEAD : info.getActiveBranch().getName()); + } + + public void rebase(final File repository, String preselectedRevision) { + final Rebase rebase = new Rebase(repository, new File[0], preselectedRevision); + if (rebase.show()) { + GitProgressSupport gitProgressSupport = new RebaseGitProgressSupport(repository, rebase); + gitProgressSupport.start(Git.getInstance().getRequestProcessor(repository), repository, NbBundle.getMessage(RebaseAction.class, "LBL_RebaseAction.progressName")); + } + } +} \ No newline at end of file diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/RebaseGitProgressSupport.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/RebaseGitProgressSupport.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,106 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import java.io.File; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.libs.git.GitException; +import org.netbeans.libs.git.GitRebaseResult; +import org.netbeans.libs.git.jgit.commands.RebaseCommand.Operation; +import org.netbeans.modules.git.Git; +import org.netbeans.modules.git.client.GitClient; +import org.netbeans.modules.git.client.GitClientExceptionHandler; +import org.netbeans.modules.git.client.GitProgressSupport; +import org.netbeans.modules.git.ui.actions.GitAction; +import org.netbeans.modules.git.utils.GitUtils; +import org.openide.util.NbBundle; + +/** + * + * @author Yannick + */ +class RebaseGitProgressSupport extends GitProgressSupport { + + private static final Logger LOG = Logger.getLogger(GitProgressSupport.class.getName()); + private final File repository; + private final Rebase rebase; + + public RebaseGitProgressSupport(File repository, Rebase rebase) { + this.repository = repository; + this.rebase = rebase; + } + private String revision; + + @Override + protected void perform() { + try { + GitClient client = getClient(); + client.addNotificationListener(new DefaultFileListener(new File[]{repository})); + revision = rebase.getRevision(); + LOG.log(Level.FINE, "Merging revision {0} into HEAD", revision); //NOI18N + boolean cont; + RebaseResultProcessor rebaseResultProcessor = new RebaseResultProcessor(client, repository, revision, getLogger(), getProgressMonitor()); + do { + cont = false; + try { + GitRebaseResult result = client.rebase(revision, Operation.BEGIN, getProgressMonitor()); + rebaseResultProcessor.processResult(result); + } catch (GitException.CheckoutConflictException ex) { + if (LOG.isLoggable(Level.FINE)) { + LOG.log(Level.FINE, "Local modifications in WT during rebase: {0} - {1}", new Object[]{repository, Arrays.asList(ex.getConflicts())}); //NOI18N + } + cont = rebaseResultProcessor.resolveLocalChanges(ex.getConflicts()); + } + } while (cont); + } catch (GitException ex) { + GitClientExceptionHandler.notifyException(ex, true); + } finally { + setDisplayName(NbBundle.getMessage(GitAction.class, "LBL_Progress.RefreshingStatuses")); //NOI18N + Git.getInstance().getFileStatusCache().refreshAllRoots(Collections.>singletonMap(repository, Git.getInstance().getSeenRoots(repository))); + GitUtils.headChanged(repository); + } + } +} diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/RebasePanel.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/RebasePanel.form Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,54 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/RebasePanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/RebasePanel.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,105 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +/* + * RebasePanel.java + * + * Created on Jan 18, 2011, 10:50:16 AM + */ + +package org.netbeans.modules.git.ui.rebase; + +import org.netbeans.modules.git.ui.repository.RevisionDialog; + +/** + * + * @author ymajoros + */ +public class RebasePanel extends javax.swing.JPanel { + private final RevisionDialog revisionPanel; + + /** Creates new form RebasePanel */ + public RebasePanel (RevisionDialog revisionPanel) { + this.revisionPanel = revisionPanel; + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + org.netbeans.modules.git.ui.repository.RevisionDialog revisionPickerDialog1 = this.revisionPanel; + jLabel1 = new javax.swing.JLabel(); + + jLabel1.setText(org.openide.util.NbBundle.getMessage(RebasePanel.class, "RebasePanel.jLabel1.text")); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addContainerGap(184, Short.MAX_VALUE)) + .addComponent(revisionPickerDialog1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(revisionPickerDialog1, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + // End of variables declaration//GEN-END:variables + +} diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/RebaseResultProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/RebaseResultProcessor.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,141 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import javax.swing.Action; +import org.netbeans.libs.git.GitException; +import org.netbeans.libs.git.GitRebaseResult; +import org.netbeans.libs.git.GitRebaseResult.RebaseStatus; +import org.netbeans.libs.git.GitRevisionInfo; +import org.netbeans.libs.git.progress.ProgressMonitor; +import org.netbeans.modules.git.client.GitClient; +import org.netbeans.modules.git.client.GitClientExceptionHandler; +import org.netbeans.modules.git.ui.output.OutputLogger; +import org.netbeans.modules.git.utils.GitUtils; +import org.netbeans.modules.git.utils.ResultProcessor; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.NbBundle; + +/** + * + * @author Yannick + */ +public class RebaseResultProcessor extends ResultProcessor { + + private final GitClient client; + private final OutputLogger logger; + private final String revision; + + public RebaseResultProcessor(GitClient client, File repository, String revision, OutputLogger logger, ProgressMonitor pm) { + super(client, repository, revision, logger, pm); + this.client = client; + this.revision = revision; + this.logger = logger; + } + + public void processResult(GitRebaseResult result) { + StringBuilder stringBuilder = new StringBuilder(); //NOI18N + RebaseStatus rebaseStatus = result.getRebaseStatus(); + switch (rebaseStatus) { + case UP_TO_DATE: + stringBuilder.append(NbBundle.getMessage(RebaseAction.class, "MSG_RebaseAction.result.upToDate", revision)); //NOI18N + DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(stringBuilder, NotifyDescriptor.PLAIN_MESSAGE)); //NOI18N + break; + case FAST_FORWARD: + stringBuilder.append(NbBundle.getMessage(RebaseAction.class, "MSG_RebaseAction.result.fastForward", revision)); //NOI18N + DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(stringBuilder, NotifyDescriptor.PLAIN_MESSAGE)); //NOI18N + break; + case OK: + stringBuilder.append(NbBundle.getMessage(RebaseAction.class, "MSG_RebaseAction.result.ok", revision)); //NOI18N + DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(stringBuilder, NotifyDescriptor.PLAIN_MESSAGE)); //NOI18N + break; + case STOPPED: + stringBuilder.append(NbBundle.getMessage(RebaseAction.class, "MSG_RebaseAction.result.stopped", revision)); //NOI18N + DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(stringBuilder, NotifyDescriptor.PLAIN_MESSAGE)); //NOI18N + break; + case ABORTED: + stringBuilder.append(NbBundle.getMessage(RebaseAction.class, "MSG_RebaseAction.result.aborted", revision)); //NOI18N + DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(stringBuilder, NotifyDescriptor.PLAIN_MESSAGE)); //NOI18N + break; + case FAILED: + final Action openAction = logger.getOpenOutputAction(); + if (openAction != null) { + try { + EventQueue.invokeAndWait(new Runnable() { + @Override + public void run() { + openAction.actionPerformed(new ActionEvent(RebaseResultProcessor.this, ActionEvent.ACTION_PERFORMED, null)); + } + }); + } catch (InterruptedException ex) { + } catch (InvocationTargetException ex) { + } + } + stringBuilder.append(NbBundle.getMessage(RebaseAction.class, "MSG_RebaseAction.result.failedFiles", revision)); //NOI18N + printConflicts(stringBuilder, result.getFailures()); + DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(RebaseAction.class, "MSG_RebaseAction.result.failed", revision), NotifyDescriptor.ERROR_MESSAGE)); //NOI18N + break; + case NOT_SUPPORTED: + stringBuilder.append(NbBundle.getMessage(RebaseAction.class, "MSG_RebaseAction.result.unsupported")); //NOI18N + DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(stringBuilder, NotifyDescriptor.PLAIN_MESSAGE)); //NOI18N + break; + } + logger.output(stringBuilder.toString()); + } + + protected GitRevisionInfo getInfo(GitRebaseResult result) { + if (result.getCurrentCommit() != null) { + try { + GitRevisionInfo info = client.log(result.getCurrentCommit(), GitUtils.NULL_PROGRESS_MONITOR); + return info; + } catch (GitException ex) { + GitClientExceptionHandler.notifyException(ex, true); + } + } + return null; + } +} diff -r 7a0c84058ab0 -r 78a01116b802 git/src/org/netbeans/modules/git/ui/rebase/SkipRebaseAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/git/src/org/netbeans/modules/git/ui/rebase/SkipRebaseAction.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,60 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ +package org.netbeans.modules.git.ui.rebase; + +import org.netbeans.libs.git.jgit.commands.RebaseCommand.Operation; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; + +/** + * + * @author ymajoros + */ +@ActionID(id = "org.netbeans.modules.git.ui.rebase.SkipRebaseAction", category = "Git") +@ActionRegistration(displayName = "#LBL_SkipRebaseAction_Name") +public class SkipRebaseAction extends AbstractEndRebaseAction { + + public SkipRebaseAction() { + super(Operation.SKIP); + } + +} \ No newline at end of file diff -r 7a0c84058ab0 -r 78a01116b802 libs.git/src/org/netbeans/libs/git/GitClassFactoryImpl.java --- a/libs.git/src/org/netbeans/libs/git/GitClassFactoryImpl.java Sat Jan 12 22:41:09 2013 +0100 +++ b/libs.git/src/org/netbeans/libs/git/GitClassFactoryImpl.java Thu Jan 24 23:30:08 2013 +0100 @@ -45,6 +45,7 @@ import java.util.List; import java.util.Map; import org.eclipse.jgit.api.MergeResult; +import org.eclipse.jgit.api.RebaseResult; import org.eclipse.jgit.blame.BlameResult; import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.lib.ObjectId; @@ -96,6 +97,11 @@ } @Override + public GitRebaseResult createRebaseResult (RebaseResult rebaseResult, File workTree) { + return new GitRebaseResult(rebaseResult, workTree); + } + + @Override public GitPullResult createPullResult (Map fetchUpdates, GitMergeResult mergeResult) { return new GitPullResult(fetchUpdates, mergeResult); } diff -r 7a0c84058ab0 -r 78a01116b802 libs.git/src/org/netbeans/libs/git/GitClient.java --- a/libs.git/src/org/netbeans/libs/git/GitClient.java Sat Jan 12 22:41:09 2013 +0100 +++ b/libs.git/src/org/netbeans/libs/git/GitClient.java Thu Jan 24 23:30:08 2013 +0100 @@ -39,7 +39,6 @@ * * Portions Copyrighted 2010 Sun Microsystems, Inc. */ - package org.netbeans.libs.git; import java.io.File; @@ -85,6 +84,8 @@ import org.netbeans.libs.git.jgit.commands.MergeCommand; import org.netbeans.libs.git.jgit.commands.PullCommand; import org.netbeans.libs.git.jgit.commands.PushCommand; +import org.netbeans.libs.git.jgit.commands.RebaseCommand; +import org.netbeans.libs.git.jgit.commands.RebaseCommand.Operation; import org.netbeans.libs.git.jgit.commands.RemoveCommand; import org.netbeans.libs.git.jgit.commands.RemoveRemoteCommand; import org.netbeans.libs.git.jgit.commands.RenameCommand; @@ -100,54 +101,61 @@ import org.netbeans.libs.git.progress.StatusListener; /** - * This class provides access to all supported git commands, methods that - * allow you to get information about a git repository or affect the behavior - * of invoked commands. - *
- * An instance of this class is always bound to a local git repository. - * The repository (identified by a git repository root file) may not exist on disk however - * because obviously when cloning or initializing a repository it may not yet physically exist. - * - *
Working with this class
- * A client of the API should follow these steps in order to run a certain git commands: - *
    - *
  1. Acquire an instance of a git client
    - *

    Instances of a git client are provided by {@link GitRepository}. To get one call - * {@link GitRepository#createClient() }.

    - *
  2. - *
  3. Configure the client
    - *

    Some git client commands may (or may not) require additional setup of the client to successfully finish their work. - * One quite usual use case is setting an instance of {@link GitClientCallback} to the client so commands like push, - * fetch or pull may connect to and access a remote repository. To set an instance of GitClientCallback - * use {@link #setCallback(org.netbeans.libs.git.GitClientCallback) } method.

    - *
  4. - *
  5. Attaching listeners
    - *

    Certain git commands may take a long time to finish and they are capable of notifying the world about the progress in their work.
    - * If you want to be notified about such changes while the command is in process, attach a listener to the client - * via {@link #addNotificationListener(org.netbeans.libs.git.progress.NotificationListener) }.
    - * An example can be the log command. Digging through the history may take a lot of time so if you do not want to wait for the complete result only - * and want to present the commit information incrementally as it is accepted one by one into the result, you can do so by adding an instance of - * {@link RevisionInfoListener} to the client.

    - *
  6. - *
  7. Running git commands
    - *

    When you have the client correctly set up, you may call any git command we support. The commands are mapped to appropriate methods in GitClient. - *
    Every method representing a git command accepts as a parameter an instance of {@link ProgressMonitor}. With that class you may affect the flow of commands - it - * has the ability to cancel running git commands - and listen for error or information messages the commands produce.

    - *
  8. + * This class provides access to all supported git commands, methods that allow + * you to get information about a git repository or affect the behavior of + * invoked commands.
    An instance of this class is always + * bound to a local git repository. The repository (identified by a git + * repository root file) may not exist on disk however because obviously when + * cloning or initializing a repository it may not yet physically exist. + * + *
    Working with this class
    A client of the API should follow these + * steps in order to run a certain git commands:
    1. Acquire an + * instance of a git client

      Instances of a git client are provided by + * {@link GitRepository}. To get one call + * {@link GitRepository#createClient() }.

    2. Configure the + * client

      Some git client commands may (or may not) require additional + * setup of the client to successfully finish their work. One quite usual use + * case is setting an instance of {@link GitClientCallback} to the client so + * commands like + * push, + * fetch or + * pull may connect to and access a remote repository. To set an + * instance of + * GitClientCallback use {@link #setCallback(org.netbeans.libs.git.GitClientCallback) + * } method.

    3. Attaching listeners

      Certain git commands + * may take a long time to finish and they are capable of notifying the world + * about the progress in their work.
      If you want to be notified about such + * changes while the command is in process, attach a listener to the client via {@link #addNotificationListener(org.netbeans.libs.git.progress.NotificationListener) + * }.
      An example can be the log command. Digging through the history may + * take a lot of time so if you do not want to wait for the complete result only + * and want to present the commit information incrementally as it is accepted + * one by one into the result, you can do so by adding an instance of + * {@link RevisionInfoListener} to the client.

    4. Running git + * commands

      When you have the client correctly set up, you may call any + * git command we support. The commands are mapped to appropriate methods in + * GitClient.
      Every method representing a git command accepts + * as a parameter an instance of {@link ProgressMonitor}. With that class you + * may affect the flow of commands - it has the ability to cancel running git + * commands - and listen for error or information messages the commands + * produce.

    5. + * * @author Ondra Vrabec */ public final class GitClient { + private final DelegateListener delegateListener; private GitClassFactory gitFactory; /** - * Used as a parameter of {@link #reset(java.lang.String, org.netbeans.libs.git.GitClient.ResetType, org.netbeans.libs.git.progress.ProgressMonitor) } + * Used as a parameter of {@link #reset(java.lang.String, org.netbeans.libs.git.GitClient.ResetType, org.netbeans.libs.git.progress.ProgressMonitor) + * } * to set the behavior of the command. */ public enum ResetType { + /** - * The command will only set the current HEAD but will not affect the Index - * or the Working tree. + * The command will only set the current HEAD but will not affect the + * Index or the Working tree. */ SOFT { @Override @@ -156,8 +164,9 @@ } }, /** - * The reset command will move the current HEAD and update the Index with - * the state in the new HEAD but will not affect files in the Working tree. + * The reset command will move the current HEAD and update the Index + * with the state in the new HEAD but will not affect files in the + * Working tree. */ MIXED { @Override @@ -166,8 +175,8 @@ } }, /** - * The reset command will move the current HEAD and update both the Index - * and the Working tree with the state in the new HEAD. + * The reset command will move the current HEAD and update both the + * Index and the Working tree with the state in the new HEAD. */ HARD { @Override @@ -184,6 +193,7 @@ * It tells the command what trees it is supposed to compare. */ public enum DiffMode { + /** * Compares the current HEAD vs. the Index */ @@ -197,12 +207,11 @@ */ INDEX_VS_WORKINGTREE } - private final JGitRepository gitRepository; private final Set listeners; private JGitCredentialsProvider credentialsProvider; - GitClient (JGitRepository gitRepository) throws GitException { + GitClient(JGitRepository gitRepository) throws GitException { this.gitRepository = gitRepository; listeners = new HashSet(); delegateListener = new DelegateListener(); @@ -211,38 +220,43 @@ /** * Adds all files under the given roots to the index + * * @param roots files or folders to add recursively to the index * @param monitor progress monitor * @throws GitException an unexpected error occurs */ - public void add (File[] roots, ProgressMonitor monitor) throws GitException { + public void add(File[] roots, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); AddCommand cmd = new AddCommand(repository, getClassFactory(), roots, monitor, delegateListener); cmd.execute(); } /** - * Adds a listener of any kind to the client. Git commands that support a listener will notify - * the appropriate ones while working. + * Adds a listener of any kind to the client. Git commands that support a + * listener will notify the appropriate ones while working. + * * @param listener a listener to add */ - public void addNotificationListener (NotificationListener listener) { + public void addNotificationListener(NotificationListener listener) { synchronized (listeners) { listeners.add(listener); } } /** - * Annotates lines of a given file in a given revision and returns the result - * with annotate information. + * Annotates lines of a given file in a given revision and returns the + * result with annotate information. + * * @param file file to be annotated - * @param revision a revision the file should be annotated in or null for blaming a checked-out file against HEAD + * @param revision a revision the file should be annotated in + * or null for blaming a checked-out file against HEAD * @param monitor progress monitor * @return annotation information - * @throws org.netbeans.libs.git.GitException.MissingObjectException when the revision revision cannot be resolved. + * @throws org.netbeans.libs.git.GitException.MissingObjectException when + * the revision revision cannot be resolved. * @throws GitException an unexpected error occurs */ - public GitBlameResult blame (File file, String revision, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { + public GitBlameResult blame(File file, String revision, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { Repository repository = gitRepository.getRepository(); BlameCommand cmd = new BlameCommand(repository, getClassFactory(), file, revision, monitor); cmd.execute(); @@ -251,14 +265,17 @@ /** * Prints file's content in the given revision to output stream + * * @param file file to cat * @param revision git revision, never null * @param out output stream to print the content to. - * @return true if the file was found in the specified revision and printed to out, otherwise false - * @throws GitException.MissingObjectException if the given revision does not exist + * @return true if the file was found in the specified revision + * and printed to out, otherwise false + * @throws GitException.MissingObjectException if the given revision does + * not exist * @throws GitException an unexpected error occurs */ - public boolean catFile (File file, String revision, java.io.OutputStream out, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { + public boolean catFile(File file, String revision, java.io.OutputStream out, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { Repository repository = gitRepository.getRepository(); CatCommand cmd = new CatCommand(repository, getClassFactory(), file, revision, out, monitor); cmd.execute(); @@ -266,18 +283,21 @@ } /** - * Prints content of an index entry accordant to the given file to the given output stream + * Prints content of an index entry accordant to the given file to the given + * output stream + * * @param file file whose relevant index entry to cat - * @param stage version of the file in the index. In case of a merge conflict there are usually more - * versions of the file. 0 for normal non-conflict version, - * 1 for the base version, - * 2 for the first merged version ("ours") and - * 3 for the second merged version ("theirs"). + * @param stage version of the file in the index. In case of a merge + * conflict there are usually more versions of the file. 0 for + * normal non-conflict version, 1 for the base version, + * 2 for the first merged version ("ours") and 3 + * for the second merged version ("theirs"). * @param out output stream - * @return true if the file was found in the index and printed to out, otherwise false + * @return true if the file was found in the index and printed + * to out, otherwise false * @throws GitException an unexpected error occurs */ - public boolean catIndexEntry (File file, int stage, java.io.OutputStream out, ProgressMonitor monitor) throws GitException { + public boolean catIndexEntry(File file, int stage, java.io.OutputStream out, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); CatCommand cmd = new CatCommand(repository, getClassFactory(), file, stage, out, monitor); cmd.execute(); @@ -285,10 +305,15 @@ } /** - * Checks out the index into the working copy root. Does not move current HEAD. - * @param revision if not null, index is updated with the revision content before checking out to WC + * Checks out the index into the working copy root. Does not move current + * HEAD. + * + * @param revision if not null, index is updated with the + * revision content before checking out to WC * @param roots files/folders to checkout - * @param recursively if set to true, all files under given roots will be checked out, otherwise only roots and direct file children will be affected. + * @param recursively if set to true, all files under given + * roots will be checked out, otherwise only roots and direct file children + * will be affected. * @throws GitException an unexpected error occurs */ public void checkout(File[] roots, String revision, boolean recursively, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { @@ -304,13 +329,17 @@ } /** - * Checks out a given revision, modifies the Index as well as the Working tree. - * @param revision cannot be null. If the value equals to anything other than an existing branch name, the revision will be checked out - * and the working tree will be in the detached HEAD state. - * @param failOnConflict if set to false, the command tries to merge local changes into the new branch + * Checks out a given revision, modifies the Index as well as the Working + * tree. + * + * @param revision cannot be null. If the value equals to + * anything other than an existing branch name, the revision will be checked + * out and the working tree will be in the detached HEAD state. + * @param failOnConflict if set to false, the command tries to + * merge local changes into the new branch * @throws GitException an unexpected error occurs */ - public void checkoutRevision (String revision, boolean failOnConflict, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { + public void checkoutRevision(String revision, boolean failOnConflict, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { if (!failOnConflict) { throw new IllegalArgumentException("Currently unsupported. failOnConflict must be set to true. JGit lib is buggy."); //NOI18N } @@ -320,37 +349,43 @@ } /** - * Cleans the working tree by recursively removing files that are not under + * Cleans the working tree by recursively removing files that are not under * version control starting from the given roots. - * @param roots files or folders to recursively remove from disk, versioned files under these files will not be deleted. + * + * @param roots files or folders to recursively remove from disk, versioned + * files under these files will not be deleted. * @param monitor progress monitor * @throws GitException an unexpected error occurs */ public void clean(File[] roots, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); CleanCommand cmd = new CleanCommand(repository, getClassFactory(), roots, monitor, delegateListener); - cmd.execute(); + cmd.execute(); } - + /** * Commits all changes made in the index to all files under the given roots + * * @param roots files or folders to recursively commit. * @param commitMessage commit message * @param author person who is the author of the changes to be committed - * @param commiter person who is committing the changes, may not be the same person as author. + * @param commiter person who is committing the changes, may not be the same + * person as author. * @param monitor progress monitor * @throws GitException an unexpected error occurs */ public GitRevisionInfo commit(File[] roots, String commitMessage, GitUser author, GitUser commiter, ProgressMonitor monitor) throws GitException { return commit(roots, commitMessage, author, commiter, false, monitor); } - + /** * Commits all changes made in the index to all files under the given roots + * * @param roots files or folders to recursively commit. * @param commitMessage commit message * @param author person who is the author of the changes to be committed - * @param commiter person who is committing the changes, may not be the same person as author. + * @param commiter person who is committing the changes, may not be the same + * person as author. * @param monitor progress monitor * @throws GitException an unexpected error occurs */ @@ -362,14 +397,16 @@ } /** - * The index entries representing files under the source are copied and the newly created entries represent the corresponding files under the target. + * The index entries representing files under the source are copied and the + * newly created entries represent the corresponding files under the target. * Modifies only the index. + * * @param source source tree to copy * @param target target file or folder the source should be copied onto. * @param monitor progress monitor * @throws GitException an unexpected error occurs */ - public void copyAfter (File source, File target, ProgressMonitor monitor) throws GitException { + public void copyAfter(File source, File target, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); CopyCommand cmd = new CopyCommand(repository, getClassFactory(), source, target, monitor, delegateListener); cmd.execute(); @@ -377,32 +414,37 @@ /** * Creates a new branch with a given name, starting at the given revision + * * @param branchName name that should be assigned to the new branch * @param revision revision that should be referenced by the new branch * @param monitor progress monitor * @return created branch * @throws GitException an unexpected error occurs */ - public GitBranch createBranch (String branchName, String revision, ProgressMonitor monitor) throws GitException { + public GitBranch createBranch(String branchName, String revision, ProgressMonitor monitor) throws GitException { CreateBranchCommand cmd = new CreateBranchCommand(gitRepository.getRepository(), getClassFactory(), branchName, revision, monitor); cmd.execute(); return cmd.getBranch(); } /** - * Creates a tag for any object represented by a given taggedObjectId. - * If message is set to null or an empty value and signed set to false than this method creates a lightweight tag. + * Creates a tag for any object represented by a given taggedObjectId. If + * message is set to + * null or an empty value and signed set to + * false than this method creates a lightweight tag. + * * @param tagName name of the new tag * @param taggedObject object to tag * @param message tag message * @param signed if the tag should be signed. Currently unsupported. - * @param forceUpdate if a tag with the same name already exists, the method fails and throws an exception unless this is set to true. In that case the - * old tag is replaced with the new one. + * @param forceUpdate if a tag with the same name already exists, the method + * fails and throws an exception unless this is set to true. In + * that case the old tag is replaced with the new one. * @param monitor progress monitor * @return the created tag * @throws GitException an unexpected error occurs */ - public GitTag createTag (String tagName, String taggedObject, String message, boolean signed, boolean forceUpdate, ProgressMonitor monitor) throws GitException { + public GitTag createTag(String tagName, String taggedObject, String message, boolean signed, boolean forceUpdate, ProgressMonitor monitor) throws GitException { CreateTagCommand cmd = new CreateTagCommand(gitRepository.getRepository(), getClassFactory(), tagName, taggedObject, message, signed, forceUpdate, monitor); cmd.execute(); return cmd.getTag(); @@ -410,91 +452,112 @@ /** * Deletes a given branch from the repository + * * @param branchName name of a branch to delete. - * @param forceDeleteUnmerged if set to true then trying to delete an unmerged branch will not fail but will forcibly delete the branch + * @param forceDeleteUnmerged if set to true then trying to + * delete an unmerged branch will not fail but will forcibly delete the + * branch * @param monitor progress monitor - * @throws GitException.NotMergedException branch has not been fully merged yet and forceDeleteUnmerged is set to false + * @throws GitException.NotMergedException branch has not been fully merged + * yet and forceDeleteUnmerged is set to false * @throws GitException an unexpected error occurs */ - public void deleteBranch (String branchName, boolean forceDeleteUnmerged, ProgressMonitor monitor) throws GitException.NotMergedException, GitException { + public void deleteBranch(String branchName, boolean forceDeleteUnmerged, ProgressMonitor monitor) throws GitException.NotMergedException, GitException { DeleteBranchCommand cmd = new DeleteBranchCommand(gitRepository.getRepository(), getClassFactory(), branchName, forceDeleteUnmerged, monitor); cmd.execute(); } /** * Deletes a given tag from the repository + * * @param tagName name of a tag to delete * @param monitor progress monitor * @throws GitException an unexpected error occurs */ - public void deleteTag (String tagName, ProgressMonitor monitor) throws GitException { + public void deleteTag(String tagName, ProgressMonitor monitor) throws GitException { DeleteTagCommand cmd = new DeleteTagCommand(gitRepository.getRepository(), getClassFactory(), tagName, monitor); cmd.execute(); } /** * Exports a given commit in the format accepted by git am + * * @param commit id of a commit whose diff to export * @param out output stream the diff will be printed to * @param monitor progress monitor * @throws GitException an unexpected error occurs */ - public void exportCommit (String commit, OutputStream out, ProgressMonitor monitor) throws GitException { + public void exportCommit(String commit, OutputStream out, ProgressMonitor monitor) throws GitException { ExportCommitCommand cmd = new ExportCommitCommand(gitRepository.getRepository(), getClassFactory(), commit, out, monitor, delegateListener); cmd.execute(); } - + /** - * Exports uncommitted changes in files under given roots to the given output stream - * @param roots the diff will be exported only for modified files under these roots, can be empty to export all modifications in the whole working tree - * @param mode defines the compared trees + * Exports uncommitted changes in files under given roots to the given + * output stream + * + * @param roots the diff will be exported only for modified files under + * these roots, can be empty to export all modifications in the whole + * working tree + * @param mode defines the compared trees * @param out output stream the diff will be printed to * @param monitor progress monitor * @throws GitException an unexpected error occurs */ - public void exportDiff (File[] roots, DiffMode mode, OutputStream out, ProgressMonitor monitor) throws GitException { + public void exportDiff(File[] roots, DiffMode mode, OutputStream out, ProgressMonitor monitor) throws GitException { ExportDiffCommand cmd = new ExportDiffCommand(gitRepository.getRepository(), getClassFactory(), roots, mode, out, monitor, delegateListener); cmd.execute(); } - + /** - * Fetches remote changes for references specified in the config file under a given remote. - * @param remote should be a name of a remote set up in the repository config file + * Fetches remote changes for references specified in the config file under + * a given remote. + * + * @param remote should be a name of a remote set up in the repository + * config file * @param monitor progress monitor * @return result of the command with listed local reference updates - * @throws GitException.AuthorizationException when the authentication or authorization fails + * @throws GitException.AuthorizationException when the authentication or + * authorization fails * @throws GitException an unexpected error occurs */ - public Map fetch (String remote, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { + public Map fetch(String remote, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { FetchCommand cmd = new FetchCommand(gitRepository.getRepository(), getClassFactory(), remote, monitor); cmd.setCredentialsProvider(this.credentialsProvider); cmd.execute(); return cmd.getUpdates(); } - + /** - * Fetches remote changes from a remote repository for given reference specifications. - * @param remote preferably a name of a remote, but can also be directly a URL of a remote repository - * @param fetchRefSpecifications list of reference specifications describing the objects to fetch from the remote repository + * Fetches remote changes from a remote repository for given reference + * specifications. + * + * @param remote preferably a name of a remote, but can also be directly a + * URL of a remote repository + * @param fetchRefSpecifications list of reference specifications describing + * the objects to fetch from the remote repository * @param monitor progress monitor * @return result of the command with listed local reference updates - * @throws GitException.AuthorizationException when the authentication or authorization fails + * @throws GitException.AuthorizationException when the authentication or + * authorization fails * @throws GitException an unexpected error occurs */ - public Map fetch (String remote, List fetchRefSpecifications, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { + public Map fetch(String remote, List fetchRefSpecifications, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { FetchCommand cmd = new FetchCommand(gitRepository.getRepository(), getClassFactory(), remote, fetchRefSpecifications, monitor); cmd.setCredentialsProvider(this.credentialsProvider); cmd.execute(); return cmd.getUpdates(); } - + /** * Returns all known branches from the repository - * @param all if false then only local (and no remote) branches will be returned + * + * @param all if false then only local (and no remote) branches + * will be returned * @return all known branches in the repository * @throws GitException an unexpected error occurs */ - public Map getBranches (boolean all, ProgressMonitor monitor) throws GitException { + public Map getBranches(boolean all, ProgressMonitor monitor) throws GitException { ListBranchCommand cmd = new ListBranchCommand(gitRepository.getRepository(), getClassFactory(), all, monitor); cmd.execute(); return cmd.getBranches(); @@ -502,25 +565,30 @@ /** * Returns all tags in the repository + * * @param monitor progress monitor - * @param allTags if set to false, only commit tags, otherwise tags for all objects are returned + * @param allTags if set to false, only commit tags, otherwise + * tags for all objects are returned * @return all known tags from the repository * @throws GitException an unexpected error occurs */ - public Map getTags (ProgressMonitor monitor, boolean allTags) throws GitException { + public Map getTags(ProgressMonitor monitor, boolean allTags) throws GitException { ListTagCommand cmd = new ListTagCommand(gitRepository.getRepository(), getClassFactory(), allTags, monitor); cmd.execute(); return cmd.getTags(); } /** - * Returns a common ancestor for given revisions or null if none found. + * Returns a common ancestor for given revisions or + * null if none found. + * * @param revisions revisions whose common ancestor to search * @param monitor progress monitor - * @return common ancestor for given revisions or null if none found. + * @return common ancestor for given revisions or null if none + * found. * @throws GitException an unexpected error occurs */ - public GitRevisionInfo getCommonAncestor (String[] revisions, ProgressMonitor monitor) throws GitException { + public GitRevisionInfo getCommonAncestor(String[] revisions, ProgressMonitor monitor) throws GitException { GetCommonAncestorCommand cmd = new GetCommonAncestorCommand(gitRepository.getRepository(), getClassFactory(), revisions, monitor); cmd.execute(); return cmd.getRevision(); @@ -528,26 +596,33 @@ /** * Returns an ancestor revision that affected a given file - * @param file limit the result only on revision that actually modified somehow the file - * @param revision revision to start search from, only its ancestors will be investigated + * + * @param file limit the result only on revision that actually modified + * somehow the file + * @param revision revision to start search from, only its ancestors will be + * investigated * @param monitor progress monitor - * @return an ancestor of a given revision that affected the given file or null if none found. + * @return an ancestor of a given revision that affected the given file + * or null if none found. * @throws GitException an unexpected error occurs */ - public GitRevisionInfo getPreviousRevision (File file, String revision, ProgressMonitor monitor) throws GitException { + public GitRevisionInfo getPreviousRevision(File file, String revision, ProgressMonitor monitor) throws GitException { GetPreviousCommitCommand cmd = new GetPreviousCommitCommand(gitRepository.getRepository(), getClassFactory(), file, revision, monitor); cmd.execute(); return cmd.getRevision(); } /** - * Similar to {@link #getStatus(java.io.File[], org.netbeans.libs.git.progress.ProgressMonitor)}, but returns only conflicts. + * Similar to + * {@link #getStatus(java.io.File[], org.netbeans.libs.git.progress.ProgressMonitor)}, + * but returns only conflicts. + * * @param roots files to search the conflicts under * @param monitor progress monitor * @return conflicted files and their accordant statuses * @throws GitException an unexpected error occurs */ - public Map getConflicts (File[] roots, ProgressMonitor monitor) throws GitException { + public Map getConflicts(File[] roots, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); ConflictCommand cmd = new ConflictCommand(repository, getClassFactory(), roots, monitor, delegateListener); cmd.execute(); @@ -556,11 +631,12 @@ /** * Returns an array of statuses for files under given roots + * * @param roots root folders or files to search under * @return status array * @throws GitException an unexpected error occurs */ - public Map getStatus (File[] roots, ProgressMonitor monitor) throws GitException { + public Map getStatus(File[] roots, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); StatusCommand cmd = new StatusCommand(repository, getClassFactory(), roots, monitor, delegateListener); cmd.execute(); @@ -568,38 +644,45 @@ } /** - * Returns remote configuration set up for this repository identified by a given remoteName - * @param remoteName name under which the remote is stored in repository's config file + * Returns remote configuration set up for this repository identified by a + * given remoteName + * + * @param remoteName name under which the remote is stored in repository's + * config file * @param monitor progress monitor - * @return remote config or null if no remote with such name was found + * @return remote config or null if no remote with such name + * was found * @throws GitException an unexpected error occurs */ - public GitRemoteConfig getRemote (String remoteName, ProgressMonitor monitor) throws GitException { + public GitRemoteConfig getRemote(String remoteName, ProgressMonitor monitor) throws GitException { return getRemotes(monitor).get(remoteName); } /** * Returns all remote configurations set up for this repository + * * @param monitor progress monitor * @return all known remote configurations * @throws GitException an unexpected error occurs */ - public Map getRemotes (ProgressMonitor monitor) throws GitException { + public Map getRemotes(ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); GetRemotesCommand cmd = new GetRemotesCommand(repository, getClassFactory(), monitor); cmd.execute(); return cmd.getRemotes(); } - + /** - * Returns the current state of the repository this client is associated with. - * The state indicates what commands may be run on the repository and if the repository - * requires any additional commands to get into the normal state. + * Returns the current state of the repository this client is associated + * with. The state indicates what commands may be run on the repository and + * if the repository requires any additional commands to get into the normal + * state. + * * @param monitor progress monitor * @return current repository state * @throws GitException an unexpected error occurs */ - public GitRepositoryState getRepositoryState (ProgressMonitor monitor) throws GitException { + public GitRepositoryState getRepositoryState(ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); RepositoryState state = repository.getRepositoryState(); return GitRepositoryState.getStateFor(state); @@ -607,20 +690,22 @@ /** * Returns the user from this clients repository + * * @throws GitException an unexpected error occurs */ - public GitUser getUser() throws GitException { + public GitUser getUser() throws GitException { return getClassFactory().createUser(new PersonIdent(gitRepository.getRepository())); } /** * Ignores given files and add their path into gitignore file. + * * @param files files to ignore * @param monitor progress monitor * @return array of .gitignore modified during the ignore process * @throws GitException an unexpected error occurs */ - public File[] ignore (File[] files, ProgressMonitor monitor) throws GitException { + public File[] ignore(File[] files, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); IgnoreCommand cmd = new IgnoreCommand(repository, getClassFactory(), files, monitor, delegateListener); cmd.execute(); @@ -628,13 +713,18 @@ } /** - * Initializes an empty git repository in a folder specified in the constructor. The repository must not yet exist - meaning - * there cannot not be a .git folder in the given folder - however the folder itself may exist and contain any other source files - * (except for git repository metadata). + * Initializes an empty git repository in a folder specified in the + * constructor. The repository must not yet exist - meaning there cannot not + * be a .git folder in the given folder - however the folder itself + * may exist and contain any other source files (except for git repository + * metadata). + * * @param monitor progress monitor - * @throws GitException if the repository could not be created either because it already exists inside workDir or cannot be created for other reasons. + * @throws GitException if the repository could not be created either + * because it already exists inside workDir or cannot be + * created for other reasons. */ - public void init (ProgressMonitor monitor) throws GitException { + public void init(ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); InitRepositoryCommand cmd = new InitRepositoryCommand(repository, getClassFactory(), monitor); cmd.execute(); @@ -642,42 +732,47 @@ /** * Returns files that are marked as modified between the HEAD and Index. + * * @param roots files or folders to search for modified files. * @param monitor progress monitor * @throws GitException an unexpected error occurs */ - public File[] listModifiedIndexEntries (File[] roots, ProgressMonitor monitor) throws GitException { + public File[] listModifiedIndexEntries(File[] roots, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); ListModifiedIndexEntriesCommand cmd = new ListModifiedIndexEntriesCommand(repository, getClassFactory(), roots, monitor, delegateListener); cmd.execute(); return cmd.getFiles(); } - + /** * Returns available branches in a given remote repository + * * @param remoteRepositoryUrl url of the remote repository * @param monitor progress monitor * @return collection of available branches in the remote repository - * @throws GitException.AuthorizationException when the authentication or authorization fails + * @throws GitException.AuthorizationException when the authentication or + * authorization fails * @throws GitException an unexpected error occurs */ - public Map listRemoteBranches (String remoteRepositoryUrl, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { + public Map listRemoteBranches(String remoteRepositoryUrl, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { Repository repository = gitRepository.getRepository(); ListRemoteBranchesCommand cmd = new ListRemoteBranchesCommand(repository, getClassFactory(), remoteRepositoryUrl, monitor); cmd.setCredentialsProvider(this.credentialsProvider); cmd.execute(); return cmd.getBranches(); } - + /** * Returns pairs tag name/id from a given remote repository + * * @param remoteRepositoryUrl url of the remote repository * @param monitor progress monitor * @return remote repository tags - * @throws GitException.AuthorizationException when the authentication or authorization fails + * @throws GitException.AuthorizationException when the authentication or + * authorization fails * @throws GitException an unexpected error occurs */ - public Map listRemoteTags (String remoteRepositoryUrl, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { + public Map listRemoteTags(String remoteRepositoryUrl, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { Repository repository = gitRepository.getRepository(); ListRemoteTagsCommand cmd = new ListRemoteTagsCommand(repository, getClassFactory(), remoteRepositoryUrl, monitor); cmd.setCredentialsProvider(this.credentialsProvider); @@ -686,14 +781,16 @@ } /** - * Digs through the repository's history and returns the revision information belonging to the given revision string. + * Digs through the repository's history and returns the revision + * information belonging to the given revision string. + * * @param revision revision to search in the history * @param monitor progress monitor * @return revision information * @throws GitException.MissingObjectException no such revision exists * @throws GitException an unexpected error occurs */ - public GitRevisionInfo log (String revision, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { + public GitRevisionInfo log(String revision, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { Repository repository = gitRepository.getRepository(); LogCommand cmd = new LogCommand(repository, getClassFactory(), revision, monitor, delegateListener); cmd.execute(); @@ -702,116 +799,157 @@ } /** - * Digs through the repository's history and returns revisions according to the given search criteria. + * Digs through the repository's history and returns revisions according to + * the given search criteria. + * * @param searchCriteria criteria filtering the returned revisions * @param monitor progress monitor * @return revisions that follow the given search criteria - * @throws GitException.MissingObjectException revision specified in search criteria (or head if no such revision is specified) does not exist + * @throws GitException.MissingObjectException revision specified in search + * criteria (or head if no such revision is specified) does not exist * @throws GitException an unexpected error occurs */ - public GitRevisionInfo[] log (SearchCriteria searchCriteria, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { + public GitRevisionInfo[] log(SearchCriteria searchCriteria, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { Repository repository = gitRepository.getRepository(); LogCommand cmd = new LogCommand(repository, getClassFactory(), searchCriteria, monitor, delegateListener); cmd.execute(); return cmd.getRevisions(); } - + /** * Merges a given revision with the current head + * * @param revision id of a revision to merge. * @param monitor progress monitor * @return result of the merge - * @throws GitException.CheckoutConflictException there are local modifications in Working Tree, merge fails in such a case + * @throws GitException.CheckoutConflictException there are local + * modifications in Working Tree, merge fails in such a case * @throws GitException an unexpected error occurs */ - public GitMergeResult merge (String revision, ProgressMonitor monitor) throws GitException.CheckoutConflictException, GitException { + public GitMergeResult merge(String revision, ProgressMonitor monitor) throws GitException.CheckoutConflictException, GitException { Repository repository = gitRepository.getRepository(); MergeCommand cmd = new MergeCommand(repository, getClassFactory(), revision, monitor); cmd.execute(); return cmd.getResult(); } - + /** - * Pulls changes from a remote repository and merges a given remote branch to an active one. - * @param remote preferably a name of a remote, but can also be directly a URL of a remote repository - * @param fetchRefSpecifications list of reference specifications describing what objects to fetch from the remote repository - * @param branchToMerge a remote branch that will be merged into an active branch + * Rebase a given revision with the current head + * + * @param revision id of a revision to rebase onto. * @param monitor progress monitor - * @return result of the command containing the list of updated local references - * @throws GitException.AuthorizationException when the authentication or authorization fails - * @throws GitException.CheckoutConflictException there are local changes in the working tree that would result in a merge conflict - * @throws GitException.MissingObjectException given branch to merge does not exist + * @return result of the rebase operation + * @throws GitException.CheckoutConflictException there are local + * modifications in Working Tree, merge fails in such a case * @throws GitException an unexpected error occurs */ - public GitPullResult pull (String remote, List fetchRefSpecifications, String branchToMerge, ProgressMonitor monitor) throws GitException.AuthorizationException, + public GitRebaseResult rebase(String revision, Operation operation, ProgressMonitor monitor) throws GitException.CheckoutConflictException, GitException { + Repository repository = gitRepository.getRepository(); + RebaseCommand rebaseCommand = new RebaseCommand(repository, getClassFactory(), revision, operation, monitor); + rebaseCommand.execute(); + return rebaseCommand.getResult(); + } + + /** + * Pulls changes from a remote repository and merges a given remote branch + * to an active one. + * + * @param remote preferably a name of a remote, but can also be directly a + * URL of a remote repository + * @param fetchRefSpecifications list of reference specifications describing + * what objects to fetch from the remote repository + * @param branchToMerge a remote branch that will be merged into an active + * branch + * @param monitor progress monitor + * @return result of the command containing the list of updated local + * references + * @throws GitException.AuthorizationException when the authentication or + * authorization fails + * @throws GitException.CheckoutConflictException there are local changes in + * the working tree that would result in a merge conflict + * @throws GitException.MissingObjectException given branch to merge does + * not exist + * @throws GitException an unexpected error occurs + */ + public GitPullResult pull(String remote, List fetchRefSpecifications, String branchToMerge, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException.CheckoutConflictException, GitException.MissingObjectException, GitException { PullCommand cmd = new PullCommand(gitRepository.getRepository(), getClassFactory(), remote, fetchRefSpecifications, branchToMerge, monitor); cmd.setCredentialsProvider(this.credentialsProvider); cmd.execute(); return cmd.getResult(); } - + /** - * Pushes changes to a remote repository specified by remote for given reference specifications. - * @param remote preferably a name of a remote defined in the repository's config, - * but can also be directly a URL of a remote repository - * @param pushRefSpecifications list of reference specifications describing the list of references to push - * @param fetchRefSpecifications list of fetch reference specifications describing the list of local references to update - * to correctly track remote repository branches. + * Pushes changes to a remote repository specified by remote for given + * reference specifications. + * + * @param remote preferably a name of a remote defined in the repository's + * config, but can also be directly a URL of a remote repository + * @param pushRefSpecifications list of reference specifications describing + * the list of references to push + * @param fetchRefSpecifications list of fetch reference specifications + * describing the list of local references to update to correctly track + * remote repository branches. * @param monitor progress monitor - * @return result of the push process with information about updated local and remote references - * @throws GitException.AuthorizationException when the authentication or authorization fails + * @return result of the push process with information about updated local + * and remote references + * @throws GitException.AuthorizationException when the authentication or + * authorization fails * @throws GitException an unexpected error occurs */ - public GitPushResult push (String remote, List pushRefSpecifications, List fetchRefSpecifications, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { + public GitPushResult push(String remote, List pushRefSpecifications, List fetchRefSpecifications, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException { PushCommand cmd = new PushCommand(gitRepository.getRepository(), getClassFactory(), remote, pushRefSpecifications, fetchRefSpecifications, monitor); cmd.setCredentialsProvider(this.credentialsProvider); cmd.execute(); return cmd.getResult(); } - + /** - * Marks this client as released and notifies the repository it does not + * Marks this client as released and notifies the repository it does not * have to stay open for this client. When all repository's clients are * released the repository closes, flushes all cached metadata and closes * all opened metadata files and file descriptors. + * * @since 1.5 */ - public void release () { + public void release() { gitRepository.decreaseClientUsage(); } /** * Removes given files/folders from the index and/or from the working tree + * * @param roots files/folders to remove, can not be empty * @param cached if true the working tree will not be affected * @param monitor progress monitor * @throws GitException an unexpected error occurs */ - public void remove (File[] roots, boolean cached, ProgressMonitor monitor) throws GitException { + public void remove(File[] roots, boolean cached, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); RemoveCommand cmd = new RemoveCommand(repository, getClassFactory(), roots, cached, monitor, delegateListener); cmd.execute(); } /** - * Removes an already added notification listener. Such a listener will not get notifications from the - * git subsystem. + * Removes an already added notification listener. Such a listener will not + * get notifications from the git subsystem. + * * @param listener listener to remove. */ - public void removeNotificationListener (NotificationListener listener) { + public void removeNotificationListener(NotificationListener listener) { synchronized (listeners) { listeners.remove(listener); } } - + /** * Removes remote configuration from the repository's config file + * * @param remote name of the remote * @param monitor progress monitor * @throws GitException an unexpected error occurs */ - public void removeRemote (String remote, ProgressMonitor monitor) throws GitException { + public void removeRemote(String remote, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); RemoveRemoteCommand cmd = new RemoveRemoteCommand(repository, getClassFactory(), remote, monitor); cmd.execute(); @@ -819,42 +957,51 @@ /** * Renames source file or folder to target + * * @param source file or folder to be renamed * @param target target file or folder. Must not yet exist. * @param after set to true if you don't only want to correct the index * @param monitor progress monitor * @throws GitException an unexpected error occurs */ - public void rename (File source, File target, boolean after, ProgressMonitor monitor) throws GitException { + public void rename(File source, File target, boolean after, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); RenameCommand cmd = new RenameCommand(repository, getClassFactory(), source, target, after, monitor, delegateListener); cmd.execute(); } - + /** - * Updates entries for given files in the index with those from the given revision + * Updates entries for given files in the index with those from the given + * revision + * * @param revision revision to go back to * @param roots files or folders to update in the index - * @param recursively if set to true, all files under given roots will be affected, otherwise only roots and direct file children will be modified in the index. + * @param recursively if set to true, all files under given + * roots will be affected, otherwise only roots and direct file children + * will be modified in the index. * @param monitor progress monitor - * @throws GitException.MissingObjectException if the given revision does not exist + * @throws GitException.MissingObjectException if the given revision does + * not exist * @throws GitException an unexpected error occurs */ - public void reset (File[] roots, String revision, boolean recursively, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { + public void reset(File[] roots, String revision, boolean recursively, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { Repository repository = gitRepository.getRepository(); ResetCommand cmd = new ResetCommand(repository, getClassFactory(), revision, roots, recursively, monitor, delegateListener); cmd.execute(); } /** - * Sets HEAD to the given revision and updates index and working copy accordingly to the given reset type + * Sets HEAD to the given revision and updates index and working copy + * accordingly to the given reset type + * * @param revision revision HEAD will reference to * @param resetType type of reset, see git help reset * @param monitor progress monitor - * @throws GitException.MissingObjectException if the given revision does not exist + * @throws GitException.MissingObjectException if the given revision does + * not exist * @throws GitException an unexpected error occurs */ - public void reset (String revision, ResetType resetType, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { + public void reset(String revision, ResetType resetType, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException { Repository repository = gitRepository.getRepository(); ResetCommand cmd = new ResetCommand(repository, getClassFactory(), revision, resetType, monitor, delegateListener); cmd.execute(); @@ -862,16 +1009,22 @@ /** * Reverts already committed changes and creates an inverse commit. + * * @param revision the id of a commit to revert - * @param commitMessage used as the commit message for the revert commit. If set to null or an empty value, a default value will be used for the commit message - * @param commit if set to false, the revert modifications will not be committed but will stay in index + * @param commitMessage used as the commit message for the revert commit. If + * set to null or an empty value, a default value will be used for the + * commit message + * @param commit if set to false, the revert modifications will + * not be committed but will stay in index * @param monitor progress monitor * @return result of the revert command - * @throws GitException.MissingObjectException if the given revision does not exist - * @throws GitException.CheckoutConflictException there are local modifications in Working Tree, merge fails in such a case + * @throws GitException.MissingObjectException if the given revision does + * not exist + * @throws GitException.CheckoutConflictException there are local + * modifications in Working Tree, merge fails in such a case * @throws GitException an unexpected error occurs */ - public GitRevertResult revert (String revision, String commitMessage, boolean commit, ProgressMonitor monitor) + public GitRevertResult revert(String revision, String commitMessage, boolean commit, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException.CheckoutConflictException, GitException { Repository repository = gitRepository.getRepository(); RevertCommand cmd = new RevertCommand(repository, getClassFactory(), revision, commitMessage, commit, monitor); @@ -880,20 +1033,25 @@ } /** - * Sets credentials callback for this client. - * Some actions (like inter-repository commands) may need it for its work to communicate with an external repository. - * @param callback callback implementation providing credentials for an authentication process. + * Sets credentials callback for this client. Some actions (like + * inter-repository commands) may need it for its work to communicate with + * an external repository. + * + * @param callback callback implementation providing credentials for an + * authentication process. */ - public void setCallback (GitClientCallback callback) { + public void setCallback(GitClientCallback callback) { this.credentialsProvider = callback == null ? null : new JGitCredentialsProvider(callback); } - + /** * Sets the remote configuration in the configuration file. - * @param remoteConfig new remote config to store as a remote section in the repository's config file. + * + * @param remoteConfig new remote config to store as a remote + * section in the repository's config file. * @param monitor progress monitor */ - public void setRemote (GitRemoteConfig remoteConfig, ProgressMonitor monitor) throws GitException { + public void setRemote(GitRemoteConfig remoteConfig, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); SetRemoteCommand cmd = new SetRemoteCommand(repository, getClassFactory(), remoteConfig, monitor); cmd.execute(); @@ -901,46 +1059,47 @@ /** * Unignores given files - * @param files files to mark unignored again and remove their respective record from gitignore files. + * + * @param files files to mark unignored again and remove their respective + * record from gitignore files. * @param monitor progress monitor * @return array of .gitignore files modified during the unignore process * @throws GitException an unexpected error occurs */ - public File[] unignore (File[] files, ProgressMonitor monitor) throws GitException { + public File[] unignore(File[] files, ProgressMonitor monitor) throws GitException { Repository repository = gitRepository.getRepository(); UnignoreCommand cmd = new UnignoreCommand(repository, getClassFactory(), files, monitor, delegateListener); cmd.execute(); return cmd.getModifiedIgnoreFiles(); } - private GitClassFactory getClassFactory () { + private GitClassFactory getClassFactory() { if (gitFactory == null) { gitFactory = GitClassFactoryImpl.getInstance(); } return gitFactory; } - + private class DelegateListener implements StatusListener, FileListener, RevisionInfoListener { @Override - public void notifyStatus (GitStatus status) { + public void notifyStatus(GitStatus status) { GitClient.this.notifyStatus(status); } @Override - public void notifyFile (File file, String relativePathToRoot) { + public void notifyFile(File file, String relativePathToRoot) { GitClient.this.notifyFile(file, relativePathToRoot); } @Override - public void notifyRevisionInfo (GitRevisionInfo revisionInfo) { + public void notifyRevisionInfo(GitRevisionInfo revisionInfo) { GitClient.this.notifyRevisionInfo(revisionInfo); } - } - + // - private void notifyFile (File file, String relativePathToRoot) { + private void notifyFile(File file, String relativePathToRoot) { List lists; synchronized (listeners) { lists = new LinkedList(listeners); @@ -952,7 +1111,7 @@ } } - private void notifyStatus (GitStatus status) { + private void notifyStatus(GitStatus status) { List lists; synchronized (listeners) { lists = new LinkedList(listeners); @@ -964,7 +1123,7 @@ } } - private void notifyRevisionInfo (GitRevisionInfo info) { + private void notifyRevisionInfo(GitRevisionInfo info) { List lists; synchronized (listeners) { lists = new LinkedList(listeners); diff -r 7a0c84058ab0 -r 78a01116b802 libs.git/src/org/netbeans/libs/git/GitRebaseResult.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs.git/src/org/netbeans/libs/git/GitRebaseResult.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,163 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.libs.git; + +import java.io.File; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.eclipse.jgit.api.RebaseResult; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.merge.ResolveMerger; +import org.eclipse.jgit.revwalk.RevCommit; + +/** + * Returned by a git merge command, represents its result. + * + * @author Ondra Vrabec + */ +public final class GitRebaseResult { + + private final RebaseStatus rebaseStatus; + private final File workDir; + private final List failures; + private final String currentCommit; + + /** + * The status the rebase resulted in. + */ + public enum RebaseStatus { + + FAST_FORWARD { + @Override + public String toString() { + return "Fast-forward"; + } + }, + UP_TO_DATE { + @Override + public String toString() { + return "Already up-to-date"; + } + }, + FAILED { + @Override + public String toString() { + return "Failed"; + } + }, + OK { + @Override + public String toString() { + return "Rebased"; + } + }, + ABORTED { + @Override + public String toString() { + return "Aborted"; + } + }, + STOPPED { + @Override + public String toString() { + return "Stopped"; + } + }, + NOT_SUPPORTED { + @Override + public String toString() { + return "Not-yet-supported"; + } + } + } + + GitRebaseResult(RebaseResult result, File workDir) { + this.rebaseStatus = GitRebaseResult.RebaseStatus.valueOf(result.getStatus().name()); + this.workDir = workDir; + this.currentCommit = getCurrentCommit(result); + this.failures = getFailures(result); + } + + /** + * @return result of the merge. + */ + public RebaseStatus getRebaseStatus() { + return rebaseStatus; + } + + /** + * @return id of current commit + */ + public String getCurrentCommit() { + return currentCommit; + } + + /** + * When the merge fails because of local modifications then this method + * returns a collections of files causing the failure. + * + * @return files that cause the merge to fail. + */ + public Collection getFailures() { + return failures; + } + + private String getCurrentCommit(RebaseResult result) { + RevCommit currentRevCommit = result.getCurrentCommit(); + String commitId = ObjectId.toString(currentRevCommit); + return commitId; + } + + private List getFailures(RebaseResult result) { + List files = new LinkedList(); + Map obstructions = result.getFailingPaths(); + if (obstructions != null) { + for (Map.Entry failure : obstructions.entrySet()) { + files.add(new File(workDir, failure.getKey())); + } + } + return Collections.unmodifiableList(files); + } +} diff -r 7a0c84058ab0 -r 78a01116b802 libs.git/src/org/netbeans/libs/git/GitRepositoryState.java --- a/libs.git/src/org/netbeans/libs/git/GitRepositoryState.java Sat Jan 12 22:41:09 2013 +0100 +++ b/libs.git/src/org/netbeans/libs/git/GitRepositoryState.java Thu Jan 24 23:30:08 2013 +0100 @@ -61,6 +61,8 @@ @Override public boolean canCommit () { return false; } @Override + public boolean canRebase () { return false; } + @Override public String toString () { return Utils.getBundle(GitRepositoryState.class).getString("LBL_RepositoryInfo_Bare"); } //NOI18N }, @@ -75,6 +77,8 @@ @Override public boolean canCommit () { return true; } @Override + public boolean canRebase () { return true; } + @Override public String toString () { return Utils.getBundle(GitRepositoryState.class).getString("LBL_RepositoryInfo_Safe"); } //NOI18N }, @@ -88,6 +92,8 @@ @Override public boolean canCommit () { return false; } @Override + public boolean canRebase () { return false; } + @Override public String toString () { return Utils.getBundle(GitRepositoryState.class).getString("LBL_RepositoryInfo_Merging"); } //NOI18N }, @@ -103,6 +109,8 @@ @Override public boolean canCommit () { return true; } @Override + public boolean canRebase () { return false; } + @Override public String toString () { return Utils.getBundle(GitRepositoryState.class).getString("LBL_RepositoryInfo_Merged"); } //NOI18N }, @@ -117,6 +125,8 @@ @Override public boolean canCommit () { return true; } @Override + public boolean canRebase () { return false; } + @Override public String toString () { return Utils.getBundle(GitRepositoryState.class).getString("LBL_RepositoryInfo_Rebasing"); } //NOI18N }, @@ -131,6 +141,8 @@ @Override public boolean canCommit () { return true; } @Override + public boolean canRebase () { return false; } + @Override public String toString () { return Utils.getBundle(GitRepositoryState.class).getString("LBL_RepositoryInfo_Apply"); } //NOI18N }, @@ -151,6 +163,9 @@ public boolean canCommit () { return true; } @Override + public boolean canRebase () { return false; } + + @Override public String toString () { return Utils.getBundle(GitRepositoryState.class).getString("LBL_RepositoryInfo_Bisecting"); } //NOI18N }; @@ -164,6 +179,11 @@ */ public abstract boolean canCommit (); + /** + * @return true if we can rebase + */ + public abstract boolean canRebase (); + /** * @return true if reset to another HEAD is considered SAFE */ diff -r 7a0c84058ab0 -r 78a01116b802 libs.git/src/org/netbeans/libs/git/jgit/GitClassFactory.java --- a/libs.git/src/org/netbeans/libs/git/jgit/GitClassFactory.java Sat Jan 12 22:41:09 2013 +0100 +++ b/libs.git/src/org/netbeans/libs/git/jgit/GitClassFactory.java Thu Jan 24 23:30:08 2013 +0100 @@ -45,6 +45,7 @@ import java.util.List; import java.util.Map; import org.eclipse.jgit.api.MergeResult; +import org.eclipse.jgit.api.RebaseResult; import org.eclipse.jgit.blame.BlameResult; import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.lib.ObjectId; @@ -64,6 +65,7 @@ import org.netbeans.libs.git.GitMergeResult; import org.netbeans.libs.git.GitPullResult; import org.netbeans.libs.git.GitPushResult; +import org.netbeans.libs.git.GitRebaseResult; import org.netbeans.libs.git.GitRemoteConfig; import org.netbeans.libs.git.GitRevertResult; import org.netbeans.libs.git.GitRevisionInfo; @@ -87,6 +89,8 @@ public abstract GitMergeResult createMergeResult (MergeResult mergeResult, File workTree); + public abstract GitRebaseResult createRebaseResult (RebaseResult rebaseResult, File workTree); + public abstract GitPullResult createPullResult (Map fetchUpdates, GitMergeResult mergeResult); public abstract GitPushResult createPushResult (Map remoteRepositoryUpdates, Map localRepositoryUpdates); diff -r 7a0c84058ab0 -r 78a01116b802 libs.git/src/org/netbeans/libs/git/jgit/commands/RebaseCommand.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs.git/src/org/netbeans/libs/git/jgit/commands/RebaseCommand.java Thu Jan 24 23:30:08 2013 +0100 @@ -0,0 +1,129 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ +package org.netbeans.libs.git.jgit.commands; + +import java.io.IOException; +import java.util.Arrays; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.JGitInternalException; +import org.eclipse.jgit.errors.CheckoutConflictException; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.Repository; +import org.netbeans.libs.git.GitException; +import org.netbeans.libs.git.GitRebaseResult; +import org.netbeans.libs.git.jgit.GitClassFactory; +import org.netbeans.libs.git.jgit.Utils; +import org.netbeans.libs.git.progress.ProgressMonitor; + +/** + * + * @author ymajoros + */ +public class RebaseCommand extends GitCommand { + + private final String revision; + private GitRebaseResult result; + private Operation operation; + + public enum Operation { + + ABORT, + BEGIN, + CONTINUE, + SKIP; + } + + public RebaseCommand(Repository repository, GitClassFactory gitFactory, String revision, Operation operation, ProgressMonitor monitor) { + super(repository, gitFactory, monitor); + this.revision = revision; + this.operation = operation; + } + + @Override + protected void run() throws GitException { + Repository repository = getRepository(); + org.eclipse.jgit.api.RebaseCommand command = new Git(repository).rebase(); + Ref ref = null; + try { + ref = repository.getRef(revision); + } catch (IOException ex) { + throw new GitException(ex); + } + + if (ref == null) { + command.setUpstream(Utils.findCommit(repository, revision)); + } else { + command.setUpstream(ref.getTarget().getObjectId()); + } + command.setOperation(org.eclipse.jgit.api.RebaseCommand.Operation.valueOf(operation.name())); + try { + result = getClassFactory().createRebaseResult(command.call(), repository.getWorkTree()); + } catch (org.eclipse.jgit.api.errors.CheckoutConflictException ex) { + parseConflicts(ex); + } catch (JGitInternalException ex) { + if (ex.getCause() instanceof CheckoutConflictException) { + parseConflicts(ex.getCause()); + } + throw new GitException(ex); + } catch (GitAPIException ex) { + throw new GitException(ex); + } + } + + @Override + protected String getCommandDescription() { + return new StringBuilder("git rebase ").append(revision).toString(); //NOI18N + } + + public GitRebaseResult getResult() { + return result; + } + + private void parseConflicts(Throwable original) throws GitException.CheckoutConflictException, GitException { + String[] lines = original.getMessage().split("\n"); //NOI18N + if (lines.length > 1) { + throw new GitException.CheckoutConflictException(Arrays.copyOfRange(lines, 1, lines.length), original); + } + throw new GitException(original); + } +}