List of usage examples for org.eclipse.jgit.lib Constants R_REMOTES
String R_REMOTES
To view the source code for org.eclipse.jgit.lib Constants R_REMOTES.
Click Source Link
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 . ja v a 2s. 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.internal.commands.GitAddRemoteCommand.java
License:Open Source License
@Override protected boolean doExecute() { Repository repo = null;// ww w . j a v a2s. c o m try { File gitDir = getProject(); if (!gitDir.exists()) { getLogger().error("Git repository is not available in provided location"); return false; } repo = FileRepositoryBuilder.create(gitDir); } catch (IOException e) { getLogger().error(e); return false; } if (repo != null) { String repoName = getReposiotryName(getRepo(), repo); if (repoName == null) { getLogger().error("Invalid repository URL :" + getRepo()); return false; } try { RemoteConfig config = new RemoteConfig(repo.getConfig(), repoName); config.addURI(new URIish(getRepo())); String dst = Constants.R_REMOTES + config.getName(); RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*", dst + "/*"); //$NON-NLS-1$ //$NON-NLS-2$ config.addFetchRefSpec(refSpec); config.update(repo.getConfig()); repo.getConfig().save(); getLogger().info( MessageFormat.format("New remote called \"{0}\" was added successfully", config.getName())); } catch (URISyntaxException e) { getLogger().error("Invalid repository URL :" + getRepo()); return false; } catch (IOException e) { getLogger().error(e); return false; } } return true; }
From source file:playRepository.GitRepository.java
License:Apache License
/** * Check if the given ref name is under a well-known namespace. * * @param refName/*from w w w.j a v a 2 s.com*/ * @return true if the refName starts with "refs/heads/", "refs/tags/" or * "refs/remotes/" */ private static boolean isWellKnownRef(String refName) { return refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_TAGS) || refName.startsWith(Constants.R_REMOTES); }