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.openengsb.connector.git.internal.UserGitServiceImplUT.java
License:Apache License
@Test public void updateWithEmptyWorkspace_shouldCloneRemoteSSHRepository() throws Exception { service.setRemoteLocation("git@github.com:Mercynary/myTestRepo.git"); List<CommitRef> commits = service.update(); assertThat(commits.size(), greaterThan(0)); assertThat(commits.get(0).getStringRepresentation(), is(service.getRepository().resolve(Constants.HEAD).name())); }
From source file:org.repodriller.scm.GitRepository.java
License:Apache License
public SCMRepository info() { try (Git git = openRepository(); RevWalk rw = new RevWalk(git.getRepository())) { AnyObjectId headId = git.getRepository().resolve(Constants.HEAD); RevCommit root = rw.parseCommit(headId); rw.sort(RevSort.REVERSE);//from w w w .j ava 2 s . c o m rw.markStart(root); RevCommit lastCommit = rw.next(); String origin = git.getRepository().getConfig().getString("remote", "origin", "url"); return new SCMRepository(this, origin, path, headId.getName(), lastCommit.getName()); } catch (Exception e) { throw new RuntimeException("Couldn't create JGit instance with path " + path); } }
From source file:org.repodriller.scm.GitRepository.java
License:Apache License
public ChangeSet getHead() { RevWalk revWalk = null;/*from w w w. j a v a2 s.c om*/ try (Git git = openRepository()) { ObjectId head = git.getRepository().resolve(Constants.HEAD); revWalk = new RevWalk(git.getRepository()); RevCommit r = revWalk.parseCommit(head); return extractChangeSet(r); } catch (Exception e) { throw new RuntimeException("error in getHead() for " + path, e); } finally { revWalk.close(); } }
From source file:org.repodriller.scm.GitRepository.java
License:Apache License
private List<ChangeSet> firstParentsOnly(Git git) { RevWalk revWalk = null;//from w w w .j a va 2 s .c o m try { List<ChangeSet> allCs = new ArrayList<>(); revWalk = new RevWalk(git.getRepository()); revWalk.setRevFilter(new FirstParentFilter()); revWalk.sort(RevSort.TOPO); Ref headRef = git.getRepository().getRef(Constants.HEAD); /* TODO Deprecated. */ RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId()); revWalk.markStart(headCommit); for (RevCommit revCommit : revWalk) { allCs.add(extractChangeSet(revCommit)); } return allCs; } catch (Exception e) { throw new RuntimeException(e); } finally { revWalk.close(); } }
From source file:org.test.RewriteGitHistory.java
License:Apache License
/** * Apply the commit on the current branch and update the head pointer. * //from w w w . j av a2 s . co m * @param commitBuilder * @throws IOException * @throws NoHeadException */ protected ObjectId executeCommit(CommitBuilder commitBuilder) throws NoHeadException, IOException { ObjectInserter inserter = repository.getObjectDatabase().newInserter(); ObjectId newBaseId = null; try { newBaseId = inserter.insert(commitBuilder); inserter.flush(); Ref head = repository.getRef(Constants.HEAD); if (head == null) throw new NoHeadException(JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); // determine the current HEAD and the commit it is referring to ObjectId headId = repository.resolve(Constants.HEAD + "^{commit}"); RevWalk revWalk = new RevWalk(repository); try { RevCommit newCommit = revWalk.parseCommit(newBaseId); RefUpdate ru = repository.updateRef(Constants.HEAD); ru.setNewObjectId(newBaseId); ru.setRefLogMessage("commit : " + newCommit.getShortMessage(), false); ru.setExpectedOldObjectId(headId); Result rc = ru.update(); log.info("rc.type = " + rc.name()); } finally { revWalk.release(); } } finally { inserter.release(); } return newBaseId; }
From source file:org.thiesen.ant.git.GitInfoExtractor.java
License:Open Source License
private static RevCommit getHead(final Repository r) throws IOException { final ObjectId headId = r.resolve(Constants.HEAD); return getCommit(r, headId); }
From source file:org.thiesen.ant.git.GitInfoExtractor.java
License:Open Source License
private static boolean isDirty(final CustomTag lastRevTag, final Repository r) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { final WorkingTreeIterator iterator = new FileTreeIterator(r); final IndexDiff d = lastRevTag == null ? new IndexDiff(r, Constants.HEAD, iterator) : new IndexDiff(r, lastRevTag.getObjectId(), iterator); d.diff();// w w w . j a va 2 s. co m @SuppressWarnings("unchecked") final Iterable<String> allModifications = Iterables.filter( Iterables.concat(d.getAdded(), d.getModified(), d.getChanged(), d.getMissing(), d.getRemoved()), new NotIsGitlink(r)); return !Iterables.isEmpty(allModifications); }
From source file:org.uberfire.java.nio.fs.jgit.util.commands.SimpleRefUpdateCommand.java
License:Apache License
private void forceUpdate(final RefUpdate ru, final ObjectId id) throws java.io.IOException, ConcurrentRefUpdateException { final RefUpdate.Result rc = ru.forceUpdate(); switch (rc) { case NEW:/*from w ww . j av a2s . c o m*/ case FORCED: case FAST_FORWARD: break; case REJECTED: case LOCK_FAILURE: throw new ConcurrentRefUpdateException(JGitText.get().couldNotLockHEAD, ru.getRef(), rc); default: throw new JGitInternalException( MessageFormat.format(JGitText.get().updatingRefFailed, Constants.HEAD, id.toString(), rc)); } }
From source file:org.uberfire.java.nio.fs.jgit.util.JGitUtil.java
License:Apache License
public static boolean commit(final Git git, final String branchName, final CommitInfo commitInfo, final boolean amend, final ObjectId _originId, final CommitContent content) { boolean hadEffecitiveCommit = true; final PersonIdent author = buildPersonIdent(git, commitInfo.getName(), commitInfo.getEmail(), commitInfo.getTimeZone(), commitInfo.getWhen()); try {//from ww w.j a v a 2 s. c o m final ObjectInserter odi = git.getRepository().newObjectInserter(); try { // Create the in-memory index of the new/updated issue. final ObjectId headId = git.getRepository().resolve(branchName + "^{commit}"); final ObjectId originId; if (_originId == null) { originId = git.getRepository().resolve(branchName + "^{commit}"); } else { originId = _originId; } final DirCache index; if (content instanceof DefaultCommitContent) { index = createTemporaryIndex(git, originId, (DefaultCommitContent) content); } else if (content instanceof MoveCommitContent) { index = createTemporaryIndex(git, originId, (MoveCommitContent) content); } else if (content instanceof CopyCommitContent) { index = createTemporaryIndex(git, originId, (CopyCommitContent) content); } else if (content instanceof RevertCommitContent) { index = createTemporaryIndex(git, originId); } else { index = null; } if (index != null) { final ObjectId indexTreeId = index.writeTree(odi); // Create a commit object final CommitBuilder commit = new CommitBuilder(); commit.setAuthor(author); commit.setCommitter(author); commit.setEncoding(Constants.CHARACTER_ENCODING); commit.setMessage(commitInfo.getMessage()); //headId can be null if the repository has no commit yet if (headId != null) { if (amend) { final List<ObjectId> parents = new LinkedList<ObjectId>(); final RevCommit previousCommit = new RevWalk(git.getRepository()).parseCommit(headId); final RevCommit[] p = previousCommit.getParents(); for (final RevCommit revCommit : p) { parents.add(0, revCommit.getId()); } commit.setParentIds(parents); } else { commit.setParentId(headId); } } commit.setTreeId(indexTreeId); // Insert the commit into the repository final ObjectId commitId = odi.insert(commit); odi.flush(); final RevWalk revWalk = new RevWalk(git.getRepository()); try { final RevCommit revCommit = revWalk.parseCommit(commitId); final RefUpdate ru = git.getRepository().updateRef("refs/heads/" + branchName); if (headId == null) { ru.setExpectedOldObjectId(ObjectId.zeroId()); } else { ru.setExpectedOldObjectId(headId); } ru.setNewObjectId(commitId); ru.setRefLogMessage("commit: " + revCommit.getShortMessage(), false); final RefUpdate.Result rc = ru.forceUpdate(); switch (rc) { case NEW: case FORCED: case FAST_FORWARD: break; case REJECTED: case LOCK_FAILURE: throw new ConcurrentRefUpdateException(JGitText.get().couldNotLockHEAD, ru.getRef(), rc); default: throw new JGitInternalException(MessageFormat.format(JGitText.get().updatingRefFailed, Constants.HEAD, commitId.toString(), rc)); } } finally { revWalk.release(); } } else { hadEffecitiveCommit = false; } } finally { odi.release(); } } catch (final Throwable t) { throw new RuntimeException(t); } return hadEffecitiveCommit; }
From source file:org.uberfire.provisioning.source.git.CloneTestJUnitTest.java
License:Apache License
@Test public void hello() throws Exception { final String repoName = "drools-workshop-build"; final Optional<Source> source = new GitConfigExecutor(new InMemorySourceRegistry()) .apply(new GitConfigImpl(tempPath.getAbsolutePath(), "master", gitUrl, repoName, "true")); assertTrue(source.isPresent());/*from ww w. jav a 2 s. c o m*/ final String targetRepoDir = tempPath.getAbsolutePath() + "/" + repoName + ".git"; Git git = Git.open(new File(targetRepoDir)); assertNotNull(git.getRepository().exactRef(Constants.HEAD)); }