public void execute (final ExecutionEvent event, final Repository repository, final String branchRef) { BranchOperationUI op = BranchOperationUI.checkout(repository, branchRef) .doneCallback( new DoneCallback() { public void done(CheckoutResult result) { if (result.getStatus() == CheckoutResult.Status.OK) { IPath path = new Path(branchRef); String stableBranch = path.segment(3); if (stableBranch.equals("features") && path.segmentCount() > 6) { //$NON-NLS-1$ stableBranch = path.removeFirstSegments(3).uptoSegment(3).toString(); } String newUpstreamRef = branchRef + ":refs/for/" + stableBranch; //$NON-NLS-1$ repository.getConfig().setString("remote", "origin", "push", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ newUpstreamRef); repository.getConfig().setBoolean("branch", //$NON-NLS-1$ path.removeFirstSegments(2).removeTrailingSeparator().makeRelative().toString(), "rebase", true); //$NON-NLS-1$ try { repository.getConfig().save(); } catch (IOException e) { RepositoryUtils.handleException(e); } } } }); op.start(); }
/** * Handler for the commit button. Attempts a commit of the added files, * then closes the window and notifies SessionController its done */ public void handleCheckoutButton() { try { if(fileNames.size() == 0) { notificationPaneController.addNotification("You need to add some files first"); return; } CheckoutResult result = this.repoHelper.checkoutFiles(fileNames, commitHelper.getId()); switch (result.getStatus()) { case CONFLICTS: notificationPaneController.addNotification("Checkout has not completed because of checkout conflicts"); break; case ERROR: notificationPaneController.addNotification("An error occurred during checkout"); break; case NONDELETED: notificationPaneController.addNotification("Checkout has completed, but some files could not be deleted."); break; case NOT_TRIED: notificationPaneController.addNotification("Something went wrong... try checking out again."); break; // The OK case happens when a file is changed in the index or an invalid file // was entered, for now just call git status and close // TODO: figure out if anything actually changed case OK: sessionController.gitStatus(); closeWindow(); break; } } catch (Exception e) { notificationPaneController.addNotification("Something went wrong."); } }
protected void execute(ExecutionEvent event, final Repository repository, final String branchRef) throws ExecutionException { //check if local branch exists final String branchName = branchRef.substring("refs/heads/".length()); //$NON-NLS-1$ try { if (repository.getRef(branchRef) == null) { //create local branch String remoteBranchRef = "refs/remotes/origin/" + branchName; //$NON-NLS-1$ Ref remoteRef = repository.getRef(remoteBranchRef); if (remoteRef == null) { throw new RuntimeException(MessageFormat.format( "Remote branch {0} doesn't exist", remoteBranchRef)); } new Git(repository).branchCreate(). setName(branchName). setStartPoint(remoteBranchRef). setUpstreamMode(SetupUpstreamMode.TRACK). call(); repository.getConfig().setBoolean("branch", branchName, "rebase", true); //$NON-NLS-1$//$NON-NLS-2$ } } catch (Exception e1) { RepositoryUtils.handleException(e1); return; } BranchOperationUI op = BranchOperationUI.checkout(repository, branchRef) .doneCallback( new DoneCallback() { public void done(CheckoutResult result) { if (result.getStatus() == CheckoutResult.Status.OK) { String newUpstreamRef = branchRef + ":refs/for/" + branchName; //$NON-NLS-1$ repository.getConfig().setString("remote", "origin", "push", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ newUpstreamRef); //ensure in rebase mode repository.getConfig().setBoolean("branch", branchName, "rebase", true); //$NON-NLS-1$//$NON-NLS-2$ try { repository.getConfig().save(); } catch (IOException e) { RepositoryUtils.handleException(e); } } } }); op.start(); }
public void done(CheckoutResult result);