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.eclipse.orion.server.tests.servlets.git.GitTagTest.java
License:Open Source License
@Test public void testTag() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null); IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute(); JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null); IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID)) .append("folder").makeAbsolute(); IPath[] clonePaths = new IPath[] { clonePathTop, clonePathFolder }; for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project/folder metadata WebRequest request = getGetFilesRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject folder = new JSONObject(response.getText()); JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT); String gitTagUri = gitSection.getString(GitConstants.KEY_TAG); // tag HEAD with 'tag' JSONObject tag = tag(gitTagUri, "tag", Constants.HEAD); assertEquals("tag", tag.getString(ProtocolConstants.KEY_NAME)); new URI(tag.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); }/*from w w w. ja v a 2s .co m*/ }
From source file:org.eclipse.releng.tools.git.GitCopyrightAdapter.java
License:Open Source License
public int getLastModifiedYear(IFile file, IProgressMonitor monitor) throws CoreException { try {//from ww w. j av a 2s . c om monitor.beginTask("Fetching logs from Git", 100); //$NON-NLS-1$ final RepositoryMapping mapping = RepositoryMapping.getMapping(file); if (mapping != null) { final Repository repo = mapping.getRepository(); if (repo != null) { RevWalk walk = null; try { final ObjectId start = repo.resolve(Constants.HEAD); walk = new RevWalk(repo); walk.setTreeFilter(AndTreeFilter .create(PathFilter.create(mapping.getRepoRelativePath(file)), TreeFilter.ANY_DIFF)); walk.markStart(walk.lookupCommit(start)); final RevCommit commit = walk.next(); if (commit != null) { if (filterString != null && commit.getFullMessage().toLowerCase().indexOf(filterString) != -1) { // the last update was a copyright check in - ignore return 0; } boolean isSWT = file.getProject().getName().startsWith("org.eclipse.swt"); //$NON-NLS-1$ String logComment = commit.getFullMessage(); if (isSWT && (logComment.indexOf("restore HEAD after accidental deletion") != -1 //$NON-NLS-1$ || logComment.indexOf("fix permission of files") != -1)) { //$NON-NLS-1$ // ignore commits with above comments return 0; } boolean isPlatform = file.getProject().getName().equals("eclipse.platform"); //$NON-NLS-1$ if (isPlatform && (logComment .indexOf("Merge in ant and update from origin/master") != -1 //$NON-NLS-1$ || logComment.indexOf( "Fixed bug 381684: Remove update from repository and map files") != -1 //$NON-NLS-1$ || logComment.indexOf("Restored 'org.eclipse.update.core'") != -1)) { //$NON-NLS-1$ // ignore commits with above comments return 0; } final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(0); calendar.add(Calendar.SECOND, commit.getCommitTime()); return calendar.get(Calendar.YEAR); } } catch (final IOException e) { throw new CoreException(new Status(IStatus.ERROR, RelEngPlugin.ID, 0, NLS.bind("An error occured when processing {0}", file.getName()), e)); } finally { if (walk != null) walk.release(); } } } } finally { monitor.done(); } return -1; }
From source file:org.eclipse.tycho.extras.buildtimestamp.jgit.JGitBuildTimestampProvider.java
License:Open Source License
public Date getTimestamp(MavenSession session, MavenProject project, MojoExecution execution) throws MojoExecutionException { FileRepositoryBuilder builder = new FileRepositoryBuilder() // .readEnvironment() // .findGitDir(project.getBasedir()) // .setMustExist(true);// w w w. jav a 2s. c om try { Repository repository = builder.build(); try { RevWalk walk = new RevWalk(repository); try { String relPath = getRelPath(repository, project); if (relPath != null && relPath.length() > 0) { walk.setTreeFilter(AndTreeFilter.create(new PathFilter(relPath, getIgnoreFilter(execution)), TreeFilter.ANY_DIFF)); } // TODO make sure working tree is clean ObjectId headId = repository.resolve(Constants.HEAD); walk.markStart(walk.parseCommit(headId)); RevCommit commit = walk.next(); return new Date(commit.getCommitTime() * 1000L); } finally { walk.release(); } } finally { repository.close(); } } catch (IOException e) { throw new MojoExecutionException("Could not determine git commit timestamp", e); } }
From source file:org.eclipse.tycho.extras.sourceref.jgit.JGitSourceReferencesProvider.java
License:Open Source License
private ObjectId resolveHead(Repository repo) throws MojoExecutionException { ObjectId head;//from w w w. j a v a 2 s. co m try { head = repo.resolve(Constants.HEAD); } catch (AmbiguousObjectException e) { throw new MojoExecutionException("exception trying resolve HEAD", e); } catch (IOException e) { throw new MojoExecutionException("exception trying resolve HEAD", e); } return head; }
From source file:org.efaps.cli.rest.ImportCICall.java
License:Apache License
/** * Gets the file information.//from ww w . j a v a 2 s.c o m * * @param _file the _file * @return the file information */ protected String[] getFileInformation(final File _file) { final String[] ret = new String[2]; try { final Repository repo = new FileRepository(evalGitDir(_file)); final ObjectId lastCommitId = repo.resolve(Constants.HEAD); final PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>(); final PlotWalk revWalk = new PlotWalk(repo); final RevCommit root = revWalk.parseCommit(lastCommitId); revWalk.markStart(root); revWalk.setTreeFilter(AndTreeFilter.create( PathFilter.create(_file.getPath().replaceFirst(repo.getWorkTree().getPath() + "/", "")), TreeFilter.ANY_DIFF)); plotCommitList.source(revWalk); plotCommitList.fillTo(2); final PlotCommit<PlotLane> commit = plotCommitList.get(0); if (commit != null) { final PersonIdent authorIdent = commit.getAuthorIdent(); final Date authorDate = authorIdent.getWhen(); final TimeZone authorTimeZone = authorIdent.getTimeZone(); final DateTime dateTime = new DateTime(authorDate.getTime(), DateTimeZone.forTimeZone(authorTimeZone)); ret[1] = dateTime.toString(); ret[0] = commit.getId().getName(); } else { ret[1] = new DateTime().toString(); ret[0] = "UNKNOWN"; } } catch (final RevisionSyntaxException | IOException e) { e.printStackTrace(); } return ret; }
From source file:org.efaps.eclipse.rest.RestClient.java
License:Apache License
protected String[] getFileInformation(final File _file) { final String[] ret = new String[2]; try {/*from w ww. j a va 2s . co m*/ final Repository repo = new FileRepository(evalGitDir(_file)); final ObjectId lastCommitId = repo.resolve(Constants.HEAD); final PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>(); final PlotWalk revWalk = new PlotWalk(repo); final RevCommit root = revWalk.parseCommit(lastCommitId); revWalk.markStart(root); revWalk.setTreeFilter(AndTreeFilter.create( PathFilter.create(_file.getPath().replaceFirst(repo.getWorkTree().getPath() + "/", "")), TreeFilter.ANY_DIFF)); plotCommitList.source(revWalk); plotCommitList.fillTo(2); final PlotCommit<PlotLane> commit = plotCommitList.get(0); if (commit != null) { final PersonIdent authorIdent = commit.getAuthorIdent(); final Date authorDate = authorIdent.getWhen(); final TimeZone authorTimeZone = authorIdent.getTimeZone(); final DateTime dateTime = new DateTime(authorDate.getTime(), DateTimeZone.forTimeZone(authorTimeZone)); ret[1] = dateTime.toString(); ret[0] = commit.getId().getName(); } else { ret[1] = new DateTime().toString(); ret[0] = "UNKNOWN"; } } catch (RevisionSyntaxException | IOException e) { e.printStackTrace(); } return ret; }
From source file:org.eluder.coveralls.maven.plugin.domain.GitRepository.java
License:Open Source License
private Git.Head getHead(final Repository repository) throws IOException { ObjectId revision = repository.resolve(Constants.HEAD); RevCommit commit = new RevWalk(repository).parseCommit(revision); Git.Head head = new Git.Head(revision.getName(), commit.getAuthorIdent().getName(), commit.getAuthorIdent().getEmailAddress(), commit.getCommitterIdent().getName(), commit.getCommitterIdent().getEmailAddress(), commit.getFullMessage()); return head;//from w w w . j a v a 2s . c o m }
From source file:org.exist.git.xquery.BranchCreate.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/*www .j ava 2s .c o m*/ String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); git.branchCreate().setName(args[1].getStringValue()) .setStartPoint( args.length <= 2 || args[2].isEmpty() ? Constants.HEAD : args[2].getStringValue()) .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).setForce(true).call(); return BooleanValue.TRUE; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.Cat.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {// www. j av a 2 s . c om String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; String objPath = args[1].getStringValue(); if (mySignature.getName() == CAT_WORKING_COPY) { Resource resource = new Resource(localPath + objPath); InputStream is = new ResourceInputStream(resource); ; Base64BinaryDocument b64doc = Base64BinaryDocument.getInstance(context, is); return b64doc; } Git git = Git.open(new Resource(localPath), FS); Repository repository = git.getRepository(); // find the HEAD ObjectId lastCommitId = repository.resolve(Constants.HEAD); // now we have to get the commit RevWalk revWalk = new RevWalk(repository); RevCommit commit = revWalk.parseCommit(lastCommitId); // and using commit's tree find the path RevTree tree = commit.getTree(); TreeWalk treeWalk = new TreeWalk(repository); treeWalk.addTree(tree); treeWalk.setRecursive(true); treeWalk.setFilter(PathFilter.create(args[1].getStringValue())); if (!treeWalk.next()) { return Sequence.EMPTY_SEQUENCE; } ObjectId objectId = treeWalk.getObjectId(0); ObjectLoader loader = repository.open(objectId); // and then one can use either InputStream is = loader.openStream(); Base64BinaryDocument b64doc = Base64BinaryDocument.getInstance(context, is); return b64doc; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.Status.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {// w w w . ja v a 2 s . c o m String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); if (getName().equals(STATUS)) { MemTreeBuilder builder = getContext().getDocumentBuilder(); int nodeNr = builder.startElement(REPOSITORY, null); StatusBuilder statusBuilder = new StatusBuilder(builder); final Repository repo = git.getRepository(); diff(repo, Constants.HEAD, new FileTreeIterator(repo), statusBuilder, args[1].getStringValue(), args[2].effectiveBooleanValue()); builder.endElement(); return builder.getDocument().getNode(nodeNr); } org.eclipse.jgit.api.Status status = git.status().call(); Set<String> list; if (getName().equals(UNTRACKED)) { list = status.getUntracked(); } else if (getName().equals(ADDED)) { list = status.getAdded(); } else if (getName().equals(CHANGED)) { list = status.getChanged(); } else if (getName().equals(CONFLICTING)) { list = status.getConflicting(); } else if (getName().equals(IGNORED)) { list = status.getIgnoredNotInIndex(); } else if (getName().equals(MISSING)) { list = status.getMissing(); } else if (getName().equals(MODIFIED)) { list = status.getModified(); } else if (getName().equals(REMOVED)) { list = status.getRemoved(); } else if (getName().equals(UNTRACKED)) { list = status.getUntracked(); } else if (getName().equals(UNTRACKED_FOLDERS)) { list = status.getUntrackedFolders(); } else { return Sequence.EMPTY_SEQUENCE; } Sequence result = new ValueSequence(); for (String modified : list) { result.add(new StringValue(modified)); } return result; } catch (Throwable e) { e.printStackTrace(); throw new XPathException(this, Module.EXGIT001, e); } }