本文整理匯總了Java中org.eclipse.jgit.storage.file.FileRepositoryBuilder類的典型用法代碼示例。如果您正苦於以下問題:Java FileRepositoryBuilder類的具體用法?Java FileRepositoryBuilder怎麽用?Java FileRepositoryBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileRepositoryBuilder類屬於org.eclipse.jgit.storage.file包,在下文中一共展示了FileRepositoryBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRepo
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
/**
*
* @param repoPath
* @return
* @throws IOException
*/
public static Repository getRepo(String repoPath) throws IOException {
Repository repo;
File repoFile = new File(repoPath);
if (repoFile.exists()) {
// Open an existing repository
repo = new FileRepositoryBuilder()
.setGitDir(new File(repoPath))
.build();
} else {
// Create a new repository
repo = FileRepositoryBuilder.create(
new File(repoPath));
repo.create(true);
}
System.out.println(repo.getDirectory());
return repo;
}
示例2: GitInfo
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
public GitInfo(File repository_file) throws IOException {
if (repository_file == null) {
throw new NullPointerException("\"repository_file\" can't to be null");
}
if (repository_file.exists() == false) {
throw new IOException("Can't found \"" + repository_file + "\"");
}
if (repository_file.isDirectory() == false) {
throw new IOException("\"" + repository_file + "\" is not a directory");
}
try {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
repository = builder.setGitDir(repository_file).readEnvironment().findGitDir().build();
if (repository.getBranch() == null) {
throw new FileNotFoundException("Can't found branch in \"" + repository_file + "\"");
}
branch = repository.getBranch();
commit = repository.getRef(Constants.HEAD).getObjectId().abbreviate(8).name();
} catch (Exception e) {
throw new IOException("Can't load git repository \"" + repository_file + "\"");
}
}
示例3: fetchTags
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的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())));
});
}
示例4: init
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
/**
* Prepare common variables to access the git repository.
*
* @throws IOException if a disk error occurred
*/
@Before
public void init() throws IOException {
repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
git = new Git(repository);
versionCalculator = GitVersionCalculator
.location(scenario.getRepositoryLocation())
.setMavenLike(true)
.setQualifierBranchingPolicies(
BranchingPolicy.ignoreBranchName("master"),
BranchingPolicy.fixedBranchName("develop"),
new BranchingPolicy("release/(.*)", Collections.singletonList(BranchNameTransformations.IGNORE.name())),
new BranchingPolicy("feature/(.*)", Arrays.asList(
BranchNameTransformations.REMOVE_UNEXPECTED_CHARS.name(),
BranchNameTransformations.LOWERCASE_EN.name())
)
)
.setUseDefaultBranchingPolicy(false);
// reset the head to master
unchecked(() -> git.checkout().setName("master").call());
}
示例5: init
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
/**
* Prepare common variables to access the git repository.
*
* @throws IOException if a disk error occurred
*/
@Before
public void init() throws IOException {
repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
git = new Git(repository);
versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation());
versionCalculator.setMavenLike(false);
versionCalculator.setAutoIncrementPatch(true);
versionCalculator.setUseGitCommitId(true);
versionCalculator.setUseLongFormat(false); // without using the new format
versionCalculator.setGitCommitIdLength(8);
versionCalculator.setUseDistance(false);
// reset the head to master
unchecked(() -> git.checkout().setName("master").call());
}
示例6: init
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
public void init() throws IOException, GitAPIException {
File gitFolder = new File(gitPath);
File gitDB = new File(gitFolder, ".git");
if (gitDB.exists() && gitDB.isDirectory()) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(gitDB)
.readEnvironment()
.findGitDir()
.build();
git = new Git(repository);
} else {
CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setURI(gitUrl);
cloneCommand.setDirectory(gitFolder);
cloneCommand.setTransportConfigCallback(sshTransportConfigCallback);
git = cloneCommand.call();
}
}
示例7: getProjectList
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
public List<String> getProjectList(String projectName){
FileRepositoryBuilder builder = new FileRepositoryBuilder();
List list= new ArrayList();
try {
log.debug("errororororoor123 "+ "\n");
Repository repository = builder
.readEnvironment() // scan environment GIT_* variables
.setGitDir(new File("C:/test0101/" + projectName +"/.git")) // scan up the file system tree
.build();
DirCache index = DirCache.read(repository);
ObjectLoader loader = null;
log.debug("DirCache has " + index.getEntryCount() + " items");
for (int i = 0; i < index.getEntryCount(); i++) {
log.debug(index.getEntry(i).getPathString()+ "\n");
list.add(index.getEntry(i).getPathString());
}
} catch (IOException e) {
log.debug("errororororoor "+ "\n");
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
示例8: commitFiles
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
public static void commitFiles(ProjectOperation operation, ParameterValues arguments, File root,
RugResolver resolver) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
try (Repository repository = builder.setGitDir(new File(root, ".git")).readEnvironment()
.findGitDir().build()) {
try (Git git = new Git(repository)) {
log.info("Committing to git repository at " + git.getRepository().getDirectory());
git.add().addFilepattern(".").call();
RevCommit commit = git.commit().setAll(true)
.setMessage(String.format("%s\n\n```\n%s```",
StringUtils.capitalize(operation.description()),
new ProvenanceInfoWriter().write(operation, arguments,
Constants.cliClient(), resolver)))
.setAuthor("Atomist", "[email protected]").call();
log.info("Committed changes to git repository (%s)", commit.abbreviate(7).name());
}
}
catch (IllegalStateException | IOException | GitAPIException e) {
throw new RunnerException(e);
}
}
示例9: getCommitsToCheck
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
private static List<RevCommit> getCommitsToCheck() throws Exception {
final List<RevCommit> commits;
final Repository repo = new FileRepositoryBuilder().findGitDir().build();
try {
final RevCommitsPair revCommitsPair = resolveRevCommitsPair(repo);
if (COMMITS_RESOLUTION_MODE == CommitsResolutionMode.BY_COUNTER) {
commits = getCommitsByCounter(revCommitsPair.getFirst());
commits.addAll(getCommitsByCounter(revCommitsPair.getSecond()));
}
else {
commits = getCommitsByLastCommitAuthor(revCommitsPair.getFirst());
commits.addAll(getCommitsByLastCommitAuthor(revCommitsPair.getSecond()));
}
}
finally {
repo.close();
}
return commits;
}
示例10: GitRepository
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
public GitRepository(File location) throws GitRepoException {
this.location = Objects.requireNonNull(location);
if ( !isGitRepo(location)) {
throw new GitRepoException("Git repository not found at " + location);
}
File gitDir =
GIT_FOLDER_NAME.equals(location.getName()) ? location : new File(location, GIT_FOLDER_NAME);
try {
repo = new FileRepositoryBuilder()
.setGitDir(gitDir)
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
git = new Git(repo);
} catch (IOException e) {
e.printStackTrace();
}
}
示例11: createId
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
static String createId(File repositoryDirectory) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.readEnvironment();
builder.findGitDir(repositoryDirectory);
File gitDir = builder.getGitDir();
if (gitDir == null) {
String message = MessageFormat.format(
"No git repository found at {0}", repositoryDirectory);
throw new GitRepositoryException(message);
}
try {
return gitDir.getCanonicalPath();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例12: getGitRepository
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
public GitRepository getGitRepository(File repositoryDirectory) {
String repositoryId = GitRepository.createId(repositoryDirectory);
GitRepository gitRepository = repositoryData.get(repositoryId);
if (gitRepository == null) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.readEnvironment();
builder.findGitDir(repositoryDirectory);
try {
Repository repository = builder.build();
gitRepository = new GitRepository(repository);
repositoryData.put(gitRepository.getId(), gitRepository);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
return gitRepository;
}
示例13: getRepository
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public Optional<Repository> getRepository(final Project project) {
final IProject eclipseProject = getEclipseProject(project);
if (eclipseProject.exists()) {
try {
final Optional<File> gitFolder = getGitFolder(eclipseProject);
if (gitFolder.isPresent()) {
final org.eclipse.jgit.lib.Repository repository = new FileRepositoryBuilder().setGitDir(gitFolder.get()).readEnvironment().findGitDir().build();
return Optional.of(JGitRepository.of(repository));
}
}
catch (final IOException e) {}
}
return Optional.empty();
}
示例14: openRepository
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
public void openRepository() throws IOException, GitAPIException,
InvalidRemoteException, TransportException {
// Now open the created repository
FileRepositoryBuilder builder = new FileRepositoryBuilder();
String directory = System.getProperty("user.home") + Properties.SEPARATOR + "TestGit\\";///.git
if(new File(directory).mkdir() || new File(directory).exists()){
directory = directory + "/.git";
repository = builder
.setGitDir(
new File(
directory)).readEnvironment() // scan
// environment
// GIT_*
// variables
.findGitDir() // scan up the file system tree
.build();
}else System.out.println("Error during repository clonage. Permission denied for creating files at user home");
}
示例15: doPull
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; //導入依賴的package包/類
protected void doPull(File gitFolder, CredentialsProvider cp, String branch, PersonIdent personIdent, UserDetails userDetails) {
try {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(gitFolder)
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
Git git = new Git(repository);
File projectFolder = repository.getDirectory();
StoredConfig config = repository.getConfig();
String url = config.getString("remote", userDetails.getRemote(), "url");
if (Strings.isNullOrBlank(url)) {
LOG.warn("No remote repository url for " + branch + " defined for the git repository at " + projectFolder.getCanonicalPath() + " so cannot pull");
//return;
}
String mergeUrl = config.getString("branch", branch, "merge");
if (Strings.isNullOrBlank(mergeUrl)) {
LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at " + projectFolder.getCanonicalPath() + " so not doing a pull");
//return;
}
LOG.debug("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: " + url);
PullCommand pull = git.pull();
GitHelpers.configureCommand(pull, userDetails);
pull.setRebase(true).call();
} catch (Throwable e) {
LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage() + ". This exception is ignored.", e);
}
}