本文整理汇总了Java中org.eclipse.jgit.internal.storage.file.FileRepository类的典型用法代码示例。如果您正苦于以下问题:Java FileRepository类的具体用法?Java FileRepository怎么用?Java FileRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileRepository类属于org.eclipse.jgit.internal.storage.file包,在下文中一共展示了FileRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasAnyAccount
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
public boolean hasAnyAccount() throws IOException {
File path = getPath();
if (path == null) {
return false;
}
try (Repository repo = new FileRepository(path)) {
return Accounts.hasAnyAccount(repo);
}
}
示例2: LambdaConfig
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
private LambdaConfig() {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("env.properties")) {
this.props.load(is);
this.repository = new FileRepository(new File(System.getProperty("java.io.tmpdir"), "s3"));
}
catch (IOException e) {
throw new IllegalArgumentException(e);
}
overwriteWithSystemProperty(ENV_BRANCH);
overwriteWithSystemProperty(ENV_BUCKET);
overwriteWithSystemProperty(ENV_GITHUB);
this.remote = new Remote(Constants.DEFAULT_REMOTE_NAME);
this.branch = new Branch(props.getProperty(ENV_BRANCH, Constants.MASTER));
this.authentication = new SecureShellAuthentication(new Bucket(props.getProperty(ENV_BUCKET)), client);
}
示例3: pullRepo
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
@Override
public PullResult pullRepo(File repoDir) throws SysException {
try {
Repository repository = new FileRepository(repoDir.getAbsolutePath() + "/.git");
Git git = new Git(repository);
PullCommand pull = git.pull();
String user = config.getRepo("username");
String passwd = config.getRepo("password");
if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(passwd)) {
UsernamePasswordCredentialsProvider upcp = new UsernamePasswordCredentialsProvider(user, passwd);
pull.setCredentialsProvider(upcp);
}
PullResult result = pull.call();
return result;
} catch (Exception e) {
throw new SysException(e);
}
}
示例4: main
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
public static void main(String[] args) throws IOException, GitAPIException {
Repository repo = new FileRepository(Consts.META_REPO_PATH + ".git");
// get a list of all known heads, tags, remotes, ...
Collection<Ref> allRefs = repo.getAllRefs().values();
// a RevWalk allows to walk over commits based on some filtering that is defined
try (RevWalk revWalk = new RevWalk(repo)) {
for (Ref ref : allRefs) {
revWalk.markStart(revWalk.parseCommit(ref.getObjectId()));
}
System.out.println("Walking all commits starting with " + allRefs.size() + " refs: " + allRefs);
int count = 0;
for (RevCommit commit : revWalk) {
System.out.println("Commit: " + commit);
count++;
}
System.out.println("Had " + count + " commits");
}
}
示例5: containsGitRepo
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
/**
* Tells if the given filesystem directory contains a valid git repository.
*
* @param dir
* a {@link Path} to check
* @return {@code true} if the given {@code dir} contains a valid git repository; {@code false} otherwise.
*/
private static boolean containsGitRepo(Path dir) {
Path gitDir = dir.resolve(".git");
if (!Files.exists(gitDir)) {
return false;
} else {
try (FileRepository repo = new FileRepository(gitDir.toFile())) {
return repo.getObjectDatabase().exists();
} catch (IOException e) {
log.warn(String.format("Could not check if [%s] contains a git repository", dir), e);
/*
* We could perhaps throw e out of this method rather than return false. Returning false sounds as a
* better idea in case the repo is somehow damaged.
*/
return false;
}
}
}
示例6: returnsCurrentCommitForNonEmptyRepos
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
@Test
public void returnsCurrentCommitForNonEmptyRepos() throws Exception {
Git git = emptyRepo();
FileRepository repository = (FileRepository) git.getRepository();
File dir = repository.getDirectory();
FileUtils.writeStringToFile(new File(dir, "file1"), "Hello", "UTF-8");
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit")
.setAuthor(new PersonIdent("Author Test", "[email protected]"))
.call();
FileUtils.writeStringToFile(new File(dir, "file2"), "Hello too", "UTF-8");
git.add().addFilepattern(".").call();
git.commit().setMessage("Second commit")
.setAuthor(new PersonIdent("Second contributor", "[email protected]"))
.call();
JSONObject actual = GitCommit.fromHEAD(git).toJSON();
JSONAssert.assertEquals("{" +
"author: 'Second contributor', message: 'Second commit'" +
"}", actual, JSONCompareMode.LENIENT);
assertThat(actual.getLong("date"), Matchers.greaterThanOrEqualTo(System.currentTimeMillis() - 1000));
assertThat(actual.getString("id"), actual.getString("id").length(), is("3688d7063d2d647e3989d62d9770d0dfd0ce3c25".length()));
}
示例7: getObjectFiles
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
private SortedSet<String> getObjectFiles(Project.NameKey project) throws Exception {
SortedSet<String> files = new TreeSet<>();
try (Repository repo = repoManager.openRepository(project)) {
Files.walkFileTree(
((FileRepository) repo).getObjectDatabase().getDirectory().toPath(),
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
String name = file.getFileName().toString();
if (!attrs.isDirectory() && !name.endsWith(".pack") && !name.endsWith(".idx")) {
files.add(name);
}
return FileVisitResult.CONTINUE;
}
});
}
return files;
}
示例8: JGitOperator
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
public JGitOperator(String repositoryPath) {
try {
// need to verify repo was created successfully - this is not enough
/*if(!repositoryPath.contains("\\.git") && !repositoryPath.equals("."))
{
repositoryPath=repositoryPath.concat("\\.git");
}*/
_repo = new FileRepository(repositoryPath);
_git = new Git(_repo);
} catch (IOException e) {
throw new RuntimeException(String.format(
"Failed creating git repository for path [%s]",
repositoryPath), e);
}
}
示例9: gitPull
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
/**
* Execute git pull command on the given repository.
* It populates an ArrayList with all the updated files.
* @param localPath The path where the project is.
* @return Returns true if you should update plugins, false otherwise.
*/
private boolean gitPull(File localPath) {
try {
Repository localRepo = new FileRepository(localPath.getAbsolutePath() + "/.git");
git = new Git(localRepo);
populateDiff();
if(!pluginsToUpdate.isEmpty()){
PullCommand pullCmd = git.pull();
pullCmd.call();
return true;
}
else{
return false;
}
} catch (GitAPIException | IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
return true;
}
示例10: gitPull
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
/**
* Execute git pull command on the given repository.
* It populates an ArrayList with all the updated files.
* @param localPath The path where the project is.
* @return Returns true if you should update plugins, false otherwise.
*/
private boolean gitPull(File localPath) {
try {
Repository localRepo = new FileRepository(localPath.getAbsolutePath() + "/.git");
git = new Git(localRepo);
if(populateDiff()){
PullCommand pullCmd = git.pull();
pullCmd.call();
return true;
}
else{
return false;
}
} catch (GitAPIException | IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
return true;
}
示例11: cloneBranch
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
public String cloneBranch(String projectName, String branchName) throws IOException, GitAPIException {
String repoPath = LOCAL_PATH + "\\" + projectName; // + "/" + branchName;
System.out.println("Initializing git object for project: " + projectName + " at path: " + repoPath);
try {
Repository localRepo = new FileRepository(repoPath + "/.git");
GitInstance newGitObject = new GitInstance(projectName + "_" + branchName, new Git(localRepo));
storedRepos.add(newGitObject);
} catch (IOException e) {
e.printStackTrace();
}
String remotePath = REPO_URL + projectName + ".git";
System.out.println("branchName - " + branchName);
String branchPath = LOCAL_PATH + "\\" + projectName;
System.out.println("Cloning branch [" + branchName + "] to path [" + branchPath + "]");
// createOrCleanDir(branchPath);
File branchFolder = new File(branchPath);
if(!branchFolder.exists()) {
Git.cloneRepository().setURI(remotePath)
.setDirectory(branchFolder)
.setBranch(branchName).call();
}
return branchPath;
}
示例12: cloneBranch
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
public String cloneBranch(String projectName, String branchName) throws IOException, GitAPIException {
String repoPath = localPath + "/" + projectName + "/" + branchName;
System.out.println("Initializing git object for project: " + projectName + " at path: " + repoPath);
try {
Repository localRepo = new FileRepository(repoPath + "/.git");
GitInstance newGitObject = new GitInstance(projectName + "_" + branchName, new Git(localRepo));
storedRepos.add(newGitObject);
} catch (IOException e) {
e.printStackTrace();
}
String remotePath = "https://github.com/1forintos/" + projectName + ".git";
System.out.println("branchName - " + branchName);
String branchPath = localPath + "/" + projectName + "/" + branchName;
System.out.println("Cloning branch [" + branchName + "] to path [" + branchPath + "]");
// createOrCleanDir(branchPath);
File branchFolder = new File(branchPath);
if(!branchFolder.exists()) {
Git.cloneRepository().setURI(remotePath)
.setDirectory(branchFolder)
.setBranch(branchName).call();
}
return branchPath;
}
示例13: getGit
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
private Git getGit() throws IOException, IllegalArgumentException
{
if (localFolder == null)
{
throw new IllegalArgumentException("localFolder has not yet been set - please call setRootLocation(...)");
}
if (!localFolder.isDirectory())
{
log.error("The passed in local folder '{}' didn't exist", localFolder);
throw new IllegalArgumentException("The localFolder must be a folder, and must exist");
}
File gitFolder = new File(localFolder, ".git");
if (!gitFolder.isDirectory())
{
log.error("The passed in local folder '{}' does not appear to be a git repository", localFolder);
throw new IllegalArgumentException("The localFolder does not appear to be a git repository");
}
return new Git(new FileRepository(gitFolder));
}
示例14: isCloned
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean isCloned(final GitRepository repository) throws RepositoryException {
try {
final FileRepository fileRepository = getFileRepository(repository);
for (final RemoteConfig remoteConfig : RemoteConfig.getAllRemoteConfigs(fileRepository.getConfig())) {
for (final URIish uri : remoteConfig.getURIs()) {
if (uri.equals(new URIish(repository.getUri()))) {
return true;
}
}
}
} catch (final URISyntaxException urise) {
throw new RepositoryException("URI syntax exception, please check that the syntax is correct", urise);
}
logger.debug("Remote repository is not yet cloned: " + repository.getUri());
return false;
}
示例15: getBranchHeads
import org.eclipse.jgit.internal.storage.file.FileRepository; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Map<String, GitCommitKey> getBranchHeads(final GitRepository repository) throws RepositoryException {
Validate.notNull(repository, "repository must not be null");
final FileRepository fileRepository = getFileRepository(repository);
try {
final List<Ref> branchRefs = Git.wrap(fileRepository)
.branchList()
.call();
final Map<String, GitCommitKey> branches = new HashMap<String, GitCommitKey>();
final RevWalk walk = new RevWalk(fileRepository);
for (final Ref branch : branchRefs) {
final RevCommit revCommit = walk.parseCommit(branch.getObjectId());
branches.put(branch.getName().substring("refs/heads/".length()),
new GitCommitKey(branch.getObjectId().getName(), revCommit.getCommitTime()));
}
return branches;
} catch (final IOException ioe) {
throw new RepositoryException("IO error while scanning branch tips", ioe);
} catch (final GitAPIException e) {
throw new RuntimeException(e);
}
}