當前位置: 首頁>>代碼示例>>Java>>正文


Java Ref類代碼示例

本文整理匯總了Java中org.eclipse.jgit.lib.Ref的典型用法代碼示例。如果您正苦於以下問題:Java Ref類的具體用法?Java Ref怎麽用?Java Ref使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Ref類屬於org.eclipse.jgit.lib包,在下文中一共展示了Ref類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBranches

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
public static ArrayList<String> getBranches(final File repo) {
    try {
        final List<Ref> refs = Git.open(repo)
                .branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();

        final ArrayList<String> result = new ArrayList<>();
        for (Ref ref : refs)
            result.add(ref.getName());

        return result;
    } catch (GitAPIException | IOException e) {
        e.printStackTrace();
    }

    return new ArrayList<>();
}
 
開發者ID:LonamiWebs,項目名稱:Stringlate,代碼行數:17,代碼來源:GitWrapper.java

示例2: findRemoteBranchName

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
private String findRemoteBranchName () throws GitException {
    Ref ref = null;
    try {
        ref = getRepository().getRef(branchToMerge);
    } catch (IOException ex) {
        throw new GitException(ex);
    }
    if (ref != null) {
        for (String s : refSpecs) {
            RefSpec spec = new RefSpec(s);
            if (spec.matchDestination(ref)) {
                spec = spec.expandFromDestination(ref);
                String refName = spec.getSource();
                if (refName.startsWith(Constants.R_HEADS)) {
                    return refName.substring(Constants.R_HEADS.length());
                }
            }
        }
    }
    return branchToMerge;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:PullCommand.java

示例3: run

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    Ref currentRef = repository.getTags().get(tagName);
    if (currentRef == null) {
        throw new GitException.MissingObjectException(tagName, GitObjectType.TAG);
    }
    String fullName = currentRef.getName();
    try {
        RefUpdate update = repository.updateRef(fullName);
        update.setRefLogMessage("tag deleted", false);
        update.setForceUpdate(true);
        Result deleteResult = update.delete();

        switch (deleteResult) {
            case IO_FAILURE:
            case LOCK_FAILURE:
            case REJECTED:
                throw new GitException.RefUpdateException("Cannot delete tag " + tagName, GitRefUpdateResult.valueOf(deleteResult.name()));
        }
    } catch (IOException ex) {
        throw new GitException(ex);
    }
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:DeleteTagCommand.java

示例4: doRefUpdate

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
@VisibleForTesting
static void doRefUpdate(org.eclipse.jgit.lib.Repository jGitRepository, RevWalk revWalk,
                        String ref, ObjectId commitId) throws IOException {

    if (ref.startsWith(Constants.R_TAGS)) {
        final Ref oldRef = jGitRepository.exactRef(ref);
        if (oldRef != null) {
            throw new StorageException("tag ref exists already: " + ref);
        }
    }

    final RefUpdate refUpdate = jGitRepository.updateRef(ref);
    refUpdate.setNewObjectId(commitId);

    final Result res = refUpdate.update(revWalk);
    switch (res) {
        case NEW:
        case FAST_FORWARD:
            // Expected
            break;
        default:
            throw new StorageException("unexpected refUpdate state: " + res);
    }
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:25,代碼來源:GitRepository.java

示例5: testDoUpdateRef

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
private static void testDoUpdateRef(String ref, ObjectId commitId, boolean tagExists) throws Exception {
    final org.eclipse.jgit.lib.Repository jGitRepo = mock(org.eclipse.jgit.lib.Repository.class);
    final RevWalk revWalk = mock(RevWalk.class);
    final RefUpdate refUpdate = mock(RefUpdate.class);

    when(jGitRepo.exactRef(ref)).thenReturn(tagExists ? mock(Ref.class) : null);
    when(jGitRepo.updateRef(ref)).thenReturn(refUpdate);

    when(refUpdate.update(revWalk)).thenReturn(RefUpdate.Result.NEW);
    GitRepository.doRefUpdate(jGitRepo, revWalk, ref, commitId);

    when(refUpdate.update(revWalk)).thenReturn(RefUpdate.Result.FAST_FORWARD);
    GitRepository.doRefUpdate(jGitRepo, revWalk, ref, commitId);

    when(refUpdate.update(revWalk)).thenReturn(RefUpdate.Result.LOCK_FAILURE);
    assertThatThrownBy(() -> GitRepository.doRefUpdate(jGitRepo, revWalk, ref, commitId))
            .isInstanceOf(StorageException.class);
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:19,代碼來源:GitRepositoryTest.java

示例6: checkoutBranch

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
private Ref checkoutBranch(File projectDir, String branch)
		throws GitAPIException {
	Git git = this.gitFactory.open(projectDir);
	CheckoutCommand command = git.checkout().setName(branch);
	try {
		if (shouldTrack(git, branch)) {
			trackBranch(command, branch);
		}
		return command.call();
	}
	catch (GitAPIException e) {
		deleteBaseDirIfExists();
		throw e;
	} finally {
		git.close();
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-release-tools,代碼行數:18,代碼來源:GitRepo.java

示例7: RevisionSelector

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
public RevisionSelector(String id, IModel<Project> projectModel, @Nullable String revision, boolean canCreateRef) {
	super(id);
	
	Preconditions.checkArgument(revision!=null || !canCreateRef);

	this.projectModel = projectModel;
	this.revision = revision;		
	if (canCreateRef) {
		Project project = projectModel.getObject();
		canCreateBranch = SecurityUtils.canWrite(project);						
		canCreateTag = SecurityUtils.canCreateTag(project, Constants.R_TAGS);						
	} else {
		canCreateBranch = false;
		canCreateTag = false;
	}
	if (revision != null) {
		Ref ref = projectModel.getObject().getRef(revision);
		branchesActive = ref == null || GitUtils.ref2tag(ref.getName()) == null;
	} else {
		branchesActive = true;
	}
	
	refs = findRefs();
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:25,代碼來源:RevisionSelector.java

示例8: getDefaultBranch

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
@Nullable
public String getDefaultBranch() {
	if (defaultBranchOptional == null) {
		try {
			Ref headRef = getRepository().findRef("HEAD");
			if (headRef != null 
					&& headRef.isSymbolic() 
					&& headRef.getTarget().getName().startsWith(Constants.R_HEADS) 
					&& headRef.getObjectId() != null) {
				defaultBranchOptional = Optional.of(Repository.shortenRefName(headRef.getTarget().getName()));
			} else {
				defaultBranchOptional = Optional.absent();
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	return defaultBranchOptional.orNull();
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:20,代碼來源:Project.java

示例9: getLastCommit

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
public RevCommit getLastCommit() {
	if (lastCommitOptional == null) {
		RevCommit lastCommit = null;
		try {
			for (Ref ref: getRepository().getRefDatabase().getRefs(Constants.R_HEADS).values()) {
				RevCommit commit = getRevCommit(ref.getObjectId(), false);
				if (commit != null) {
					if (lastCommit != null) {
						if (commit.getCommitTime() > lastCommit.getCommitTime())
							lastCommit = commit;
					} else {
						lastCommit = commit;
					}
				}
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		lastCommitOptional = Optional.fromNullable(lastCommit);
	}
	return lastCommitOptional.orNull();
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:23,代碼來源:Project.java

示例10: tags

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
@Override
public List<String> tags() throws GitException {
    try {
        Collection<Ref> refs = buildCommand(Git.lsRemoteRepository()
            .setTags(true)
            .setTimeout(GIT_TRANS_TIMEOUT)
            .setRemote(gitUrl)).call();


        List<Ref> listRefs = Lists.newArrayList(refs);
        listRefs.sort(JGitUtil.REF_COMPARATOR);

        return JGitUtil.simpleRef(refs);
    } catch (GitAPIException e) {
        throw new GitException("Fail to list tags from remote repo", ExceptionUtil.findRootCause(e));
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:18,代碼來源:JGitBasedClient.java

示例11: should_list_existing_repo_from_git_workspace

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
@Test
public void should_list_existing_repo_from_git_workspace() throws Throwable {
    // given: copy exit git to workspace
    ClassLoader classLoader = TestBase.class.getClassLoader();
    URL resource = classLoader.getResource("hello.git");
    File path = new File(resource.getFile());
    FileUtils.copyDirectoryToDirectory(path, gitWorkspace.toFile());

    // when: load repos from git workspace
    List<Repository> repos = gitService.repos();
    Assert.assertEquals(1, repos.size());

    // then:
    Repository helloRepo = repos.get(0);
    Map<String, Ref> tags = helloRepo.getTags();
    Assert.assertEquals(1, tags.size());
    Assert.assertTrue(tags.keySet().contains("v1.0"));
    Assert.assertEquals("hello.git", helloRepo.getDirectory().getName());

    for (Repository repo : repos) {
        repo.close();
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:24,代碼來源:GitServiceTest.java

示例12: fetchTags

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
public static Single<ImmutableMap<String, GitCommitHash>> fetchTags(final String gitURL) {

        Preconditions.checkNotNull(gitURL);

        return Single.fromCallable(() -> {

            // The repository is not actually used, JGit just seems to require it.
            final Repository repository = FileRepositoryBuilder.create(Paths.get("").toFile());
            final Collection<Ref> refs = new LsRemoteCommand(repository)
                .setRemote(gitURL)
                .setTags(true)
                .call();

            final String prefix = "refs/tags/";

            return refs.stream()
                .filter(x -> x.getTarget().getName().startsWith(prefix))
                .collect(ImmutableMap.toImmutableMap(
                    x -> x.getTarget().getName().substring(prefix.length()),
                    x -> GitCommitHash.of((x.getPeeledObjectId() == null ? x.getObjectId() : x.getPeeledObjectId()).getName())));
        });
    }
 
開發者ID:LoopPerfect,項目名稱:buckaroo,代碼行數:23,代碼來源:GitTasks.java

示例13: testInit_nullHeadRefObjectId

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
@Test
public void testInit_nullHeadRefObjectId()
        throws RevisionGeneratorException,
        IOException {

    Repository repo = mock(Repository.class);
    Ref headRef = mock(Ref.class);

    when(git.getRepository()).thenReturn(repo);
    when(repo.isBare()).thenReturn(Boolean.FALSE);
    when(repo.getRef(eq("HEAD"))).thenReturn(headRef);
    when(headRef.getObjectId()).thenReturn(null);

    item.init(git, logger);

    Assert.assertEquals("GetRevision", "SNAPSHOT", item.getRevision());
    Assert.assertEquals("IsDirty", false, item.isDirty());

    verify(git).getRepository();
    verify(repo).isBare();
    verify(repo).getRef(eq("HEAD"));
    verify(logger).warn(eq("The Git repository is initialised, but no commits have been done: Setting revision to SNAPSHOT"));
    verifyNoMoreInteractions(git);
    verifyNoMoreInteractions(repo);
    verifyNoMoreInteractions(logger);
}
 
開發者ID:IG-Group,項目名稱:cdversion-maven-extension,代碼行數:27,代碼來源:GitRevisionGeneratorTest.java

示例14: fetchAndCreateNewRevsWalk

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
public RevWalk fetchAndCreateNewRevsWalk(Repository repository, String branch) throws Exception {
	List<ObjectId> currentRemoteRefs = new ArrayList<ObjectId>();
	for (Ref ref : repository.getAllRefs().values()) {
		String refName = ref.getName();
		if (refName.startsWith(REMOTE_REFS_PREFIX)) {
			currentRemoteRefs.add(ref.getObjectId());
		}
	}
	
	List<TrackingRefUpdate> newRemoteRefs = this.fetch(repository);
	
	RevWalk walk = new RevWalk(repository);
	for (TrackingRefUpdate newRef : newRemoteRefs) {
		if (branch == null || newRef.getLocalName().endsWith("/" + branch)) {
			walk.markStart(walk.parseCommit(newRef.getNewObjectId()));
		}
	}
	for (ObjectId oldRef : currentRemoteRefs) {
		walk.markUninteresting(walk.parseCommit(oldRef));
	}
	walk.setRevFilter(commitsFilter);
	return walk;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:24,代碼來源:GitHelper.java

示例15: createAllRevsWalk

import org.eclipse.jgit.lib.Ref; //導入依賴的package包/類
public RevWalk createAllRevsWalk(Repository repository, String branch) throws Exception {
	List<ObjectId> currentRemoteRefs = new ArrayList<ObjectId>();
	for (Ref ref : repository.getAllRefs().values()) {
		String refName = ref.getName();
		if (refName.startsWith(REMOTE_REFS_PREFIX)) {
			if (branch == null || refName.endsWith("/" + branch)) {
				currentRemoteRefs.add(ref.getObjectId());
			}
		}
	}
	
	RevWalk walk = new RevWalk(repository);
	for (ObjectId newRef : currentRemoteRefs) {
		walk.markStart(walk.parseCommit(newRef));
	}
	walk.setRevFilter(commitsFilter);
	return walk;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:19,代碼來源:GitHelper.java


注:本文中的org.eclipse.jgit.lib.Ref類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。