use of org.eclipse.jgit.transport.RemoteConfig in project jbosstools-openshift by jbosstools.
the class EGitUtils method addRemoteTo.
/**
* Adds the given uri of a remote repository to the given repository by the
* given name.
*
* @param remoteName
* the name to use for the remote repository
* @param uri
* the uri of the remote repository
* @param repository
* the repository to add the remote to
* @throws URISyntaxException
* the uRI syntax exception
* @throws MalformedURLException
* the malformed url exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void addRemoteTo(String remoteName, URIish uri, Repository repository) throws URISyntaxException, MalformedURLException, IOException {
StoredConfig config = repository.getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
remoteConfig.addURI(uri);
remoteConfig.update(config);
config.save();
}
use of org.eclipse.jgit.transport.RemoteConfig in project jbosstools-openshift by jbosstools.
the class EGitUtilsTest method canGetFromSeveralRemoteConfig.
@Test
public void canGetFromSeveralRemoteConfig() throws CoreException, MalformedURLException, URISyntaxException, IOException {
String repo2RemoteName = "repo2";
testRepositoryClone.addRemoteTo(repo2RemoteName, testRepository2.getRepository());
List<RemoteConfig> allRemoteConfigs = EGitUtils.getAllRemoteConfigs(testRepositoryClone.getRepository());
assertNotNull(allRemoteConfigs);
// clone already has repo1 as origin
assertEquals(2, allRemoteConfigs.size());
RemoteConfig repo2Config = EGitUtils.getRemoteConfig(repo2RemoteName, allRemoteConfigs);
assertNotNull(repo2Config);
}
use of org.eclipse.jgit.transport.RemoteConfig in project gitea-plugin by jenkinsci.
the class GiteaCreateSCMEvent method isMatch.
/**
* {@inheritDoc}
*/
@Override
public boolean isMatch(@NonNull SCM scm) {
URIish uri;
try {
uri = new URIish(getPayload().getRepository().getHtmlUrl());
} catch (URISyntaxException e) {
return false;
}
String ref = getPayload().getRef();
ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref;
if (scm instanceof GitSCM) {
GitSCM git = (GitSCM) scm;
if (git.getExtensions().get(IgnoreNotifyCommit.class) != null) {
return false;
}
for (RemoteConfig repository : git.getRepositories()) {
for (URIish remoteURL : repository.getURIs()) {
if (GitStatus.looselyMatches(uri, remoteURL)) {
for (BranchSpec branchSpec : git.getBranches()) {
if (branchSpec.getName().contains("$")) {
// If the branchspec is parametrized, always run the polling
return true;
} else {
if (branchSpec.matches(repository.getName() + "/" + ref)) {
return true;
}
}
}
}
}
}
}
return false;
}
use of org.eclipse.jgit.transport.RemoteConfig in project che by eclipse.
the class JGitConnection method remoteUpdate.
@Override
public void remoteUpdate(RemoteUpdateParams params) throws GitException {
String remoteName = params.getName();
if (isNullOrEmpty(remoteName)) {
throw new GitException(ERROR_UPDATE_REMOTE_NAME_MISSING);
}
StoredConfig config = repository.getConfig();
Set<String> remoteNames = config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE);
if (!remoteNames.contains(remoteName)) {
throw new GitException("Remote " + remoteName + " not found. ");
}
RemoteConfig remoteConfig;
try {
remoteConfig = new RemoteConfig(config, remoteName);
} catch (URISyntaxException e) {
throw new GitException(e.getMessage(), e);
}
List<String> branches = params.getBranches();
if (!branches.isEmpty()) {
if (!params.isAddBranches()) {
remoteConfig.setFetchRefSpecs(Collections.emptyList());
remoteConfig.setPushRefSpecs(Collections.emptyList());
} else {
// Replace wildcard refSpec if any.
remoteConfig.removeFetchRefSpec(new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*").setForceUpdate(true));
remoteConfig.removeFetchRefSpec(new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*"));
}
// Add new refSpec.
for (String branch : branches) {
remoteConfig.addFetchRefSpec(new RefSpec(Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remoteName + "/" + branch).setForceUpdate(true));
}
}
// Remove URLs first.
for (String url : params.getRemoveUrl()) {
try {
remoteConfig.removeURI(new URIish(url));
} catch (URISyntaxException e) {
LOG.debug(ERROR_UPDATE_REMOTE_REMOVE_INVALID_URL);
}
}
// Add new URLs.
for (String url : params.getAddUrl()) {
try {
remoteConfig.addURI(new URIish(url));
} catch (URISyntaxException e) {
throw new GitException("Remote url " + url + " is invalid. ");
}
}
// Remove URLs for pushing.
for (String url : params.getRemovePushUrl()) {
try {
remoteConfig.removePushURI(new URIish(url));
} catch (URISyntaxException e) {
LOG.debug(ERROR_UPDATE_REMOTE_REMOVE_INVALID_URL);
}
}
// Add URLs for pushing.
for (String url : params.getAddPushUrl()) {
try {
remoteConfig.addPushURI(new URIish(url));
} catch (URISyntaxException e) {
throw new GitException("Remote push url " + url + " is invalid. ");
}
}
remoteConfig.update(config);
try {
config.save();
} catch (IOException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
use of org.eclipse.jgit.transport.RemoteConfig in project camel by apache.
the class GitProducerTest method remoteListTest.
@Test
public void remoteListTest() throws Exception {
Repository repository = getTestRepository();
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
Git git = new Git(repository);
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
remoteAddCommand.setUri(new URIish(remoteUriTest));
remoteAddCommand.call();
List<RemoteConfig> gitRemoteConfigs = git.remoteList().call();
Object result = template.requestBody("direct:remoteList", "");
assertTrue(result instanceof List);
List<RemoteConfig> remoteConfigs = (List<RemoteConfig>) result;
assertEquals(gitRemoteConfigs.size(), remoteConfigs.size());
assertEquals(gitRemoteConfigs.get(0).getName(), remoteConfigs.get(0).getName());
assertEquals(gitRemoteConfigs.get(0).getURIs(), remoteConfigs.get(0).getURIs());
git.close();
}
Aggregations