@Override protected IStatus run(IProgressMonitor monitor) { try { SubMonitor subMonitor = SubMonitor.convert(monitor); // fetch target first to retrieve parent commit String targetRef = EGitUiUtil.fetchPatchSet(subMonitor, repository, remote, target).getName(); String baseRef; if (base != null) { baseRef = EGitUiUtil.fetchPatchSet(subMonitor, repository, remote, base).getName(); } else { baseRef = fetchParent(target, subMonitor); } openSynchronization(baseRef, targetRef); } catch (Exception e) { return new Status(IStatus.ERROR, GerritUiPlugin.PLUGIN_ID, "Patch set retrieval failed", e); } return Status.OK_STATUS; }
public static RevCommit fetchPatchSet( IProgressMonitor monitor, Repository repository, RemoteConfig remote, PatchSet patchSet) throws IOException, CoreException, URISyntaxException { try { // commit was already fetched return EGitUiUtil.getRevCommit(repository, patchSet); } catch (MissingObjectException e) { // need to fetch it RefSpec refSpec = new RefSpec(patchSet.getRefName() + ":FETCH_HEAD"); // $NON-NLS-1$ return fetchRefSpec(monitor, repository, remote, refSpec); } }
private GerritToGitMapping getRepository(ChangeDetail changeDetail) { GerritToGitMapping mapper = new GerritToGitMapping( getTaskEditorPage().getTaskRepository(), getConfig(), getGerritProject(changeDetail)); try { if (mapper.find() != null) { return mapper; } else if (mapper.getGerritProject() != null) { boolean create = MessageDialog.openQuestion( getShell(), "Clone Git Repository", "The referenced Git repository was not found in the workspace. Clone Git repository?"); if (create) { int response = EGitUiUtil.openCloneRepositoryWizard( getShell(), getTaskEditorPage().getTaskRepository(), mapper.getGerritProject()); if (response == Window.OK && mapper.find() != null) { return mapper; } } } else { String message = NLS.bind( "No Git repository found for fetching Gerrit change {0}", getTask().getTaskKey()); String reason = NLS.bind( "No remote config found that has fetch URL with host ''{0}'' and path matching ''{1}''", mapper.getGerritHost(), mapper.getGerritProjectName()); GerritCorePlugin.logError(message, null); ErrorDialog.openError( getShell(), "Gerrit Fetch Change Error", message, new Status(IStatus.ERROR, GerritUiPlugin.PLUGIN_ID, reason)); } } catch (IOException e) { Status status = new Status(IStatus.ERROR, GerritUiPlugin.PLUGIN_ID, "Error accessing Git repository", e); StatusManager.getManager() .handle(status, StatusManager.BLOCK | StatusManager.SHOW | StatusManager.LOG); } return null; }
private String fetchParent(PatchSet patchSet, IProgressMonitor monitor) throws URISyntaxException, CoreException, IOException { RevCommit targetCommit = EGitUiUtil.getRevCommit(repository, patchSet); RevCommit parentCommit = targetCommit.getParents()[0]; return parentCommit.getName(); }