Search in sources :

Example 56 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project jbosstools-openshift by jbosstools.

the class EGitUtilsTest method shouldFetchAndHaveRemoteRef.

@Test
public void shouldFetchAndHaveRemoteRef() throws Exception {
    // given
    testRepository.createAndCheckoutBranch(Constants.HEAD, REPO_BRANCH);
    RemoteConfig remoteConfig = EGitUtils.getRemoteByName("origin", testRepositoryClone.getRepository());
    String fullRef = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + REPO_BRANCH;
    assertThat(testRepositoryClone.getRepository().findRef(fullRef), is(nullValue()));
    // when
    EGitUtils.fetch(remoteConfig, testRepositoryClone.getRepository(), new NullProgressMonitor());
    // then
    assertThat(testRepositoryClone.getRepository().findRef(fullRef), is(not(nullValue())));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) Test(org.junit.Test)

Example 57 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project jbosstools-openshift by jbosstools.

the class EGitUtilsTest method shouldReturnLatestCommitInRemoteRepo.

@Test
public void shouldReturnLatestCommitInRemoteRepo() throws Exception {
    // given
    File file = testRepository.createFile("gargamel.txt", "a smurfs soup is excellent!");
    RevCommit commit = testRepository.addAndCommit(file, "adding a file");
    String currentBranch = testRepository.getRepository().getBranch();
    RemoteConfig remoteConfig = EGitUtils.getRemoteByName("origin", testRepositoryClone.getRepository());
    EGitUtils.fetch(remoteConfig, testRepositoryClone.getRepository(), new NullProgressMonitor());
    // when
    RevCommit latestCommit = EGitUtils.getLatestCommit(currentBranch, "origin", testRepositoryClone.getRepository());
    // then
    assertThat(latestCommit, equalTo(commit));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) IFile(org.eclipse.core.resources.IFile) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 58 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project jbosstools-openshift by jbosstools.

the class EGitUtilsTest method canGetSingleRemoteConfig.

@Test
public void canGetSingleRemoteConfig() throws CoreException, MalformedURLException, URISyntaxException, IOException {
    String remoteName = "repo2";
    testRepository.addRemoteTo(remoteName, testRepository2.getRepository());
    List<RemoteConfig> allRemoteConfigs = EGitUtils.getAllRemoteConfigs(testRepository.getRepository());
    assertNotNull(allRemoteConfigs);
    assertEquals(1, allRemoteConfigs.size());
    RemoteConfig repo2Config = EGitUtils.getRemoteConfig(remoteName, allRemoteConfigs);
    assertNotNull(repo2Config);
}
Also used : RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) Test(org.junit.Test)

Example 59 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project jbosstools-openshift by jbosstools.

the class TestRepository method addRemoteTo.

public void addRemoteTo(String remoteName, URIish remoteUri) throws URISyntaxException, IOException {
    StoredConfig config = repository.getConfig();
    RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
    remoteConfig.addURI(remoteUri);
    remoteConfig.update(config);
    config.save();
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 60 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project jbosstools-openshift by jbosstools.

the class EGitUtils method isNonTrackingBranchAhead.

private static boolean isNonTrackingBranchAhead(Repository repo, String remote, IProgressMonitor monitor) throws URISyntaxException, MissingObjectException, IncorrectObjectTypeException, IOException, InvocationTargetException {
    RemoteConfig remoteConfig = new RemoteConfig(repo.getConfig(), remote);
    FetchResult fetchResult = fetch(remoteConfig, repo, monitor);
    Ref ref = fetchResult.getAdvertisedRef(Constants.HEAD);
    if (ref == null) {
        return false;
    }
    Ref currentBranchRef = repo.findRef(repo.getBranch());
    RevWalk walk = new RevWalk(repo);
    RevCommit localCommit = walk.parseCommit(currentBranchRef.getObjectId());
    RevCommit trackingCommit = walk.parseCommit(ref.getObjectId());
    walk.setRevFilter(RevFilter.MERGE_BASE);
    walk.markStart(localCommit);
    walk.markStart(trackingCommit);
    RevCommit mergeBase = walk.next();
    walk.reset();
    walk.setRevFilter(RevFilter.ALL);
    int aheadCount = RevWalkUtils.count(walk, localCommit, mergeBase);
    return aheadCount > 0;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) FetchResult(org.eclipse.jgit.transport.FetchResult) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)63 URISyntaxException (java.net.URISyntaxException)23 StoredConfig (org.eclipse.jgit.lib.StoredConfig)21 URIish (org.eclipse.jgit.transport.URIish)21 IOException (java.io.IOException)16 RefSpec (org.eclipse.jgit.transport.RefSpec)14 Repository (org.eclipse.jgit.lib.Repository)13 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)7 Button (org.eclipse.swt.widgets.Button)6 Composite (org.eclipse.swt.widgets.Composite)6 File (java.io.File)5 Git (org.eclipse.jgit.api.Git)5 Ref (org.eclipse.jgit.lib.Ref)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Label (org.eclipse.swt.widgets.Label)5 List (java.util.List)4 CoreException (org.eclipse.core.runtime.CoreException)4 UIText (org.eclipse.egit.ui.internal.UIText)4