List of usage examples for org.eclipse.jgit.lib Repository getBranch
@Nullable public String getBranch() throws IOException
From source file:org.eclipse.egit.gitflow.op.InitOperationTest.java
License:Open Source License
@Test(expected = CoreException.class) public void testInitLocalMasterMissing() throws Exception { testRepository.createInitialCommit("testInitLocalMasterMissing\n\nfirst commit\n"); Repository repository = testRepository.getRepository(); new RenameBranchOperation(repository, repository.findRef(repository.getBranch()), "foobar").execute(null); new InitOperation(repository).execute(null); }
From source file:org.eclipse.egit.gitflow.ui.internal.actions.FeatureFinishHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event); if (gfRepo == null) { return error(UIText.Handlers_noGitflowRepositoryFound); }/*from ww w.j a va 2 s. c om*/ final String featureBranch; Repository repo = gfRepo.getRepository(); try { featureBranch = repo.getBranch(); } catch (IOException e) { return error(e.getMessage(), e); } Shell activeShell = HandlerUtil.getActiveShell(event); FinishFeatureDialog dialog = new FinishFeatureDialog(activeShell, featureBranch); if (dialog.open() != Window.OK) { return null; } final boolean squash = dialog.isSquash(); boolean keepBranch = dialog.isKeepBranch(); try { try { if (squash && !UIRepositoryUtils.handleUncommittedFiles(repo, activeShell)) return null; } catch (GitAPIException e) { Activator.logError(e.getMessage(), e); return null; } final FeatureFinishOperation operation = new FeatureFinishOperation(gfRepo); operation.setSquash(squash); operation.setKeepBranch(keepBranch); JobUtil.scheduleUserWorkspaceJob(operation, UIText.FeatureFinishHandler_finishingFeature, JobFamilies.GITFLOW_FAMILY, new JobChangeAdapter() { @Override public void done(IJobChangeEvent jobChangeEvent) { if (jobChangeEvent.getResult().isOK()) { postMerge(gfRepo, featureBranch, squash, operation.getMergeResult()); } } }); } catch (WrongGitFlowStateException | CoreException | IOException | OperationCanceledException e) { return error(e.getMessage(), e); } return null; }
From source file:org.eclipse.egit.ui.gitflow.InitHandlerTest.java
License:Open Source License
@Test public void testInitEmptyRepoMissingMaster() throws Exception { String projectName = "AnyProjectName"; TestRepository testRepository = createAndShare(projectName); selectProject(projectName);//from ww w.j a v a 2s . c o m clickInit(); bot.button("Yes").click(); fillDialog(MASTER_BRANCH_MISSING); bot.waitUntil(shellIsActive(UIText.InitDialog_masterBranchIsMissing)); bot.button("Yes").click(); bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, "Git flow jobs")); Repository localRepository = testRepository.getRepository(); GitFlowRepository gitFlowRepository = new GitFlowRepository(localRepository); GitFlowConfig config = gitFlowRepository.getConfig(); assertEquals(DEVELOP_BRANCH, localRepository.getBranch()); assertEquals(MASTER_BRANCH_MISSING, config.getMaster()); assertEquals(FEATURE_BRANCH_PREFIX, config.getFeaturePrefix()); assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix()); assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix()); assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix()); assertNotNull(localRepository.exactRef(Constants.R_HEADS + DEVELOP_BRANCH)); }
From source file:org.eclipse.egit.ui.internal.actions.PullFromUpstreamActionHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { final Repository repository = getRepository(true, event); if (repository == null) return null; if (!canMerge(repository, event)) return null; // obtain the currently checked-out branch String branchName;/*from w w w.j a v a2 s.com*/ try { branchName = repository.getBranch(); } catch (IOException e) { throw new ExecutionException(e.getMessage(), e); } String jobname = NLS.bind(UIText.PullCurrentBranchActionHandler_PullJobname, branchName); int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); final PullOperation pull = new PullOperation(repository, timeout); Job job = new Job(jobname) { @Override protected IStatus run(IProgressMonitor monitor) { try { pull.execute(monitor); } catch (final CoreException e) { return e.getStatus(); } return Status.OK_STATUS; } }; job.setUser(true); job.setRule(pull.getSchedulingRule()); job.addJobChangeListener(new JobChangeAdapter() { @Override public void done(IJobChangeEvent cevent) { IStatus result = cevent.getJob().getResult(); if (result.getSeverity() == IStatus.CANCEL) { Display.getDefault().asyncExec(new Runnable() { public void run() { // don't use getShell(event) here since // the active shell has changed since the // execution has been triggered. Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); MessageDialog.openInformation(shell, UIText.PullCurrentBranchActionHandler_PullCanceledTitle, UIText.PullCurrentBranchActionHandler_PullCanceledMessage); } }); } else if (result.isOK()) { Display.getDefault().asyncExec(new Runnable() { public void run() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); new PullResultDialog(shell, repository, pull.getResult()).open(); } }); } } }); job.schedule(); return null; }
From source file:org.eclipse.egit.ui.internal.commit.command.CherryPickHandler.java
License:Open Source License
private boolean confirmCherryPick(final Shell shell, final Repository repository, final RevCommit commit) throws ExecutionException { final AtomicBoolean confirmed = new AtomicBoolean(false); final String message; try {//from w ww.ja v a 2 s. co m message = MessageFormat.format(UIText.CherryPickHandler_ConfirmMessage, commit.abbreviate(7).name(), repository.getBranch()); } catch (IOException e) { throw new ExecutionException("Exception obtaining current repository branch", e); //$NON-NLS-1$ } shell.getDisplay().syncExec(new Runnable() { public void run() { confirmed.set(MessageDialog.openConfirm(shell, UIText.CherryPickHandler_ConfirmTitle, message)); } }); return confirmed.get(); }
From source file:org.eclipse.egit.ui.internal.decorators.DecoratableResourceHelper.java
License:Open Source License
static String getBranchStatus(Repository repo) throws IOException { String branchName = repo.getBranch(); if (branchName == null) return null; BranchTrackingStatus status = BranchTrackingStatus.of(repo, branchName); if (status == null) return null; if (status.getAheadCount() == 0 && status.getBehindCount() == 0) return null; String formattedStatus = GitLabelProvider.formatBranchTrackingStatus(status); return formattedStatus; }
From source file:org.eclipse.egit.ui.internal.fetch.SimpleConfigureFetchDialog.java
License:Open Source License
/** * @param repository/*from w w w . j ava 2 s .com*/ * @return the configured remote for the current branch, or the default * remote; <code>null</code> if a local branch is checked out that * points to "." as remote */ public static RemoteConfig getConfiguredRemote(Repository repository) { String branch; try { branch = repository.getBranch(); } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); return null; } if (branch == null) return null; String remoteName; if (ObjectId.isId(branch)) remoteName = Constants.DEFAULT_REMOTE_NAME; else remoteName = repository.getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_REMOTE_SECTION); // check if we find the configured and default Remotes List<RemoteConfig> allRemotes; try { allRemotes = RemoteConfig.getAllRemoteConfigs(repository.getConfig()); } catch (URISyntaxException e) { allRemotes = new ArrayList<RemoteConfig>(); } RemoteConfig defaultConfig = null; RemoteConfig configuredConfig = null; for (RemoteConfig config : allRemotes) { if (config.getName().equals(Constants.DEFAULT_REMOTE_NAME)) defaultConfig = config; if (remoteName != null && config.getName().equals(remoteName)) configuredConfig = config; } RemoteConfig configToUse = configuredConfig != null ? configuredConfig : defaultConfig; return configToUse; }
From source file:org.eclipse.egit.ui.internal.history.command.AbstractRebaseHistoryCommandHandler.java
License:Open Source License
/** * @param repository//from www . j av a 2 s .c o m * @return the short name of the current branch that HEAD points to. * @throws ExecutionException */ protected String getCurrentBranch(Repository repository) throws ExecutionException { try { return repository.getBranch(); } catch (IOException e) { throw new ExecutionException(UIText.RebaseCurrentRefCommand_ErrorGettingCurrentBranchMessage, e); } }
From source file:org.eclipse.egit.ui.internal.history.command.RebaseCurrentHandler.java
License:Open Source License
private String getCurrentBranch(Repository repository) throws ExecutionException { try {//w w w. j av a2 s . c om return repository.getBranch(); } catch (IOException e) { throw new ExecutionException(UIText.RebaseCurrentRefCommand_ErrorGettingCurrentBranchMessage, e); } }
From source file:org.eclipse.egit.ui.internal.preferences.GitProjectPropertyPage.java
License:Open Source License
private void fillValues(Repository repository) throws IOException { gitDir.setText(repository.getDirectory().getAbsolutePath()); branch.setText(repository.getBranch()); workDir.setText(repository.getWorkTree().getAbsolutePath()); state.setText(repository.getRepositoryState().getDescription()); final ObjectId objectId = repository.resolve(repository.getFullBranch()); if (objectId == null) { if (repository.getAllRefs().size() == 0) id.setText(UIText.GitProjectPropertyPage_ValueEmptyRepository); else//w w w. ja v a 2 s. c o m id.setText(UIText.GitProjectPropertyPage_ValueUnbornBranch); } else id.setText(objectId.name()); }