Skip to content

Commit

Permalink
FORGE-1893: No need to switch branches if same as default
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jun 20, 2014
1 parent 4709be0 commit 8cecb4f
Showing 1 changed file with 15 additions and 9 deletions.
@@ -1,11 +1,12 @@
package org.jboss.forge.addon.manager.impl.ui;

import java.io.File;
import java.io.IOException;

import javax.inject.Inject;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.jboss.forge.addon.dependencies.Coordinate;
import org.jboss.forge.addon.git.GitUtils;
Expand Down Expand Up @@ -159,21 +160,26 @@ public Result execute(UIExecutionContext context) throws Exception
}
}

private void cloneTo(DirectoryResource projectRoot) throws GitAPIException
private void cloneTo(DirectoryResource projectRoot) throws GitAPIException, IOException
{
Git git = null;
try
{
git = gitUtils.clone(projectRoot, url.getValue().getFullyQualifiedName());
if (ref.hasValue())
{
String branchName = ref.getValue();
git.checkout().
setCreateBranch(true).
setName(branchName).
setUpstreamMode(SetupUpstreamMode.TRACK).
setStartPoint("origin/" + branchName).
call();
String refName = ref.getValue();
String currentBranch = git.getRepository().getBranch();
// No need to checkout if the branch name is the same
if (!currentBranch.equals(refName))
{
git.checkout().
setCreateBranch(true).
setName(refName).
setUpstreamMode(SetupUpstreamMode.TRACK).
setStartPoint("origin/" + refName).
call();
}
}
}
finally
Expand Down

0 comments on commit 8cecb4f

Please sign in to comment.