use of org.eclipse.jgit.lib.RefUpdate in project egit by eclipse.
the class ListRemoteOperationTest method setUp.
/**
* Set up repository1 with branch "master", create some project and commit
* it; then clone into repository2; finally create a branch "test" on top of
* "master" in repository2
*
* @throws Exception
*/
@Before
public void setUp() throws Exception {
workdir = testUtils.createTempDir("Repository1");
workdir2 = testUtils.createTempDir("Repository2");
repository1 = new TestRepository(new File(workdir, Constants.DOT_GIT));
// now we create a project in repo1
IProject project = testUtils.createProjectInLocalFileSystem(workdir, projectName);
testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");
repository1.connect(project);
repository1.trackAllFiles(project);
repository1.commit("Initial commit");
// let's get rid of the project
project.delete(false, false, null);
// let's clone repository1 to repository2
URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString());
CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0);
clop.run(null);
Repository existingRepo = Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, Constants.DOT_GIT));
repository2 = new TestRepository(existingRepo);
// we push to branch "test" of repository2
RefUpdate createBranch = repository2.getRepository().updateRef("refs/heads/test");
createBranch.setNewObjectId(repository2.getRepository().resolve("refs/heads/master"));
createBranch.update();
}
use of org.eclipse.jgit.lib.RefUpdate in project egit by eclipse.
the class PushOperationTest method setUp.
/**
* Set up repository1 with branch "master", create some project and commit
* it; then clone into repository2; finally create a branch "test" on top of
* "master" in repository2
*
* @throws Exception
*/
@Before
public void setUp() throws Exception {
workdir = testUtils.createTempDir("Repository1");
workdir2 = testUtils.createTempDir("Repository2");
repository1 = new TestRepository(new File(workdir, Constants.DOT_GIT));
// now we create a project in repo1
IProject project = testUtils.createProjectInLocalFileSystem(workdir, projectName);
testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");
repository1.connect(project);
repository1.trackAllFiles(project);
repository1.commit("Initial commit");
// let's get rid of the project
project.delete(false, false, null);
// let's clone repository1 to repository2
URIish uri = repository1.getUri();
CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0);
clop.run(null);
Repository repo2 = Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, Constants.DOT_GIT));
repository2 = new TestRepository(repo2);
// we push to branch "test" of repository2
RefUpdate createBranch = repository2.getRepository().updateRef("refs/heads/test");
createBranch.setNewObjectId(repository2.getRepository().resolve("refs/heads/master"));
createBranch.update();
}
use of org.eclipse.jgit.lib.RefUpdate in project egit by eclipse.
the class TestRepository method createBranch.
/**
* Creates a new branch
*
* @param refName
* starting point for the new branch
* @param newRefName
* @throws IOException
*/
public void createBranch(String refName, String newRefName) throws IOException {
RefUpdate updateRef;
updateRef = repository.updateRef(newRefName);
Ref startRef = repository.findRef(refName);
ObjectId startAt = repository.resolve(refName);
String startBranch;
if (startRef != null)
startBranch = refName;
else
startBranch = startAt.name();
startBranch = Repository.shortenRefName(startBranch);
updateRef.setNewObjectId(startAt);
updateRef.setRefLogMessage("branch: Created from " + startBranch, // $NON-NLS-1$
false);
updateRef.update();
}
use of org.eclipse.jgit.lib.RefUpdate in project egit by eclipse.
the class LocalRepositoryTestCase method createBranch.
protected static void createBranch(Repository myRepository, String newRefName) throws IOException {
RefUpdate updateRef = myRepository.updateRef(newRefName);
Ref sourceBranch = myRepository.exactRef("refs/heads/master");
ObjectId startAt = sourceBranch.getObjectId();
String startBranch = Repository.shortenRefName(sourceBranch.getName());
updateRef.setNewObjectId(startAt);
updateRef.setRefLogMessage("branch: Created from " + startBranch, // $NON-NLS-1$
false);
updateRef.update();
TestUtil.waitForJobs(50, 5000);
}
use of org.eclipse.jgit.lib.RefUpdate in project gitblit by gitblit.
the class JGitUtils method deleteBranchRef.
/**
* Deletes the specified branch ref.
*
* @param repository
* @param branch
* @return true if successful
*/
public static boolean deleteBranchRef(Repository repository, String branch) {
try {
RefUpdate refUpdate = repository.updateRef(branch, false);
refUpdate.setForceUpdate(true);
RefUpdate.Result result = refUpdate.delete();
switch(result) {
case NEW:
case FORCED:
case NO_CHANGE:
case FAST_FORWARD:
return true;
default:
LOGGER.error(MessageFormat.format("{0} failed to delete to {1} returned result {2}", repository.getDirectory().getAbsolutePath(), branch, result));
}
} catch (Throwable t) {
error(t, repository, "{0} failed to delete {1}", branch);
}
return false;
}
Aggregations