本文整理匯總了Java中org.eclipse.jgit.lib.Repository.getRef方法的典型用法代碼示例。如果您正苦於以下問題:Java Repository.getRef方法的具體用法?Java Repository.getRef怎麽用?Java Repository.getRef使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jgit.lib.Repository
的用法示例。
在下文中一共展示了Repository.getRef方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupRebaseFlag
import org.eclipse.jgit.lib.Repository; //導入方法依賴的package包/類
private void setupRebaseFlag (Repository repository) throws IOException {
Ref baseRef = repository.getRef(revision);
if (baseRef != null && baseRef.getName().startsWith(Constants.R_REMOTES)) {
StoredConfig config = repository.getConfig();
String autosetupRebase = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION,
null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE);
boolean rebase = ConfigConstants.CONFIG_KEY_ALWAYS.equals(autosetupRebase)
|| ConfigConstants.CONFIG_KEY_REMOTE.equals(autosetupRebase);
if (rebase && !config.getNames(ConfigConstants.CONFIG_BRANCH_SECTION, branchName).isEmpty()) {
config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
ConfigConstants.CONFIG_KEY_REBASE, rebase);
config.save();
}
}
}
示例2: run
import org.eclipse.jgit.lib.Repository; //導入方法依賴的package包/類
@Override
protected void run () throws GitException {
Repository repository = getRepository();
try {
Ref ref = repository.getRef(trackedBranchName);
if (ref == null) {
throw new GitException(MessageFormat.format(Utils.getBundle(SetUpstreamBranchCommand.class)
.getString("MSG_Error_UpdateTracking_InvalidReference"), trackedBranchName)); //NOI18N)
}
String remote = null;
String branchName = ref.getName();
StoredConfig config = repository.getConfig();
if (branchName.startsWith(Constants.R_REMOTES)) {
String[] elements = branchName.split("/", 4);
remote = elements[2];
if (config.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION).contains(remote)) {
branchName = Constants.R_HEADS + elements[3];
setupRebaseFlag(repository);
} else {
// remote not yet set
remote = null;
}
}
if (remote == null) {
remote = "."; //NOI18N
}
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName,
ConfigConstants.CONFIG_KEY_REMOTE, remote);
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName,
ConfigConstants.CONFIG_KEY_MERGE, branchName);
config.save();
} catch (IOException ex) {
throw new GitException(ex);
}
ListBranchCommand branchCmd = new ListBranchCommand(repository, getClassFactory(), false, new DelegatingGitProgressMonitor(monitor));
branchCmd.run();
Map<String, GitBranch> branches = branchCmd.getBranches();
branch = branches.get(localBranchName);
}
示例3: getRepoMetadata
import org.eclipse.jgit.lib.Repository; //導入方法依賴的package包/類
/**
* Fetch all commit metadata from the repo
* @param repoDir repository directory
* @return list of commit metadata
* @throws IOException
* @throws GitAPIException
*/
public static List<CommitMetadata> getRepoMetadata(String repoDir) throws IOException, GitAPIException {
List<CommitMetadata> metadataList = new ArrayList<>();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(repoDir, ".git")).readEnvironment().findGitDir().build();
// Current branch may not be master. Instead of hard coding determine the current branch
String currentBranch = repository.getBranch();
Ref head = repository.getRef("refs/heads/" + currentBranch); // current branch may not be "master"
if (head == null) {
return metadataList;
}
Git git = new Git(repository);
RevWalk walk = new RevWalk(repository);
RevCommit commit = walk.parseCommit(head.getObjectId());
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(commit.getTree());
treeWalk.setRecursive(true);
while (treeWalk.next()) {
String filePath = treeWalk.getPathString();
Iterable<RevCommit> commitLog = git.log().add(repository.resolve(Constants.HEAD)).addPath(filePath).call();
for (RevCommit r : commitLog) {
CommitMetadata metadata = new CommitMetadata(r.getName());
metadata.setFilePath(filePath);
metadata.setFileName(FilenameUtils.getName(filePath));
metadata.setMessage(r.getShortMessage().trim());
// Difference between committer and author
// refer to: http://git-scm.com/book/ch2-3.html
PersonIdent committer = r.getCommitterIdent();
PersonIdent author = r.getAuthorIdent();
metadata.setAuthor(author.getName());
metadata.setAuthorEmail(author.getEmailAddress());
metadata.setCommitter(committer.getName());
metadata.setCommitterEmail(committer.getEmailAddress());
metadata.setCommitTime(committer.getWhen());
metadataList.add(metadata);
}
}
git.close();
return metadataList;
}