use of org.eclipse.jgit.api.MergeResult in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method mergeProfileChanges.
@Override
public void mergeProfileChanges(Patch patch, File gitRepository, String versionBranch, String patchBranch) {
Git git = null;
try {
git = Git.open(gitRepository);
// merge version branch with patch branch - no fast forward, so we have nice named commit
git.checkout().setCreateBranch(false).setName(versionBranch).call();
MergeResult result = git.merge().setFastForward(MergeCommand.FastForwardMode.NO_FF).include(git.getRepository().resolve(patchBranch)).setCommit(false).call();
boolean commit = true;
if (result.getMergeStatus() == MergeResult.MergeStatus.CONFLICTING) {
handleMergeConflict(git, result, versionBranch, patchBranch);
} else if (result.getMergeStatus() != MergeResult.MergeStatus.MERGED_NOT_COMMITTED) {
commit = false;
Activator.log2(LogService.LOG_ERROR, "Can't merge version branch \"" + versionBranch + "\" with" + " patch branch \"" + patchBranch + "\". Resetting the branch.");
git.reset().setMode(ResetCommand.ResetType.HARD).call();
}
// if (commit) {
// git.commit()
// .setMessage("Installing rollup patch \"" + patch.getPatchData().getId() + "\"")
// .call();
// }
} catch (Exception e) {
throw new PatchException(e.getMessage(), e);
} finally {
if (git != null) {
try {
git.branchDelete().setBranchNames(patchBranch).setForce(true).call();
} catch (GitAPIException e) {
Activator.log2(LogService.LOG_ERROR, e.getMessage());
}
gitPatchRepository.closeRepository(git, false);
}
}
}
use of org.eclipse.jgit.api.MergeResult in project fabric8 by jboss-fuse.
the class GitConflictResolutionIT method mergeConflict.
@Test
public void mergeConflict() throws Exception {
prepareChanges();
RevWalk rw = new RevWalk(git.getRepository());
git.checkout().setName("custom").setCreateBranch(false).call();
MergeResult result = git.merge().setFastForward(MergeCommand.FastForwardMode.NO_FF).include(git.getRepository().resolve("patched")).call();
assertThat(result.getMergeStatus(), equalTo(MergeResult.MergeStatus.CONFLICTING));
assertThat(result.getConflicts().size(), equalTo(1));
Map<String, IndexDiff.StageState> conflicts = git.status().call().getConflictingStageState();
assertThat(conflicts.size(), equalTo(1));
assertThat(conflicts.get("etc/org.ops4j.pax.logging.cfg"), equalTo(IndexDiff.StageState.BOTH_MODIFIED));
}
use of org.eclipse.jgit.api.MergeResult in project archi-modelrepository-plugin by archi-contribs.
the class RevertCommitAction method run.
@Override
public void run() {
// Offer to save the model if open and dirty
// We need to do this to keep grafico and temp files in sync
IArchimateModel model = getRepository().locateModel();
if (model != null && IEditorModelManager.INSTANCE.isModelDirty(model)) {
if (!offerToSaveModel(model)) {
return;
}
}
// Do the Grafico Export first
try {
getRepository().exportModelToGraficoFiles();
} catch (IOException ex) {
displayErrorDialog(Messages.RevertCommitAction_0, ex);
return;
}
// Then offer to Commit
try {
if (getRepository().hasChangesToCommit()) {
if (!offerToCommitChanges()) {
return;
}
}
} catch (IOException | GitAPIException ex) {
displayErrorDialog(Messages.RevertCommitAction_3, ex);
return;
}
// Revert
try (Git git = Git.open(getRepository().getLocalRepositoryFolder())) {
RevertCommand revertCommand = doRevertCommand(git);
MergeResult failingResult = revertCommand.getFailingResult();
if (failingResult != null) {
MergeConflictHandler handler = new MergeConflictHandler(failingResult, getRepository(), fWindow.getShell());
boolean result = handler.checkForMergeConflicts();
if (result) {
handler.mergeAndCommit(Messages.RevertCommitAction_4, false);
} else {
// User cancelled - we assume user has committed all changes so we can reset
handler.resetToLocalState();
}
} else {
new GraficoModelLoader(getRepository()).loadModel();
}
// Save the checksum
getRepository().saveChecksum();
notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
} catch (IOException | GitAPIException ex) {
displayErrorDialog(Messages.RevertCommitAction_1, ex);
}
}
use of org.eclipse.jgit.api.MergeResult in project egit by eclipse.
the class MergeOperation method execute.
@Override
public void execute(IProgressMonitor m) throws CoreException {
if (mergeResult != null)
throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), CoreText.OperationAlreadyExecuted));
IWorkspaceRunnable action = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor mymonitor) throws CoreException {
IProject[] validProjects = ProjectUtil.getValidOpenProjects(repository);
SubMonitor progress = SubMonitor.convert(mymonitor, NLS.bind(CoreText.MergeOperation_ProgressMerge, refName), 3);
try (Git git = new Git(repository)) {
progress.worked(1);
MergeCommand merge = git.merge().setProgressMonitor(new EclipseGitProgressTransformer(progress.newChild(1)));
Ref ref = repository.findRef(refName);
if (ref != null) {
merge.include(ref);
} else {
merge.include(ObjectId.fromString(refName));
}
if (fastForwardMode != null) {
merge.setFastForward(fastForwardMode);
}
if (commit != null) {
merge.setCommit(commit.booleanValue());
}
if (squash != null) {
merge.setSquash(squash.booleanValue());
}
if (mergeStrategy != null) {
merge.setStrategy(mergeStrategy);
}
if (message != null) {
merge.setMessage(message);
}
mergeResult = merge.call();
if (MergeResult.MergeStatus.NOT_SUPPORTED.equals(mergeResult.getMergeStatus())) {
throw new TeamException(new Status(IStatus.INFO, Activator.getPluginId(), mergeResult.toString()));
}
} catch (IOException e) {
throw new TeamException(CoreText.MergeOperation_InternalError, e);
} catch (NoHeadException e) {
throw new TeamException(CoreText.MergeOperation_MergeFailedNoHead, e);
} catch (ConcurrentRefUpdateException e) {
throw new TeamException(CoreText.MergeOperation_MergeFailedRefUpdate, e);
} catch (CheckoutConflictException e) {
mergeResult = new MergeResult(e.getConflictingPaths());
return;
} catch (GitAPIException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
} finally {
ProjectUtil.refreshValidProjects(validProjects, progress.newChild(1));
}
}
};
// lock workspace to protect working tree changes
ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, m);
}
use of org.eclipse.jgit.api.MergeResult in project egit by eclipse.
the class DecoratableWorkingSetTest method testAnyConflictsIsConflicts.
@Test
public void testAnyConflictsIsConflicts() throws Exception {
// Create new file and commit
IFile file = createFile(project1, TEST_FILE, "Something");
gitAdd(git, file);
RevCommit masterCommit = gitCommit(git);
// Create and checkout new branch, change file content, add and commit
// file
git.checkout().setCreateBranch(true).setName("first_topic").call();
file = findFile(project1, TEST_FILE);
write(file.getLocation().toFile(), "First Topic Content");
project1.refreshLocal(IResource.DEPTH_INFINITE, null);
gitAdd(git, file);
RevCommit firstTopicCommit = gitCommit(git);
// Create and checkout new branch (from master), change file content,
// add and commit file
git.checkout().setCreateBranch(true).setStartPoint(masterCommit).setName("second_topic").call();
file = findFile(project1, TEST_FILE);
write(file.getLocation().toFile(), "Second Topic Content");
project1.refreshLocal(IResource.DEPTH_INFINITE, null);
gitAdd(git, file);
gitCommit(git);
// merge second_topic with first_topic
MergeResult mergeResult = git.merge().include(firstTopicCommit).call();
assertEquals(MergeStatus.CONFLICTING, mergeResult.getMergeStatus());
IDecoratableResource[] expectedDRs = new IDecoratableResource[] { newExpectedDecoratableResource(project1).tracked().conflicts(), newExpectedDecoratableResource(file).tracked().conflicts(), newExpectedDecoratableWorkingSet(WORKING_SET).tracked().conflicts() };
IndexDiffData indexDiffData = waitForIndexDiff(true);
IDecoratableResource[] actualDRs = { newDecoratableResource(indexDiffData, project1), newDecoratableResource(indexDiffData, file), newDecoratableWorkingSet(resourceMapping) };
assertArrayEquals(expectedDRs, actualDRs);
assertHasUnstagedChanges(true, actualDRs);
assertDecorationConflicts(resourceMapping);
}
Aggregations