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())));
}
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));
}
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);
}
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();
}
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;
}
Aggregations