use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.
the class BranchOperationUI method run.
/**
* Runs the operation synchronously.
*
* @param monitor
* @throws CoreException
*/
public void run(IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 100);
target = confirmTarget(progress.newChild(20));
if (target == null) {
return;
}
final boolean restore = Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.CHECKOUT_PROJECT_RESTORE);
BranchOperation bop = new BranchOperation(repository, target, !restore);
doCheckout(bop, restore, progress.newChild(80));
show(bop.getResult());
}
use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.
the class PushBranchWizardTest method checkoutNewLocalBranch.
private void checkoutNewLocalBranch(String branchName) throws Exception {
CreateLocalBranchOperation createBranch = new CreateLocalBranchOperation(repository, branchName, repository.findRef("master"), null);
createBranch.execute(null);
BranchOperation checkout = new BranchOperation(repository, branchName);
checkout.execute(null);
}
use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.
the class PushOperationTest method testPush.
/**
* Push from repository1 "master" into "test" of repository2.
*
* @throws Exception
*/
@Test
public void testPush() throws Exception {
// push from repository1 to repository2
PushOperation pop = createPushOperation();
pop.run(new NullProgressMonitor());
assertEquals(Status.UP_TO_DATE, getStatus(pop.getOperationResult()));
// let's add a new file to the project shared with repository1
IProject proj = importProject(repository1, projectName);
ArrayList<IFile> files = new ArrayList<IFile>();
IFile newFile = testUtils.addFileToProject(proj, "folder2/file2.txt", "New file");
files.add(newFile);
IFile[] fileArr = files.toArray(new IFile[files.size()]);
AddToIndexOperation trop = new AddToIndexOperation(files);
trop.execute(null);
CommitOperation cop = new CommitOperation(fileArr, files, TestUtils.AUTHOR, TestUtils.COMMITTER, "Added file");
cop.execute(null);
proj.delete(false, false, null);
pop = createPushOperation();
pop.run(null);
assertEquals(Status.OK, getStatus(pop.getOperationResult()));
try {
// assert that we cannot run this again
pop.run(null);
fail("Expected Exception not thrown");
} catch (IllegalStateException e) {
// expected
}
pop = createPushOperation();
pop.run(null);
assertEquals(Status.UP_TO_DATE, getStatus(pop.getOperationResult()));
String newFilePath = newFile.getFullPath().toOSString();
File testFile = new File(workdir2, newFilePath);
assertFalse(testFile.exists());
testFile = new File(workdir, newFilePath);
assertTrue(testFile.exists());
// check out test and verify the file is there
BranchOperation bop = new BranchOperation(repository2.getRepository(), "refs/heads/test");
bop.execute(null);
testFile = new File(workdir2, newFilePath);
assertTrue(testFile.exists());
}
use of org.eclipse.egit.core.op.BranchOperation 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));
}
}
use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.
the class GitFlowOperation method start.
/**
* git flow * start
*
* @param monitor
* @param branchName
* @param sourceCommit
* @throws CoreException
*/
protected void start(IProgressMonitor monitor, String branchName, RevCommit sourceCommit) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 2);
CreateLocalBranchOperation branchOperation = createBranchFromHead(branchName, sourceCommit);
branchOperation.execute(progress.newChild(1));
BranchOperation checkoutOperation = new BranchOperation(repository.getRepository(), branchName);
checkoutOperation.execute(progress.newChild(1));
}
Aggregations