List of usage examples for org.eclipse.jgit.transport RemoteConfig addURI
public boolean addURI(URIish toAdd)
From source file:com.google.gct.idea.appengine.synchronization.SampleSyncTaskTest.java
License:Apache License
@Override public void setUp() throws Exception { super.setUp(); mockAndroidRepoPath = System.getProperty("java.io.tmpdir") + "/android/mockAndroidRepo"; String mockGitHubRepoGitPath = db.getDirectory().getPath(); mockGitHubRepoPath = mockGitHubRepoGitPath.substring(0, mockGitHubRepoGitPath.lastIndexOf('/')); // Configure the mock github repo StoredConfig targetConfig = db.getConfig(); targetConfig.setString("branch", "master", "remote", "origin"); targetConfig.setString("branch", "master", "merge", "refs/heads/master"); RemoteConfig config = new RemoteConfig(targetConfig, "origin"); config.addURI(new URIish(mockGitHubRepoGitPath)); config.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); config.update(targetConfig);//from w w w .jav a 2 s. c o m targetConfig.save(); mockGitHubRepo = new Git(db); // commit something writeTrashFile("Test.txt", "Hello world"); mockGitHubRepo.add().addFilepattern("Test.txt").call(); mockGitHubRepo.commit().setMessage("Initial commit").call(); mockGitHubRepo.tag().setName("tag-initial").setMessage("Tag initial").call(); }
From source file:com.netbeetle.reboot.git.CachedRepository.java
License:Apache License
public void init() throws IOException, URISyntaxException { if (exists()) { return;/* w ww . ja v a 2 s . co m*/ } repository.create(true); StoredConfig config = repository.getConfig(); RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); remoteConfig.addURI(new URIish(uri)); remoteConfig.setMirror(true); remoteConfig.addFetchRefSpec(new RefSpec().setForceUpdate(true).setSourceDestination("refs/*", "refs/*")); remoteConfig.update(config); config.save(); }
From source file:com.rimerosolutions.ant.git.tasks.FetchTask.java
License:Apache License
@Override public void doExecute() { try {//from w w w . j a v a 2 s. c o m StoredConfig config = git.getRepository().getConfig(); List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config); if (remoteConfigs.isEmpty()) { URIish uri = new URIish(getUri()); RemoteConfig remoteConfig = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME); remoteConfig.addURI(uri); remoteConfig.addFetchRefSpec(new RefSpec("+" + Constants.R_HEADS + "*:" + Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/*")); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_REMOTE, Constants.DEFAULT_REMOTE_NAME); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + Constants.MASTER); remoteConfig.update(config); config.save(); } List<RefSpec> specs = new ArrayList<RefSpec>(3); specs.add(new RefSpec( "+" + Constants.R_HEADS + "*:" + Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/*")); specs.add(new RefSpec("+" + Constants.R_NOTES + "*:" + Constants.R_NOTES + "*")); specs.add(new RefSpec("+" + Constants.R_TAGS + "*:" + Constants.R_TAGS + "*")); FetchCommand fetchCommand = git.fetch().setDryRun(dryRun).setThin(thinPack).setRemote(getUri()) .setRefSpecs(specs).setRemoveDeletedRefs(removeDeletedRefs); setupCredentials(fetchCommand); if (getProgressMonitor() != null) { fetchCommand.setProgressMonitor(getProgressMonitor()); } FetchResult fetchResult = fetchCommand.call(); GitTaskUtils.validateTrackingRefUpdates(FETCH_FAILED_MESSAGE, fetchResult.getTrackingRefUpdates()); log(fetchResult.getMessages()); } catch (URISyntaxException e) { throw new GitBuildException("Invalid URI syntax: " + e.getMessage(), e); } catch (IOException e) { throw new GitBuildException("Could not save or get repository configuration: " + e.getMessage(), e); } catch (InvalidRemoteException e) { throw new GitBuildException("Invalid remote URI: " + e.getMessage(), e); } catch (TransportException e) { throw new GitBuildException("Communication error: " + e.getMessage(), e); } catch (GitAPIException e) { throw new GitBuildException("Unexpected exception: " + e.getMessage(), e); } }
From source file:com.rimerosolutions.ant.git.tasks.PushTask.java
License:Apache License
@Override protected void doExecute() { try {// ww w .jav a 2 s . c o m StoredConfig config = git.getRepository().getConfig(); List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config); if (remoteConfigs.isEmpty()) { URIish uri = new URIish(getUri()); RemoteConfig remoteConfig = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME); remoteConfig.addURI(uri); remoteConfig.addFetchRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.addPushRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.update(config); config.save(); } String currentBranch = git.getRepository().getBranch(); List<RefSpec> specs = Arrays.asList(new RefSpec(currentBranch + ":" + currentBranch)); if (deleteRemoteBranch != null) { specs = Arrays.asList(new RefSpec(":" + Constants.R_HEADS + deleteRemoteBranch)); } PushCommand pushCommand = git.push().setPushAll().setRefSpecs(specs).setDryRun(false); if (getUri() != null) { pushCommand.setRemote(getUri()); } setupCredentials(pushCommand); if (includeTags) { pushCommand.setPushTags(); } if (getProgressMonitor() != null) { pushCommand.setProgressMonitor(getProgressMonitor()); } Iterable<PushResult> pushResults = pushCommand.setForce(true).call(); for (PushResult pushResult : pushResults) { log(pushResult.getMessages()); GitTaskUtils.validateRemoteRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getRemoteUpdates()); GitTaskUtils.validateTrackingRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getTrackingRefUpdates()); } } catch (Exception e) { if (pushFailedProperty != null) { getProject().setProperty(pushFailedProperty, e.getMessage()); } throw new GitBuildException(PUSH_FAILED_MESSAGE, e); } }
From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java
License:Open Source License
@Secured({ Role.Admin }) @Override// w ww. j av a 2s . c o m public void addExternalRepository(String url) { try { String repoName = getRepoDirNameFromExternalUrl(url); File dir = new File(repositoryProvider.getTenantMirroredBaseDir(), repoName); Git git = Git.init().setBare(true).setDirectory(dir).call(); RemoteConfig config = new RemoteConfig(git.getRepository().getConfig(), Constants.DEFAULT_REMOTE_NAME); config.addURI(new URIish(url)); config.update(git.getRepository().getConfig()); git.getRepository().getConfig().save(); } catch (JGitInternalException e) { throw new RuntimeException(e); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (GitAPIException e) { throw new RuntimeException(e); } }
From source file:edu.wustl.lookingglass.community.CommunityRepository.java
License:Open Source License
private void addRemote(String newName, URL newURL) throws IOException, URISyntaxException { assert this.remoteName != null; assert this.remoteURL != null; boolean remoteExists = false; StoredConfig config = this.git.getRepository().getConfig(); Set<String> remotes = config.getSubsections("remote"); for (String oldName : remotes) { String oldURL = config.getString("remote", oldName, "url"); if (newName.equals(oldName)) { remoteExists = true;//from w w w . j av a2s . com if (newURL.toExternalForm().equals(oldURL)) { break; } else { Logger.warning("inconsistent remote url " + oldName + " : " + oldURL); config.setString("remote", oldName, "url", newURL.toExternalForm()); config.save(); break; } } } if (!remoteExists) { RemoteConfig remoteConfig = new RemoteConfig(config, this.remoteName); remoteConfig.addURI(new URIish(this.remoteURL)); remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + this.remoteName + "/*")); remoteConfig.update(config); config.save(); } }
From source file:eu.cloud4soa.cli.roo.addon.commands.GitManager.java
License:Apache License
public void setConfig() throws URISyntaxException, IOException, GitAPIException { StoredConfig config = gitRepository.getConfig(); if (config.getString("remote", repoName, "url") == null || config.getString("remote", repoName, "url") != gitProxyUrl) { config.unset("remote", repoName, "url"); RemoteConfig remoteConfig = new RemoteConfig(config, repoName); //cloud@94.75.243.141/proxyname.git //proxy<userid><applicationid>.git? // String gitUrl = gitUser+"@"+gitProxyUrl+"/proxy"+this.userId+this.applicationId+".git"; URIish uri = new URIish(gitProxyUrl); remoteConfig.addURI(uri); config.unset("remote", repoName, "fetch"); RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/" + repoName + "/*"); remoteConfig.addFetchRefSpec(spec); remoteConfig.update(config);//from w w w .j a va 2 s . c om } if (config.getString("branch", "master", "remote") == null || config.getString("branch", "master", "remote") != repoName) { config.unset("branch", "master", "remote"); config.setString("branch", "master", "remote", repoName); } if (config.getString("branch", "master", "merge") == null || config.getString("branch", "master", "merge") != "refs/heads/master") { config.unset("branch", "master", "merge"); config.setString("branch", "master", "merge", "refs/heads/master"); } config.save(); }
From source file:hudson.plugins.git.GitSCMUnitTest.java
License:Open Source License
@Test public void testGetRepositoryByName() throws Exception { RemoteConfig expected = new RemoteConfig(new Config(), "origin"); expected.addURI(new URIish(gitDir)); assertRemoteConfigEquals(gitSCM.getRepositoryByName("origin"), expected); }
From source file:hudson.plugins.git.GitSCMUnitTest.java
License:Open Source License
@Test public void testGetRepositories() throws Exception { List<RemoteConfig> expectedRemoteConfigList = new ArrayList<>(); RemoteConfig remoteConfig = new RemoteConfig(new Config(), "origin"); remoteConfig.addURI(new URIish(gitDir)); expectedRemoteConfigList.add(remoteConfig); assertRemoteConfigListEquals(gitSCM.getRepositories(), expectedRemoteConfigList); }
From source file:net.erdfelt.android.sdkfido.git.internal.GitCloneCommand.java
License:Apache License
/** * Add a 'remote' configuration./*from www .ja va 2 s . c om*/ * * @param remoteName * the name of the remote * @param uri * the uri to the remote * @throws URISyntaxException * if unable to process uri * @throws IOException * if unable to add remote config */ private void addRemoteConfig(String remoteName, URIish uri) throws URISyntaxException, IOException { RemoteConfig rc = new RemoteConfig(repo.getConfig(), remoteName); rc.addURI(uri); String dest = Constants.R_HEADS + "*:" + Constants.R_REMOTES + remoteName + "/*"; RefSpec refspec = new RefSpec(dest); refspec.setForceUpdate(true); rc.addFetchRefSpec(refspec); rc.update(repo.getConfig()); repo.getConfig().save(); }