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 getRemoteConfig.
/**
* Gets the remote config with the given name from the list of remote
* configs. Returns <code>null</code> if it was not found.
*
* @param remoteName
* the remote name
* @param remoteRepositories
* the remote repositories
* @return the remote config
*
* @see #getAllRemoteConfigs(Repository)
*/
public static RemoteConfig getRemoteConfig(String name, List<RemoteConfig> remoteConfigs) {
Assert.isLegal(name != null);
RemoteConfig remoteConfig = null;
for (RemoteConfig config : remoteConfigs) {
if (name != null && config.getName().equals(name)) {
remoteConfig = config;
break;
}
}
return 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;
}
Aggregations