List of usage examples for org.eclipse.jgit.lib Constants HEAD
String HEAD
To view the source code for org.eclipse.jgit.lib Constants HEAD.
Click Source Link
From source file:org.walkmod.git.constraints.JavaConstraintProvider.java
License:Open Source License
public JavaConstraintProvider() throws IOException { File file = new File(".git").getCanonicalFile(); if (file.exists()) { Git git = Git.open(file.getAbsoluteFile().getParentFile().getCanonicalFile()); formatter = new WalkmodDiffFormatter(git.getRepository()); AbstractTreeIterator commitTreeIterator = prepareTreeParser(git.getRepository(), Constants.HEAD); FileTreeIterator workTreeIterator = new FileTreeIterator(git.getRepository()); List<DiffEntry> diffEntries = formatter.scan(commitTreeIterator, workTreeIterator); for (DiffEntry entry : diffEntries) { File aux = new File(entry.getNewPath()).getCanonicalFile(); this.diffEntries.put(aux.getPath(), entry); }//from w w w.j a va2s.c o m formatter.close(); } }
From source file:org.webcat.core.git.GitCloner.java
License:Open Source License
private void doCheckout(Repository repository, Ref branch) throws IOException { if (!Constants.HEAD.equals(branch.getName())) { RefUpdate refUpdate = repository.updateRef(Constants.HEAD); refUpdate.disableRefLog();/*from w w w . j ava2 s. co m*/ refUpdate.link(branch.getName()); } RevCommit commit = parseCommit(repository, branch); RefUpdate refUpdate = repository.updateRef(Constants.HEAD); refUpdate.setNewObjectId(commit); refUpdate.forceUpdate(); DirCache dirCache = repository.lockDirCache(); DirCacheCheckout checkout = new DirCacheCheckout(repository, dirCache, commit.getTree()); checkout.checkout(); }
From source file:org.webcat.core.git.GitCloner.java
License:Open Source License
private Ref guessHead(FetchResult result) { Ref idHEAD = result.getAdvertisedRef(Constants.HEAD); List<Ref> availableRefs = new ArrayList<Ref>(); Ref head = null;// ww w. j a va2 s. c om for (Ref ref : result.getAdvertisedRefs()) { String name = ref.getName(); if (!name.startsWith(Constants.R_HEADS)) { continue; } availableRefs.add(ref); if (idHEAD == null || head != null) { continue; } if (ref.getObjectId().equals(idHEAD.getObjectId())) { head = ref; } } Collections.sort(availableRefs, RefComparator.INSTANCE); if (idHEAD != null && head == null) { head = idHEAD; } return head; }
From source file:org.webcat.core.git.http.InfoRefsRequestHandler.java
License:Open Source License
/** * Looks up the requested repository and appends its info/refs to the * response./*w w w . ja v a 2 s. c om*/ * * @param request the request * @param response the response * @throws Exception if an error occurs */ public void handleRequest(WORequest request, WOResponse response) throws Exception { response.setHeader("text/plain", "Content-Type"); NSMutableDataOutputStream outputStream = new NSMutableDataOutputStream(); Repository repo = RepositoryRequestUtils.repositoryFromRequest(request); //RevWalk walk = new RevWalk(repo); //try //{ //final RevFlag ADVERTISED = walk.newFlag("ADVERTISED"); final OutputStreamWriter out = new OutputStreamWriter(outputStream, Constants.CHARSET); final RefAdvertiser adv = new RefAdvertiser() { protected void writeOne(CharSequence line) throws IOException { out.append(line.toString().replace(' ', '\t')); } protected void end() { // Do nothing. } }; adv.init(repo); //adv.init(walk, ADVERTISED); adv.setDerefTags(true); Map<String, Ref> refs = repo.getAllRefs(); refs.remove(Constants.HEAD); adv.send(refs); //} //finally //{ //walk.release(); //} outputStream.close(); response.appendContentData(outputStream.data()); }
From source file:pl.nask.hsn2.framework.workflow.repository.GitWorkflowRepository.java
License:Open Source License
@Override public List<String> listWorkflowNames() throws WorkflowRepoException { File[] files = repoDir.listFiles(filenameFilter); List<String> l = new ArrayList<String>(files.length); try {/*from w w w. j a v a2 s.c om*/ ObjectId revId = repo.resolve(Constants.HEAD); if (revId == null) { throw new WorkflowRepoException( "GIT repository does not exists or it does not contains any workflow files."); } TreeWalk tree = new TreeWalk(repo); tree.addTree(new RevWalk(repo).parseTree(revId)); while (tree.next()) { l.add(tree.getNameString()); } } catch (IOException ex) { throw new WorkflowRepoException("Error during listing GIT repository.", ex); } return l; }
From source file:pl.project13.maven.git.GitCommitIdMojo.java
License:Open Source License
void loadGitData(@NotNull Properties properties) throws IOException, MojoExecutionException { Repository git = getGitRepository(); ObjectReader objectReader = git.newObjectReader(); // git.user.name String userName = git.getConfig().getString("user", null, "name"); put(properties, BUILD_AUTHOR_NAME, userName); // git.user.email String userEmail = git.getConfig().getString("user", null, "email"); put(properties, BUILD_AUTHOR_EMAIL, userEmail); // more details parsed out bellow Ref HEAD = git.getRef(Constants.HEAD); if (HEAD == null) { throw new MojoExecutionException( "Could not get HEAD Ref, are you sure you've set the dotGitDirectory property of this plugin to a valid path?"); }/* ww w . j a v a2 s . c o m*/ RevWalk revWalk = new RevWalk(git); RevCommit headCommit = revWalk.parseCommit(HEAD.getObjectId()); revWalk.markStart(headCommit); try { // git.branch String branch = determineBranchName(git, System.getenv()); put(properties, BRANCH, branch); // git.commit.id.describe maybePutGitDescribe(properties, git); // git.commit.id put(properties, COMMIT_ID, headCommit.getName()); // git.commit.id.abbrev putAbbrevCommitId(objectReader, properties, headCommit, abbrevLength); // git.commit.author.name String commitAuthor = headCommit.getAuthorIdent().getName(); put(properties, COMMIT_AUTHOR_NAME, commitAuthor); // git.commit.author.email String commitEmail = headCommit.getAuthorIdent().getEmailAddress(); put(properties, COMMIT_AUTHOR_EMAIL, commitEmail); // git commit.message.full String fullMessage = headCommit.getFullMessage(); put(properties, COMMIT_MESSAGE_FULL, fullMessage); // git commit.message.short String shortMessage = headCommit.getShortMessage(); put(properties, COMMIT_MESSAGE_SHORT, shortMessage); long timeSinceEpoch = headCommit.getCommitTime(); Date commitDate = new Date(timeSinceEpoch * 1000); // git is "by sec" and java is "by ms" SimpleDateFormat smf = new SimpleDateFormat(dateFormat); put(properties, COMMIT_TIME, smf.format(commitDate)); // git remote.origin.url String remoteOriginUrl = git.getConfig().getString("remote", "origin", "url"); put(properties, REMOTE_ORIGIN_URL, remoteOriginUrl); } finally { revWalk.dispose(); } }
From source file:playRepository.GitRepository.java
License:Apache License
/** * Returns the path extended so that empty intermediate folders * are skipped.//from w w w .j av a 2s .co m * * @see <a href="https://github.com/blog/1877-folder-jumping">Folder Jumping on GitHub blog</a> */ public String extendPath(String basePath, String path) { try { ObjectId objectId = repository.resolve(Constants.HEAD); RevWalk revWalk = new RevWalk(repository); RevTree revTree = revWalk.parseTree(objectId); while (true) { String fullPath; if (StringUtils.isEmpty(basePath)) { fullPath = path; } else { fullPath = basePath + "/" + path; } TreeWalk treeWalk = TreeWalk.forPath(repository, fullPath, revTree); // path is not a folder if (treeWalk == null || !treeWalk.isSubtree()) return path; treeWalk.enterSubtree(); treeWalk.next(); // path contains a file if (!treeWalk.isSubtree()) return path; String next = path + "/" + treeWalk.getNameString(); // path contains more than a single entry if (treeWalk.next()) return path; path = next; } } catch (IOException e) { return path; } }
From source file:playRepository.GitRepository.java
License:Apache License
public boolean isIntermediateFolder(String path) { try {/*from w ww . jav a2 s . c om*/ ObjectId objectId = repository.resolve(Constants.HEAD); RevWalk revWalk = new RevWalk(repository); RevTree revTree = revWalk.parseTree(objectId); if (StringUtils.isEmpty(path)) { return false; } TreeWalk treeWalk = TreeWalk.forPath(repository, path, revTree); // path is not a folder if (treeWalk == null || !treeWalk.isSubtree()) return false; treeWalk.enterSubtree(); treeWalk.next(); // path contains a file if (!treeWalk.isSubtree()) return false; // patch contains more than a single entry if (treeWalk.next()) return false; return true; } catch (IOException e) { return false; } }
From source file:playRepository.GitRepository.java
License:Apache License
@Override public boolean isFile(String path) throws IOException { return isFile(path, Constants.HEAD); }
From source file:playRepository.GitRepository.java
License:Apache License
@Override public String getDefaultBranch() throws IOException { return repository.getRef(Constants.HEAD).getTarget().getName(); }