本文整理了Java中org.eclipse.jgit.lib.Repository.findRef
方法的一些代码示例,展示了Repository.findRef
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.findRef
方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:findRef
[英]Search for a ref by (possibly abbreviated) name.
[中]通过名称(可能缩写)搜索ref。
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory findRef(String name) throws IOException {
Ref ref = getWrappedObject().getRepository().findRef(name);
return ref == null ? Memory.NULL : GitUtils.valueOf(ref);
}
代码示例来源:origin: spring-cloud/spring-cloud-config
private MergeResult merge(Git git, String label) {
try {
MergeCommand merge = git.merge();
merge.include(git.getRepository().findRef("origin/" + label));
MergeResult result = merge.call();
if (!result.getMergeStatus().isSuccessful()) {
this.logger.warn("Merged from remote " + label + " with result "
+ result.getMergeStatus());
}
return result;
}
catch (Exception ex) {
String message = "Could not merge remote for " + label + " remote: " + git
.getRepository().getConfig().getString("remote", "origin", "url");
warn(message, ex);
return null;
}
}
代码示例来源:origin: spring-cloud/spring-cloud-config
return git.getRepository().findRef("HEAD").getObjectId().getName();
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
Ref head = repository.findRef("refs/heads/master");
System.out.println("Found head: " + head);
// 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("\nCommit-Message: " + commit.getFullMessage());
walk.dispose();
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
Ref head = repository.findRef("refs/heads/master");
System.out.println("Found head: " + head);
// 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("\nCommit-Message: " + commit.getFullMessage());
walk.dispose();
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// a RevWalk allows to retrieve information from the repository
try (RevWalk walk = new RevWalk(repository)) {
// a simple tag that is not annotated
Ref simpleTag = repository.findRef("initialtag");
RevObject any = walk.parseAny(simpleTag.getObjectId());
System.out.println("Commit: " + any);
// an annotated tag
Ref annotatedTag = repository.findRef("secondtag");
any = walk.parseAny(annotatedTag.getObjectId());
System.out.println("Tag: " + any);
// finally try to print out the tag-content
System.out.println("\nTag-Content: \n");
ObjectLoader loader = repository.open(annotatedTag.getObjectId());
loader.copyTo(System.out);
walk.dispose();
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// a RevWalk allows to retrieve information from the repository
try (RevWalk walk = new RevWalk(repository)) {
// a simple tag that is not annotated
Ref simpleTag = repository.findRef("initialtag");
RevObject any = walk.parseAny(simpleTag.getObjectId());
System.out.println("Commit: " + any);
// an annotated tag
Ref annotatedTag = repository.findRef("secondtag");
any = walk.parseAny(annotatedTag.getObjectId());
System.out.println("Tag: " + any);
// finally try to print out the tag-content
System.out.println("\nTag-Content: \n");
ObjectLoader loader = repository.open(annotatedTag.getObjectId());
loader.copyTo(System.out);
walk.dispose();
}
}
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/** {@inheritDoc} */
@Override
public List<Note> call() throws GitAPIException {
checkCallable();
List<Note> notes = new ArrayList<>();
NoteMap map = NoteMap.newEmptyMap();
try (RevWalk walk = new RevWalk(repo)) {
Ref ref = repo.findRef(notesRef);
// if we have a notes ref, use it
if (ref != null) {
RevCommit notesCommit = walk.parseCommit(ref.getObjectId());
map = NoteMap.read(walk.getObjectReader(), notesCommit);
}
Iterator<Note> i = map.iterator();
while (i.hasNext())
notes.add(i.next());
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
}
return notes;
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException, GitAPIException {
final File localPath;
try (Repository repository = cloneRepository()) {
localPath = repository.getWorkTree();
System.out.println("Having repository: " + repository.getDirectory() + " with head: " +
repository.findRef(Constants.HEAD) + "/" + repository.resolve("HEAD") + "/" +
repository.resolve("refs/heads/master"));
// TODO: why do we get null here for HEAD?!? See also
// http://stackoverflow.com/questions/17979660/jgit-pull-noheadexception
try (Git git = new Git(repository)) {
PullResult call = git.pull().call();
System.out.println("Pulled from the remote repository: " + call);
}
}
// clean up here to not keep using more and more disk-space for these samples
FileUtils.deleteDirectory(localPath);
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException, GitAPIException {
final File localPath;
try (Repository repository = cloneRepository()) {
localPath = repository.getWorkTree();
System.out.println("Having repository: " + repository.getDirectory() + " with head: " +
repository.findRef(Constants.HEAD) + "/" + repository.resolve("HEAD") + "/" +
repository.resolve("refs/heads/master"));
// TODO: why do we get null here for HEAD?!? See also
// http://stackoverflow.com/questions/17979660/jgit-pull-noheadexception
try (Git git = new Git(repository)) {
PullResult call = git.pull().call();
System.out.println("Pulled from the remote repository: " + call);
}
}
// clean up here to not keep using more and more disk-space for these samples
FileUtils.deleteDirectory(localPath);
}
代码示例来源:origin: centic9/jgit-cookbook
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();
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
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();
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
Ref head = repository.findRef("HEAD");
// 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());
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now use a TreeWalk to iterate over all files in the Tree recursively
// you can set Filters to narrow down the results if needed
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
while (treeWalk.next()) {
System.out.println("found: " + treeWalk.getPathString());
}
}
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
Ref head = repository.findRef("HEAD");
// 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());
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now use a TreeWalk to iterate over all files in the Tree
// you can set Filters to narrow down the results if needed
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(tree);
// not walk the tree recursively so we only get the elements in the top-level directory
treeWalk.setRecursive(false);
while (treeWalk.next()) {
System.out.println("found: " + treeWalk.getPathString());
}
}
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
Ref head = repository.findRef("HEAD");
// 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());
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now use a TreeWalk to iterate over all files in the Tree recursively
// you can set Filters to narrow down the results if needed
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
while (treeWalk.next()) {
System.out.println("found: " + treeWalk.getPathString());
}
}
}
}
}
}
代码示例来源:origin: centic9/jgit-cookbook
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
Ref head = repository.findRef("HEAD");
// 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());
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now use a TreeWalk to iterate over all files in the Tree
// you can set Filters to narrow down the results if needed
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(tree);
// not walk the tree recursively so we only get the elements in the top-level directory
treeWalk.setRecursive(false);
while (treeWalk.next()) {
System.out.println("found: " + treeWalk.getPathString());
}
}
}
}
}
}
代码示例来源:origin: git-commit-id/maven-git-commit-id-plugin
@Override
public void prepareGitToExtractMoreDetailedRepoInformation() throws GitCommitIdExecutionException {
try {
// more details parsed out bellow
Ref evaluateOnCommitReference = git.findRef(evaluateOnCommit);
ObjectId evaluateOnCommitResolvedObjectId = git.resolve(evaluateOnCommit);
if ((evaluateOnCommitReference == null) && (evaluateOnCommitResolvedObjectId == null)) {
throw new GitCommitIdExecutionException("Could not get " + evaluateOnCommit + " Ref, are you sure you have set the dotGitDirectory property of this plugin to a valid path?");
}
revWalk = new RevWalk(git);
ObjectId headObjectId;
if (evaluateOnCommitReference != null) {
headObjectId = evaluateOnCommitReference.getObjectId();
} else {
headObjectId = evaluateOnCommitResolvedObjectId;
}
if (headObjectId == null) {
throw new GitCommitIdExecutionException("Could not get " + evaluateOnCommit + " Ref, are you sure you have some commits in the dotGitDirectory?");
}
evalCommit = revWalk.parseCommit(headObjectId);
revWalk.markStart(evalCommit);
} catch (Exception e) {
throw new GitCommitIdExecutionException("Error", e);
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/** {@inheritDoc} */
@Override
public Note call() throws GitAPIException {
checkCallable();
NoteMap map = NoteMap.newEmptyMap();
RevCommit notesCommit = null;
try (RevWalk walk = new RevWalk(repo);
ObjectInserter inserter = repo.newObjectInserter()) {
Ref ref = repo.findRef(notesRef);
// if we have a notes ref, use it
if (ref != null) {
notesCommit = walk.parseCommit(ref.getObjectId());
map = NoteMap.read(walk.getObjectReader(), notesCommit);
}
map.set(id, message, inserter);
commitNoteMap(repo, notesRef, walk, map, notesCommit, inserter,
"Notes added by 'git notes add'"); //$NON-NLS-1$
return map.getNote(id);
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent,
String refLogMessage) throws IOException {
if (ref == null)
return;
Ref currentRef = repo.findRef(ref);
RefUpdate refUpdate = repo.updateRef(ref);
refUpdate.setNewObjectId(commitId);
refUpdate.setRefLogIdent(refLogIdent);
refUpdate.setRefLogMessage(refLogMessage, false);
refUpdate.setForceRefLog(true);
if (currentRef != null)
refUpdate.setExpectedOldObjectId(currentRef.getObjectId());
else
refUpdate.setExpectedOldObjectId(ObjectId.zeroId());
refUpdate.forceUpdate();
}
代码示例来源:origin: FlowCI/flow-platform
/**
* 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);
}
}
内容来源于网络,如有侵权,请联系作者删除!