List of usage examples for org.eclipse.jgit.lib Constants DEFAULT_REMOTE_NAME
String DEFAULT_REMOTE_NAME
To view the source code for org.eclipse.jgit.lib Constants DEFAULT_REMOTE_NAME.
Click Source Link
From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java
License:Open Source License
/** * Returns the name of the remote repository for the given branch. If * there's no current branch or no remote configured to it, the default * remote is returned ("origin").//w w w .jav a 2 s . c o m * * @param branch * the branch * @param repository * the repository * @return the remote name */ private static String getRemoteName(String branch, Repository repository) { String remoteName = null; if (ObjectId.isId(branch)) { remoteName = Constants.DEFAULT_REMOTE_NAME; } else { remoteName = repository.getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_REMOTE_SECTION); if (remoteName == null) { remoteName = Constants.DEFAULT_REMOTE_NAME; } } return remoteName; }
From source file:org.jboss.tools.openshift.egit.internal.test.EGitUtilsTest.java
License:Open Source License
@Test public void shouldReturnThatCloneIsAhead() throws Exception { assertFalse(EGitUtils.isAhead(testRepositoryClone.getRepository(), Constants.DEFAULT_REMOTE_NAME, null)); String fileName = "c.txt"; String fileContent = "adietish@redhat.com"; File file = testRepositoryClone.createFile(fileName, fileContent); testRepositoryClone.addAndCommit(file, "adding a file"); assertTrue(EGitUtils.isAhead(testRepositoryClone.getRepository(), Constants.DEFAULT_REMOTE_NAME, null)); }
From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java
License:Open Source License
public TestRepository cloneRepository(File path) throws URISyntaxException, InvocationTargetException, InterruptedException, IOException { URIish uri = new URIish("file:///" + repository.getDirectory().toString()); CloneOperation clop = new CloneOperation(uri, true, null, path, Constants.R_HEADS + Constants.MASTER, Constants.DEFAULT_REMOTE_NAME, 0); clop.run(null);/*from w ww. ja v a 2 s . co m*/ RepositoryCache repositoryCache = Activator.getDefault().getRepositoryCache(); Repository clonedRepository = repositoryCache.lookupRepository(new File(path, Constants.DOT_GIT)); return new TestRepository(clonedRepository); }
From source file:org.jboss.tools.openshift.express.internal.ui.wizard.application.importoperation.AbstractImportApplicationOperation.java
License:Open Source License
/** * Adds the given remote repo (at the given git uri) with the given name to * the given repository. The remote is not added if the remoteName to use is * "origin".//from w ww. ja v a 2 s. c om * * @param remoteName * the name to store the remote repo with * @param gitUri * the git uri at which the remote repo is reachable * @param repository * the local repo to add the remote to * @throws MalformedURLException * @throws URISyntaxException * @throws IOException */ protected void addRemoteRepo(String remoteName, String gitUri, Repository repository) throws MalformedURLException, URISyntaxException, IOException { if (remoteName != Constants.DEFAULT_REMOTE_NAME) { EGitUtils.addRemoteTo(remoteName, gitUri, repository); } }
From source file:org.jboss.tools.openshift.internal.ui.wizard.importapp.ImportProjectOperation.java
License:Open Source License
/** * Clones the repository of the selected OpenShift application to the user * provided path.//from ww w. j a v a2s. c o m * * @param application * the application to clone * @param remoteName * the name of the remote repo to clone * @param destination * the destination to clone to * @param gitRef * the git reference to check-out * @param addToRepoView * if true, the clone repo will get added to the (egit) * repositories view * @param monitor * the monitor to report progress to * * @return the location of the cloned repository * @throws OpenShiftException * @throws InvocationTargetException * @throws InterruptedException * @throws URISyntaxException * * @see AbstractImportApplicationOperation#getApplication() * @see #getCloneDestination() */ protected File cloneRepository(String gitUrl, File destination, String gitRef, IProgressMonitor monitor) throws OpenShiftException, InvocationTargetException, InterruptedException, URISyntaxException { monitor.subTask(NLS.bind("Cloning {0}...", gitUrl)); EGitUIUtils.ensureEgitUIIsStarted(); EGitUtils.cloneRepository(gitUrl, Constants.DEFAULT_REMOTE_NAME, gitRef, destination, EGitUIUtils.ADD_TO_REPOVIEW_TASK, monitor); return destination; }
From source file:org.z2env.impl.helper.GitTools.java
License:Apache License
/** * Switches to the given target branch in the given repository. If such a local branch exists the method performs a checkout on this branch. * Otherwise the branch name can be a remote branch in which case a local tracking branch is created. * @param repo the repository//from ww w. j av a 2 s . co m * @param targetBranch a local or remote branch name. * @throws IOException if something went wrong */ public static void switchBranch(Repository repo, String targetBranch) throws IOException { if (hasLocalBranch(repo, targetBranch)) { if (!targetBranch.equals(repo.getBranch())) { try { new Git(repo).checkout().setName(targetBranch).call(); } catch (Exception e) { throw new IOException("Failed to switch to branch '" + targetBranch + "' inside " + repo + "!"); } } } else if (hasRemoteBranch(repo, targetBranch)) { // create tracking branch try { new Git(repo).branchCreate().setName(targetBranch).setUpstreamMode(SetupUpstreamMode.TRACK) .setStartPoint(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + targetBranch) .call(); } catch (Exception e) { throw new IOException( "Failed to create tracking branch '" + targetBranch + "' inside " + repo + "!"); } // switch to new branch try { new Git(repo).checkout().setName(targetBranch).call(); } catch (Exception e) { throw new IOException("Failed to switch to branch '" + targetBranch + "' inside " + repo + "!"); } } else { throw new IOException("No such branch '" + targetBranch + "' inside " + repo + "!"); } }
From source file:org.zend.sdkcli.GitHelper.java
License:Open Source License
/** * Returns remote valued based on provided git repository URL. * //w w w .j a va 2 s . c o m * @param url * @return {@link GitHelper#ZEND_CLOUD_REMOTE} if it is phpCloud repository; * otherwise return {@link Constants#DEFAULT_REMOTE_NAME} */ public static String getRemote(String url) { try { URIish uri = new URIish(url); if (TargetsManager.isPhpcloud(uri.getHost())) { return ZEND_CLOUD_REMOTE; } } catch (URISyntaxException e) { // return default Constants.DEFAULT_REMOTE_NAME } return Constants.DEFAULT_REMOTE_NAME; }
From source file:org.zend.sdkcli.internal.commands.GitCloneProjectCommand.java
License:Open Source License
@Override protected boolean doExecute() { CloneCommand clone = new CloneCommand(); String repo = getRepo();/*from w w w .j a va2s. c o m*/ clone.setURI(repo); clone.setRemote(GitHelper.getRemote(repo)); File dir = null; try { dir = getDirectory(repo); if (dir.exists()) { File[] children = dir.listFiles(); if (children != null && children.length > 0) { getLogger().error(MessageFormat.format( "Destination folder {0} already exists and is not an empty directory", dir.getName())); return false; } } clone.setDirectory(dir); } catch (URISyntaxException e) { getLogger().error(e); return false; } clone.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))); if (!askUsername()) { getLogger().info(MessageFormat.format("Cloning into {0}...", dir.getName())); } String branch = getBranch(); if (branch != null) { clone.setBranch(Constants.R_HEADS + branch); } try { URIish uri = new URIish(repo); if (GITHUB_HOST.equals(uri.getHost()) && "git".equals(uri.getUser())) { if (!prepareSSHFactory()) { return false; } } else { CredentialsProvider credentials = getCredentials(repo); if (credentials != null) { clone.setCredentialsProvider(credentials); } } clone.call(); } catch (JGitInternalException e) { delete(dir); getLogger().error(e); return false; } catch (URISyntaxException e) { delete(dir); getLogger().error(e); return false; } catch (InvalidRemoteException e) { delete(dir); getLogger().error(e); return false; } catch (TransportException e) { delete(dir); String repoUrl = getRepo(); if (repoUrl != null && repoUrl.startsWith("https")) { if (e.getMessage().endsWith("not authorized")) { setAskUsername(true); return doExecute(); } } getLogger().error(e); return false; } catch (GitAPIException e) { delete(dir); getLogger().error(e); return false; } updateProject(dir); if (GitHelper.ZEND_CLOUD_REMOTE.equals(GitHelper.getRemote(repo))) { getLogger().info("The remote name used to keep track of the phpCloud repository is: " + GitHelper.ZEND_CLOUD_REMOTE); } else { getLogger().info("The remote name used to keep track of the cloned repository is: " + Constants.DEFAULT_REMOTE_NAME); } return true; }
From source file:to.sauerkraut.krautadmin.core.Toolkit.java
License:Open Source License
public static boolean updateFromGit(final File repositoryDirectory, final URI repositoryUri) throws Exception { final String unexpectedExceptionText = "incremental plugin-update from git failed"; final String upstream = "refs/remotes/origin/master"; boolean hasUpdated = false; Git gitRepo = null;/*from www. jav a 2s .c om*/ try { gitRepo = Git.open(repositoryDirectory); // first reset local changes gitRepo.reset().setMode(ResetCommand.ResetType.HARD).call(); LOG.info("starting incremental plugin-update from git..."); gitRepo.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call(); final RebaseResult rebaseResult = gitRepo.rebase().setStrategy(MergeStrategy.THEIRS) .setUpstream(upstream).setUpstreamName(upstream).call(); final Status rebaseStatus = rebaseResult.getStatus(); if (rebaseStatus.isSuccessful()) { if (!(Status.UP_TO_DATE.equals(rebaseStatus))) { hasUpdated = true; } } else { throw new WTFException(unexpectedExceptionText); } if (hasUpdated) { LOG.info("incremental plugin-update from git successful"); } else { LOG.info("plugin-files are up-to-date"); } } finally { try { if (gitRepo != null) { gitRepo.close(); } } catch (Exception closex) { LOG.debug("closing git repo failed"); } } return hasUpdated; }