use of org.eclipse.jgit.api.CheckoutResult in project jbosstools-openshift by jbosstools.
the class ImportProjectOperation method checkoutBranch.
protected void checkoutBranch(String gitRef, String gitUrl, List<IProject> importedProjects, File repositoryFolder, IProgressMonitor monitor) throws CoreException {
if (!StringUtils.isEmpty(gitRef) && !CollectionUtils.isEmpty(importedProjects)) {
// all projects are in the same repo
IProject project = importedProjects.get(0);
Repository repository = EGitUtils.getRepository(project);
try {
if (!EGitUtils.hasBranch(gitRef, repository)) {
Pattern gitURIPattern = Pattern.compile(RegExUtils.escapeRegex(gitUrl));
RemoteConfig remote = EGitUtils.getRemoteByUrl(gitURIPattern, repository);
fetchBranch(gitRef, remote, repository, monitor);
}
CheckoutResult result = EGitUtils.checkoutBranch(gitRef, repository, monitor);
switch(result.getStatus()) {
case CONFLICTS:
case ERROR:
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Could not check out the branch {0} of the (reused) local repository at {1} because of {2}." + " Please resolve the problem and check out the branch manually so that it matches the code that's used in your OpenShift application.", new Object[] { gitRef, repositoryFolder, result.getStatus().toString().toLowerCase() })));
default:
}
} catch (IOException e) {
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Could check that branch {0} exists within the (reused) local repository at {1}.", gitRef, repositoryFolder), e));
} catch (InvocationTargetException e) {
throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Could not fetch branch {0} from check that branch {0} exists within the (reused) local repository at {1}.", gitRef, repositoryFolder), e));
}
}
}
use of org.eclipse.jgit.api.CheckoutResult in project jbosstools-openshift by jbosstools.
the class EGitUtilsTest method shouldCheckoutBranch.
@Test
public void shouldCheckoutBranch() throws Exception {
// given file committed in custom branch
String branch = testRepository.getCurrentBranch();
testRepository.createAndCheckoutBranch(Constants.HEAD, REPO_BRANCH);
String fileName = "a.txt";
String fileContent = "adietish@redhat.com";
IFile file = commitFile(fileName, fileContent, testProject, testRepository);
testUtils.assertRepositoryContainsFilesWithContent(testRepository.getRepository(), new String[] { testUtils.getPathInRepository(file), fileContent });
testRepository.checkoutBranch(branch);
testUtils.assertRepositoryMisses(testRepository.getRepository(), testUtils.getPathInRepository(file));
// when checkout custom branch
CheckoutResult result = EGitUtils.branch(REPO_BRANCH, testProject.getProject(), null);
// then file should be present
assertTrue(result.getStatus() == CheckoutResult.Status.OK);
assertTrue(testRepository.isCurrentBranch(REPO_BRANCH));
testUtils.assertRepositoryContainsFilesWithContent(testRepository.getRepository(), new String[] { testUtils.getPathInRepository(file), fileContent });
}
use of org.eclipse.jgit.api.CheckoutResult in project egit by eclipse.
the class FeatureCheckoutHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
if (gfRepo == null) {
return error(UIText.Handlers_noGitflowRepositoryFound);
}
Repository repository = gfRepo.getRepository();
final List<Ref> refs = gfRepo.getFeatureBranches();
FeatureBranchSelectionDialog dialog = new FeatureBranchSelectionDialog(HandlerUtil.getActiveShell(event), refs, UIText.FeatureCheckoutHandler_selectFeature, UIText.FeatureCheckoutHandler_localFeatures, Constants.R_HEADS + gfRepo.getConfig().getFeaturePrefix(), gfRepo);
if (dialog.open() != Window.OK) {
return null;
}
final Ref ref = dialog.getSelectedNode();
try {
String featureName = gfRepo.getFeatureBranchName(ref);
// TODO: consider using BranchOperationUI because checkout can take
// a long time on large repositories
FeatureCheckoutOperation checkoutOperation = new FeatureCheckoutOperation(gfRepo, featureName);
JobUtil.scheduleUserWorkspaceJob(checkoutOperation, UIText.FeatureCheckoutHandler_checkingOutFeature, JobFamilies.GITFLOW_FAMILY);
IJobManager jobMan = Job.getJobManager();
try {
jobMan.join(GITFLOW_FAMILY, null);
} catch (OperationCanceledException | InterruptedException e) {
return error(e.getMessage(), e);
}
CheckoutResult result = checkoutOperation.getResult();
if (!CheckoutResult.Status.OK.equals(result.getStatus())) {
Shell shell = HandlerUtil.getActiveShell(event);
if (!handleUncommittedFiles(gfRepo.getRepository(), shell, repository.getWorkTree().getName())) {
return Status.CANCEL_STATUS;
} else {
JobUtil.scheduleUserWorkspaceJob(checkoutOperation, UIText.FeatureCheckoutHandler_checkingOutFeature, JobFamilies.GITFLOW_FAMILY);
}
}
} catch (GitAPIException e) {
throw new RuntimeException(e);
}
return null;
}
use of org.eclipse.jgit.api.CheckoutResult in project egit by eclipse.
the class FeatureTrackOperation method execute.
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 3);
try {
String newLocalBranch = repository.getConfig().getFeatureBranchName(featureName);
operationResult = fetch(progress.newChild(1), timeout);
if (repository.hasBranch(newLocalBranch)) {
String errorMessage = String.format(CoreText.FeatureTrackOperation_localBranchExists, newLocalBranch);
throw new CoreException(error(errorMessage));
}
CreateLocalBranchOperation createLocalBranchOperation = new CreateLocalBranchOperation(repository.getRepository(), newLocalBranch, remoteFeature, BranchRebaseMode.NONE);
createLocalBranchOperation.execute(progress.newChild(1));
BranchOperation branchOperation = new BranchOperation(repository.getRepository(), newLocalBranch);
branchOperation.execute(progress.newChild(1));
CheckoutResult result = branchOperation.getResult();
if (!Status.OK.equals(result.getStatus())) {
String errorMessage = String.format(CoreText.FeatureTrackOperation_checkoutReturned, newLocalBranch, result.getStatus().name());
throw new CoreException(error(errorMessage));
}
try {
repository.setRemote(newLocalBranch, DEFAULT_REMOTE_NAME);
repository.setUpstreamBranchName(newLocalBranch, repository.getConfig().getFullFeatureBranchName(featureName));
} catch (IOException e) {
throw new CoreException(error(CoreText.FeatureTrackOperation_unableToStoreGitConfig, e));
}
} catch (URISyntaxException e) {
throw new CoreException(error(e.getMessage(), e));
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
throw new CoreException(error(targetException.getMessage(), targetException));
} catch (GitAPIException e) {
throw new CoreException(error(e.getMessage(), e));
}
}
Aggregations