Search in sources :

Example 16 with RefUpdate

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();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) TestRepository(org.eclipse.egit.core.test.TestRepository) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) File(java.io.File) IProject(org.eclipse.core.resources.IProject) CloneOperation(org.eclipse.egit.core.op.CloneOperation) RefUpdate(org.eclipse.jgit.lib.RefUpdate) Before(org.junit.Before)

Example 17 with RefUpdate

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();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) TestRepository(org.eclipse.egit.core.test.TestRepository) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) CloneOperation(org.eclipse.egit.core.op.CloneOperation) RefUpdate(org.eclipse.jgit.lib.RefUpdate) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) Before(org.junit.Before)

Example 18 with RefUpdate

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();
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Example 19 with RefUpdate

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);
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Example 20 with RefUpdate

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;
}
Also used : Result(org.eclipse.jgit.lib.RefUpdate.Result) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Aggregations

RefUpdate (org.eclipse.jgit.lib.RefUpdate)110 Repository (org.eclipse.jgit.lib.Repository)51 ObjectId (org.eclipse.jgit.lib.ObjectId)45 IOException (java.io.IOException)34 Test (org.junit.Test)32 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)27 TestRepository (org.eclipse.jgit.junit.TestRepository)26 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)24 RevWalk (org.eclipse.jgit.revwalk.RevWalk)23 Result (org.eclipse.jgit.lib.RefUpdate.Result)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)20 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)18 Ref (org.eclipse.jgit.lib.Ref)17 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)17 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)15 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)14 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)12 LockFailureException (com.google.gerrit.git.LockFailureException)10 PersonIdent (org.eclipse.jgit.lib.PersonIdent)9 DirCache (org.eclipse.jgit.dircache.DirCache)8