List of usage examples for org.eclipse.jgit.lib Constants R_HEADS
String R_HEADS
To view the source code for org.eclipse.jgit.lib Constants R_HEADS.
Click Source Link
From source file:org.webcat.core.RepositoryFileLabel.java
License:Open Source License
public String branch() { String branch = fileItem.branch(); if (branch.startsWith(Constants.R_HEADS)) { return branch.substring(Constants.R_HEADS.length()); } else if (branch.startsWith(Constants.R_TAGS)) { return branch.substring(Constants.R_TAGS.length()); } else {// w w w . jav a2 s . c om return branch; } }
From source file:org.zend.sdkcli.internal.commands.GitAddRemoteCommand.java
License:Open Source License
@Override protected boolean doExecute() { Repository repo = null;/*from ww w .j a v a 2 s.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:org.zend.sdkcli.internal.commands.GitCloneProjectCommand.java
License:Open Source License
@Override protected boolean doExecute() { CloneCommand clone = new CloneCommand(); String repo = getRepo();/*from w ww. j a va2 s .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:playRepository.GitBranch.java
License:Apache License
public GitBranch(String name, GitCommit headCommit) { this.name = name; this.shortName = StringUtils.removeStart(name, Constants.R_HEADS); this.headCommit = headCommit; this.user = User.findByEmail(headCommit.getCommitterEmail()); }
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 ww .j a v a 2s . c o m * @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); }
From source file:svnserver.repository.git.GitRepository.java
License:GNU General Public License
public GitRepository(@NotNull LocalContext context, @NotNull Repository repository, @NotNull GitPusher pusher, @NotNull String branch, boolean renameDetection, @NotNull LockManagerFactory lockManagerFactory) throws IOException, SVNException { this.context = context; final SharedContext shared = context.getShared(); shared.getOrCreate(GitSubmodules.class, GitSubmodules::new).register(repository); this.repository = repository; this.binaryCache = shared.getCacheDB().getHashMap("cache.binary"); this.pusher = pusher; this.renameDetection = renameDetection; this.lockManagerFactory = lockManagerFactory; this.gitFilters = GitFilterHelper.createFilters(context); this.svnBranch = LayoutHelper.initRepository(repository, branch).getName(); this.gitBranch = Constants.R_HEADS + branch; final String repositoryId = loadRepositoryId(repository, svnBranch); this.uuid = UUID.nameUUIDFromBytes((repositoryId + "\0" + gitBranch).getBytes(StandardCharsets.UTF_8)) .toString();//from ww w.j ava 2 s. c o m log.info("Repository registered (branch: {})", gitBranch); }
From source file:svnserver.SvnTestServer.java
License:GNU General Public License
private void cleanupBranches(Repository repository) { final List<String> branches = new ArrayList<>(); for (String ref : repository.getAllRefs().keySet()) { if (ref.startsWith(Constants.R_HEADS + TEST_BRANCH_PREFIX)) { branches.add(ref.substring(Constants.R_HEADS.length())); }//from www.j a va2s . com } if (!branches.isEmpty()) { for (String branch : branches) { log.info("Cleanup branch: {}", branch); try { new Git(repository).branchDelete().setBranchNames(branch).setForce(true).call(); } catch (GitAPIException e) { log.error("Cleanup branch: " + branch, e); } } } }
From source file:util.ChkoutCmd.java
License:Eclipse Distribution License
/** * @throws RefAlreadyExistsException//w w w .j a v a 2s .c o m * when trying to create (without force) a branch with a name * that already exists * @throws RefNotFoundException * if the start point or branch can not be found * @throws InvalidRefNameException * if the provided name is <code>null</code> or otherwise * invalid * @throws CheckoutConflictException * if the checkout results in a conflict * @return the newly created branch */ public Ref call() throws GitAPIException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, CheckoutConflictException { checkCallable(); processOptions(); try { if (checkoutAllPaths || !paths.isEmpty()) { checkoutPaths(); status = new CheckoutResult(Status.OK, paths); setCallable(false); return null; } if (createBranch) { Git git = new Git(repo); CreateBranchCommand command = git.branchCreate(); command.setName(name); command.setStartPoint(getStartPoint().name()); if (upstreamMode != null) command.setUpstreamMode(upstreamMode); command.call(); } Ref headRef = repo.getRef(Constants.HEAD); String shortHeadRef = getShortBranchName(headRef); String refLogMessage = "checkout: moving from " + shortHeadRef; //$NON-NLS-1$ ObjectId branch = repo.resolve(name); if (branch == null) throw new RefNotFoundException(MessageFormat.format(JGitText.get().refNotResolved, name)); RevWalk revWalk = new RevWalk(repo); AnyObjectId headId = headRef.getObjectId(); RevCommit headCommit = headId == null ? null : revWalk.parseCommit(headId); RevCommit newCommit = revWalk.parseCommit(branch); RevTree headTree = headCommit == null ? null : headCommit.getTree(); DirCacheCheckout dco; DirCache dc = repo.lockDirCache(); try { dco = new DirCacheCheckout(repo, headTree, dc, newCommit.getTree()); dco.setFailOnConflict(false); try { dco.checkout(); } catch (org.eclipse.jgit.errors.CheckoutConflictException e) { status = new CheckoutResult(Status.CONFLICTS, dco.getConflicts()); throw new CheckoutConflictException(dco.getConflicts(), e); } } finally { dc.unlock(); } Ref ref = repo.getRef(name); if (ref != null && !ref.getName().startsWith(Constants.R_HEADS)) ref = null; String toName = Repository.shortenRefName(name); RefUpdate refUpdate = repo.updateRef(Constants.HEAD, ref == null); refUpdate.setForceUpdate(force); refUpdate.setRefLogMessage(refLogMessage + " to " + toName, false); //$NON-NLS-1$ Result updateResult; if (ref != null) updateResult = refUpdate.link(ref.getName()); else { refUpdate.setNewObjectId(newCommit); updateResult = refUpdate.forceUpdate(); } setCallable(false); boolean ok = false; switch (updateResult) { case NEW: ok = true; break; case NO_CHANGE: case FAST_FORWARD: case FORCED: ok = true; break; default: break; } if (!ok) throw new JGitInternalException( MessageFormat.format(JGitText.get().checkoutUnexpectedResult, updateResult.name())); if (!dco.getToBeDeleted().isEmpty()) { status = new CheckoutResult(Status.NONDELETED, dco.getToBeDeleted()); } else status = new CheckoutResult(new ArrayList<String>(dco.getUpdated().keySet()), dco.getRemoved()); return ref; } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); } finally { if (status == null) status = CheckoutResult.ERROR_RESULT; } }
From source file:util.ChkoutCmd.java
License:Eclipse Distribution License
private void processOptions() throws InvalidRefNameException { if ((!checkoutAllPaths && paths.isEmpty()) && (name == null || !Repository.isValidRefName(Constants.R_HEADS + name))) throw new InvalidRefNameException( MessageFormat.format(JGitText.get().branchNameInvalid, name == null ? "<null>" : name)); //$NON-NLS-1$ }