List of usage examples for org.eclipse.jgit.transport RemoteConfig addFetchRefSpec
public boolean addFetchRefSpec(RefSpec s)
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.j a v a 2 s .co 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;/*ww w. j a va2 s . c om*/ } 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 {// ww w. j a va 2 s.com 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 {/* w w w . jav a2s.co 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: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 ww .jav a 2s .co m 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);//from w w w. j a va2 s .com config.unset("remote", repoName, "fetch"); RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/" + repoName + "/*"); remoteConfig.addFetchRefSpec(spec); remoteConfig.update(config); } 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:net.erdfelt.android.sdkfido.git.internal.GitCloneCommand.java
License:Apache License
/** * Add a 'remote' configuration./*from w w w . j a v a 2s . 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(); }
From source file:org.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
protected final void doClone(final String remoteUrl, final String remoteName, final String branch) throws GitWrapException { final FileRepository repository = getRepository(); final String branchRef = Constants.R_HEADS + (branch == null ? Constants.MASTER : branch); try {//from ww w. j a v a2 s.com final RefUpdate head = repository.updateRef(Constants.HEAD); head.disableRefLog(); head.link(branchRef); final RemoteConfig remoteConfig = new RemoteConfig(repository.getConfig(), remoteName); remoteConfig.addURI(new URIish(remoteUrl)); final String remoteRef = Constants.R_REMOTES + remoteName; RefSpec spec = new RefSpec(); spec = spec.setForceUpdate(true); spec = spec.setSourceDestination(Constants.R_HEADS + "*", remoteRef + "/*"); remoteConfig.addFetchRefSpec(spec); remoteConfig.update(repository.getConfig()); repository.getConfig().setString("branch", branch, "remote", remoteName); repository.getConfig().setString("branch", branch, "merge", branchRef); repository.getConfig().save(); fetch(remoteName); postClone(remoteUrl, branchRef); } catch (final IOException e) { throw new GitWrapException("Failed to clone from: %s. Reason: %s", e, remoteUrl, e.getMessage()); } catch (final URISyntaxException e) { throw new GitWrapException("Failed to clone from: %s. Reason: %s", e, remoteUrl, e.getMessage()); } }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public void remoteAdd(RemoteAddRequest request) throws GitException { String remoteName = request.getName(); if (isNullOrEmpty(remoteName)) { throw new IllegalArgumentException(ERROR_ADD_REMOTE_NAME_MISSING); }/*from w w w.ja v a 2 s. c o m*/ StoredConfig config = repository.getConfig(); Set<String> remoteNames = config.getSubsections("remote"); if (remoteNames.contains(remoteName)) { throw new IllegalArgumentException(String.format(ERROR_REMOTE_NAME_ALREADY_EXISTS, remoteName)); } String url = request.getUrl(); if (isNullOrEmpty(url)) { throw new IllegalArgumentException(ERROR_REMOTE_URL_MISSING); } RemoteConfig remoteConfig; try { remoteConfig = new RemoteConfig(config, remoteName); } catch (URISyntaxException exception) { // Not happen since it is newly created remote. throw new GitException(exception.getMessage(), exception); } try { remoteConfig.addURI(new URIish(url)); } catch (URISyntaxException exception) { throw new IllegalArgumentException("Remote url " + url + " is invalid. "); } List<String> branches = request.getBranches(); if (branches.isEmpty()) { remoteConfig.addFetchRefSpec( new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*") .setForceUpdate(true)); } else { for (String branch : branches) { remoteConfig.addFetchRefSpec(new RefSpec( Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remoteName + "/" + branch) .setForceUpdate(true)); } } remoteConfig.update(config); try { config.save(); } catch (IOException exception) { throw new GitException(exception.getMessage(), exception); } }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public void remoteUpdate(RemoteUpdateRequest request) throws GitException { String remoteName = request.getName(); if (isNullOrEmpty(remoteName)) { throw new IllegalArgumentException(ERROR_UPDATE_REMOTE_NAME_MISSING); }//from www . j a va 2 s .c o m StoredConfig config = repository.getConfig(); Set<String> remoteNames = config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE); if (!remoteNames.contains(remoteName)) { throw new IllegalArgumentException("Remote " + remoteName + " not found. "); } RemoteConfig remoteConfig; try { remoteConfig = new RemoteConfig(config, remoteName); } catch (URISyntaxException e) { throw new GitException(e.getMessage(), e); } List<String> branches = request.getBranches(); if (!branches.isEmpty()) { if (!request.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 : request.getRemoveUrl()) { try { remoteConfig.removeURI(new URIish(url)); } catch (URISyntaxException e) { LOG.debug(ERROR_REMOVING_INVALID_URL); } } // Add new URLs. for (String url : request.getAddUrl()) { try { remoteConfig.addURI(new URIish(url)); } catch (URISyntaxException e) { throw new IllegalArgumentException("Remote url " + url + " is invalid. "); } } // Remove URLs for pushing. for (String url : request.getRemovePushUrl()) { try { remoteConfig.removePushURI(new URIish(url)); } catch (URISyntaxException e) { LOG.debug(ERROR_REMOVING_INVALID_URL); } } // Add URLs for pushing. for (String url : request.getAddPushUrl()) { try { remoteConfig.addPushURI(new URIish(url)); } catch (URISyntaxException e) { throw new IllegalArgumentException("Remote push url " + url + " is invalid. "); } } remoteConfig.update(config); try { config.save(); } catch (IOException exception) { throw new GitException(exception.getMessage(), exception); } }