Refine search
ObjectId oldHeadTree = git.getRepository().resolve(this.lastProcessedGitHash + "^{tree}"); this.git.fetch() .setRemote(REMOTE_NAME) .setCredentialsProvider(getCredentialsProvider()) .call(); this.git.reset().setMode(ResetCommand.ResetType.HARD).setRef(REMOTE_NAME + "/" + this.branchName).call(); ObjectId head = this.git.getRepository().resolve("HEAD"); ObjectId headTree = this.git.getRepository().resolve("HEAD^{tree}"); latestGitHash = head.getName();
private static void append(StringBuilder s, Ref r, String nullName) { if (r == null) { s.append(nullName); } else if (r.isSymbolic()) { s.append(r.getTarget().getName()); } else { ObjectId id = r.getObjectId(); if (id != null) { s.append(id.name()); } } }
private boolean hasDanglingHead() throws IOException { Ref head = exactRef(Constants.HEAD); if (head != null) { ObjectId id = head.getObjectId(); return id == null || id.equals(ObjectId.zeroId()); } return false; }
if (buildByBranchName.getValue().getSHA1().equals(ObjectId.fromString(scmRevisionHash))) { addGitLabBranchBuild(result, scmRevisionHash, buildData.getRemoteUrls(), environment, gitLabClient);
try (Git git = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) { System.out.println("Having repository: " + git.getRepository().getDirectory()); FetchResult result = git.fetch().setCheckFetchedObjects(true).call(); System.out.println("Messages: " + result.getMessages()); List<Ref> call = git.branchList().call(); for (Ref ref : call) { System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); call = git.branchList().setListMode(ListMode.ALL).call(); for (Ref ref : call) { System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { System.out.println("Listing local branches:"); try (Git git = new Git(repository)) { List<Ref> call = git.branchList().call(); for (Ref ref : call) { System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); } System.out.println("Now including remote branches:"); call = git.branchList().setListMode(ListMode.ALL).call(); for (Ref ref : call) { System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); } } } } }
RepositoryState state = repo.getRepositoryState(); if (!state.canCommit()) throw new WrongRepositoryStateException(MessageFormat.format( if (all && !repo.isBare()) { try (Git git = new Git(repo)) { git.add() .addFilepattern(".") //$NON-NLS-1$ .setUpdate(true).call(); Ref head = repo.exactRef(Constants.HEAD); if (head == null) throw new NoHeadException( if (indexTreeId.equals(headCommit.getTree())) { throw new EmptyCommitException( JGitText.get().emptyCommit); ru.setExpectedOldObjectId(headId); else ru.setExpectedOldObjectId(ObjectId.zeroId()); Result rc = ru.forceUpdate(); switch (rc) { throw new JGitInternalException(MessageFormat.format( JGitText.get().updatingRefFailed, Constants.HEAD, commitId.toString(), rc));
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Ref> call = git.tagList().call(); for (Ref ref : call) { System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName()); // fetch all commits for this tag LogCommand log = git.log(); Ref peeledRef = repository.getRefDatabase().peel(ref); if(peeledRef.getPeeledObjectId() != null) { log.add(peeledRef.getPeeledObjectId()); } else { log.add(ref.getObjectId()); } Iterable<RevCommit> logs = log.call(); for (RevCommit rev : logs) { System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */); } } } } } }
Ref headRef = repo.exactRef(Constants.HEAD); if (headRef == null) throw new NoHeadException( JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported); RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId()); ObjectId srcObjectId = src.getPeeledObjectId(); if (srcObjectId == null) srcObjectId = src.getObjectId(); RevCommit srcCommit = revWalk.parseCommit(srcObjectId); String revertName = srcCommit.getId().abbreviate(7).name() + "\""; //$NON-NLS-1$ String newMessage = shortMessage + "\n\n" //$NON-NLS-1$ + "This reverts commit " + srcCommit.getId().getName() //$NON-NLS-1$ + ".\n"; //$NON-NLS-1$ if (merger.merge(headCommit, srcParent)) { .formatWithConflicts(newMessage, merger.getUnmergedPaths()); repo.writeRevertHead(srcCommit.getId());
/** * Get latest commit by ref name from local .git */ @Override public GitCommit commit(String refName) throws GitException { try (Git git = gitOpen()) { Repository repo = git.getRepository(); Ref head = repo.findRef(refName); if (head == null) { return null; } try (RevWalk walk = new RevWalk(repo)) { RevCommit commit = walk.parseCommit(head.getObjectId()); walk.dispose(); String id = commit.getId().getName(); String message = commit.getFullMessage(); String author = commit.getAuthorIdent().getName(); return new GitCommit(id, message, author); } } catch (IOException e) { throw new GitException("Fail to get commit message", e); } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // See e.g. GetRevCommitFromObjectId for how to use a SHA-1 directly Ref head = repository.findRef("HEAD"); System.out.println("Ref of HEAD: " + head + ": " + head.getName() + " - " + head.getObjectId().getName()); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("Commit: " + commit); // a commit points to a tree RevTree tree = walk.parseTree(commit.getTree().getId()); System.out.println("Found Tree: " + tree); walk.dispose(); } } } }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.exactRef("refs/heads/master"); System.out.println("Found head: " + head); RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("Found Commit: " + commit); try (Git git = new Git(repository)) { git.notesAdd().setMessage("some note message").setObjectId(commit).call(); System.out.println("Added Note to commit " + commit); List<Note> call = git.notesList().call(); System.out.println("Listing " + call.size() + " notes"); for(Note note : call) { if(!note.getName().equals(head.getObjectId().getName())) { System.out.println("Note " + note + " did not match commit " + head); continue; ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out);
private static String getHeadName(Ref head) { String headName; if (head.isSymbolic()) { headName = head.getTarget().getName(); } else { ObjectId headId = head.getObjectId(); // the callers are checking this already assert headId != null; headName = headId.getName(); } return headName; }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // the Ref holds an ObjectId for any type of object (tree, commit, blob, tree) Ref head = repository.exactRef("refs/heads/master"); System.out.println("Ref of refs/heads/master: " + head + ": " + head.getName() + " - " + head.getObjectId().getName()); } } }
return git.getRepository().findRef("HEAD").getObjectId().getName(); try { if (git != null) { git.close();
Ref head = repo.exactRef("HEAD"); //$NON-NLS-1$ if (head == null) { throw new NoHeadException( JGitText.get().invalidRepositoryStateNoHead); RevCommit headCommit = revWalk.parseCommit(head.getObjectId()); RevTree tree = headCommit.getTree(); if (!submoduleHead.equals(w.getObjectId())) { if (!submoduleHead.equals(w.getObjectId())) { Status status = Git.wrap(submoduleRepo).status().call(); return status.isClean() ? SubmoduleDeinitStatus.SUCCESS : SubmoduleDeinitStatus.DIRTY;
String getMergedConfig(String branchName, RevCommit newCommit) throws GitAPIException, IOException { MergeResult result = null; try { checkout(branchName); result = git.merge().include(newCommit).call(); } catch (GitAPIException e) { LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); throw e; } if (!result.getMergeStatus().isSuccessful()) { LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed as config file has changed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); throw new ConfigFileHasChangedException(); } LOGGER.info("[CONFIG_MERGE] Successfully merged commit {} by user {} to branch {}. Merge commit revision is {}", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); return FileUtils.readFileToString(new File(workingDir, CRUISE_CONFIG_XML), UTF_8); }
private static boolean matchOld(ReceiveCommand cmd, @Nullable Ref ref) { if (ref == null) { return AnyObjectId.equals(ObjectId.zeroId(), cmd.getOldId()) && cmd.getOldSymref() == null; } else if (ref.isSymbolic()) { return ref.getTarget().getName().equals(cmd.getOldSymref()); } ObjectId id = ref.getObjectId(); if (id == null) { id = ObjectId.zeroId(); } return cmd.getOldId().equals(id); }
private void markLocalRefsComplete(Set<ObjectId> have) throws TransportException { List<Ref> refs; try { refs = local.getRefDatabase().getRefs(); } catch (IOException e) { throw new TransportException(e.getMessage(), e); } for (Ref r : refs) { try { markLocalObjComplete(revWalk.parseAny(r.getObjectId())); } catch (IOException readError) { throw new TransportException(MessageFormat.format(JGitText.get().localRefIsMissingObjects, r.getName()), readError); } } for (ObjectId id : have) { try { markLocalObjComplete(revWalk.parseAny(id)); } catch (IOException readError) { throw new TransportException(MessageFormat.format(JGitText.get().transportExceptionMissingAssumed, id.name()), readError); } } }