Search in sources :

Example 1 with SetupUpstreamMode

use of org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode in project egit by eclipse.

the class CreateLocalBranchOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor actMonitor) throws CoreException {
            String taskName = NLS.bind(CoreText.CreateLocalBranchOperation_CreatingBranchMessage, name);
            SubMonitor progress = SubMonitor.convert(actMonitor);
            progress.setTaskName(taskName);
            try (Git git = new Git(repository)) {
                if (ref != null) {
                    SetupUpstreamMode mode;
                    if (upstreamConfig == null)
                        mode = SetupUpstreamMode.NOTRACK;
                    else
                        mode = SetupUpstreamMode.SET_UPSTREAM;
                    git.branchCreate().setName(name).setStartPoint(ref.getName()).setUpstreamMode(mode).call();
                } else
                    git.branchCreate().setName(name).setStartPoint(commit).setUpstreamMode(SetupUpstreamMode.NOTRACK).call();
            } catch (Exception e) {
                throw new CoreException(Activator.error(e.getMessage(), e));
            }
            if (upstreamConfig != null) {
                // set "branch.<name>.rebase"
                StoredConfig config = repository.getConfig();
                config.setEnum(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REBASE, upstreamConfig);
                try {
                    config.save();
                } catch (IOException e) {
                    throw new CoreException(Activator.error(e.getMessage(), e));
                }
            }
        }
    };
    // lock workspace to protect working tree changes
    ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Git(org.eclipse.jgit.api.Git) CoreException(org.eclipse.core.runtime.CoreException) SetupUpstreamMode(org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode) SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

IOException (java.io.IOException)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 SetupUpstreamMode (org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode)1 Git (org.eclipse.jgit.api.Git)1 StoredConfig (org.eclipse.jgit.lib.StoredConfig)1