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.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public List<Object> getBranches(ServiceInvocationContext context, String repositoryUrl) { tlCommand.set((InvokeServiceMethodServerCommand) context.getCommand()); Repository db = null;// w ww. j a va2 s. c om try { URIish uri = new URIish(repositoryUrl.trim()); db = new FileRepository(new File("/tmp")); Git git = new Git(db); LsRemoteCommand rc = git.lsRemote(); rc.setRemote(uri.toString()).setTimeout(30); Collection<Ref> remoteRefs = rc.call(); List<GitRef> branches = new ArrayList<GitRef>(); Ref idHEAD = null; for (Ref r : remoteRefs) { if (r.getName().equals(Constants.HEAD)) { idHEAD = r; } } Ref head = null; boolean headIsMaster = false; String masterBranchRef = Constants.R_HEADS + Constants.MASTER; for (Ref r : remoteRefs) { String n = r.getName(); if (!n.startsWith(Constants.R_HEADS)) continue; branches.add(new GitRef(n, Repository.shortenRefName(n))); if (idHEAD == null || headIsMaster) continue; if (r.getObjectId().equals(idHEAD.getObjectId())) { headIsMaster = masterBranchRef.equals(r.getName()); if (head == null || headIsMaster) head = r; } } Collections.sort(branches, new Comparator<GitRef>() { public int compare(GitRef r1, GitRef r2) { return r1.getShortName().compareTo(r2.getShortName()); } }); if (idHEAD != null && head == null) { head = idHEAD; branches.add(0, new GitRef(idHEAD.getName(), Repository.shortenRefName(idHEAD.getName()))); } GitRef headRef = head != null ? new GitRef(head.getName(), Repository.shortenRefName(head.getName())) : null; return Arrays.asList(new Object[] { branches, headRef }); } catch (JGitInternalException | GitAPIException e) { context.getCommunicationChannel() .appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), GitPlugin.getInstance().getMessage("git.cloneWizard.branch.cannotListBranches") + "\n" + e.getCause().getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); } catch (IOException e) { context.getCommunicationChannel().appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), GitPlugin.getInstance().getMessage("git.cloneWizard.branch.cannotCreateTempRepo"), DisplaySimpleMessageClientCommand.ICON_ERROR)); } catch (URISyntaxException e) { context.getCommunicationChannel().appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getReason(), DisplaySimpleMessageClientCommand.ICON_ERROR)); } catch (Exception e) { if (GitPlugin.getInstance().getUtils().isAuthentificationException(e)) { openLoginWindow(); return null; } logger.debug(CommonPlugin.getInstance().getMessage("error"), e); } finally { if (db != null) { db.close(); } } return null; }
From source file:org.flowerplatform.web.git.GitUtils.java
License:Open Source License
public RevCommit getHeadCommit(Repository repository) { RevCommit headCommit = null;//w w w .j a v a 2s.c o m try { ObjectId parentId = repository.resolve(Constants.HEAD); if (parentId != null) { headCommit = new RevWalk(repository).parseCommit(parentId); } } catch (IOException e) { return null; } return headCommit; }
From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java
License:Open Source License
private void setupWalk(WebWalk walk, Repository repo, String path) throws IOException { walk.addAdditionalRefs(repo.getRefDatabase().getAdditionalRefs()); walk.addAdditionalRefs(repo.getRefDatabase().getRefs(Constants.R_NOTES).values()); walk.sort(RevSort.COMMIT_TIME_DESC, true); walk.sort(RevSort.BOUNDARY, true);/*from w ww.j a va 2 s. co m*/ walk.setRetainBody(false); setWalkStartPoints(walk, repo, walk.parseCommit(repo.resolve(Constants.HEAD))); createFileWalker(walk, repo, path); }
From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java
License:Open Source License
private String mergeStatus(Repository repository) { String message = null;//from w w w . j av a2s . c o m try { Ref head = repository.getRef(Constants.HEAD); if (head == null || !head.isSymbolic()) { message = GitPlugin.getInstance().getMessage("git.merge.headIsNoBranch"); } else if (!repository.getRepositoryState().equals(RepositoryState.SAFE)) message = GitPlugin.getInstance().getMessage("git.merge.wrongRepositoryState", repository.getRepositoryState()); } catch (IOException e) { message = e.getMessage(); } return message; }
From source file:org.gitective.tests.CommitFinderTest.java
License:Open Source License
/** * Test searching commit range that has none in-between start and end * * @throws Exception/*from w w w . jav a2 s .c o m*/ */ @Test public void noCommitsBetween() throws Exception { add("test.txt", "content"); CommitFinder finder = new CommitFinder(testRepo); CommitCountFilter count = new CommitCountFilter(); finder.setFilter(count); finder.findBetween(Constants.HEAD, Constants.HEAD); assertEquals(0, count.getCount()); }
From source file:org.gitective.tests.CommitFinderTest.java
License:Open Source License
/** * Test searching commit range that has none in-between start and end * * @throws Exception/*w w w .j a v a2 s . c o m*/ */ @Test public void noCommitsBetweenHeadAndHead() throws Exception { add("test.txt", "content"); CommitFinder finder = new CommitFinder(testRepo); CommitCountFilter count = new CommitCountFilter(); finder.setFilter(count); finder.findBetween(Constants.HEAD, Constants.HEAD); assertEquals(0, count.getCount()); }
From source file:org.gitective.tests.CommitFinderTest.java
License:Open Source License
/** * Test searching commit range that has none in-between start and end * * @throws Exception// w ww .j a va 2s . c o m */ @Test public void noCommitsBetweenCommitIdAndHead() throws Exception { add("test.txt", "content"); RevCommit commit = add("test.txt", "content2"); CommitFinder finder = new CommitFinder(testRepo); CommitListFilter commits = new CommitListFilter(); finder.setFilter(commits); finder.findBetween(commit, Constants.HEAD + "~1"); assertEquals(1, commits.getCommits().size()); assertEquals(commit, commits.getCommits().get(0)); }
From source file:org.gitective.tests.TreeUtilsTest.java
License:Open Source License
/** * Diff walk for commit with no parents/* w ww . j a va 2 s .co m*/ * * @throws Exception */ @Test public void diffWithNoParents() throws Exception { RevCommit commit = add("test.txt", "content"); Repository repo = new FileRepository(testRepo); TreeWalk walk = TreeUtils.diffWithParents(repo, Constants.HEAD); assertNotNull(walk); assertEquals(2, walk.getTreeCount()); assertTrue(walk.next()); assertEquals("test.txt", walk.getPathString()); assertEquals(ObjectId.zeroId(), walk.getObjectId(0)); assertEquals(BlobUtils.getId(repo, commit, "test.txt"), walk.getObjectId(1)); assertFalse(walk.next()); }
From source file:org.gitective.tests.TreeUtilsTest.java
License:Open Source License
/** * Diff walk for commit with one parent/*from w ww. j a v a 2 s . c om*/ * * @throws Exception */ @Test public void diffWithOneParent() throws Exception { Repository repo = new FileRepository(testRepo); RevCommit commit1 = add("test.txt", "content"); RevCommit commit2 = add("test.txt", "content2"); TreeWalk walk = TreeUtils.diffWithParents(repo, Constants.HEAD); assertNotNull(walk); assertEquals(2, walk.getTreeCount()); assertTrue(walk.next()); assertEquals("test.txt", walk.getPathString()); assertEquals(BlobUtils.getId(repo, commit1, "test.txt"), walk.getObjectId(0)); assertEquals(BlobUtils.getId(repo, commit2, "test.txt"), walk.getObjectId(1)); assertFalse(walk.next()); }
From source file:org.jboss.as.server.controller.git.GitConfigurationPersistenceResource.java
License:Apache License
@Override public void rollback() { super.rollback(); try (Git git = repository.getGit()) { git.reset().setMode(ResetCommand.ResetType.HARD).setRef(Constants.HEAD).call(); } catch (GitAPIException ex) { MGMT_OP_LOGGER.failedToStoreConfiguration(ex, file.getName()); }//from w w w . j a v a 2 s .co m }