Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

jgit clone in memory

    // sample usage
    private void loadFromGit() throws Exception {
        ObjectLoader loader = loadRemote("https://github.com/msangel/promisified-resource-loader", "master", "README.md");
        loader.copyTo(System.out);
    }

    private ObjectLoader loadRemote(String uri, String branch, String filename) throws Exception {
        DfsRepositoryDescription repoDesc = new DfsRepositoryDescription();
        InMemoryRepository repo = new InMemoryRepository(repoDesc);
        Git git = new Git(repo);
        git.fetch()
                .setRemote(uri)
                .setRefSpecs(new RefSpec("+refs/heads/*:refs/heads/*"))
                .call();
        repo.getObjectDatabase();
        ObjectId lastCommitId = repo.resolve("refs/heads/"+ branch);
        RevWalk revWalk = new RevWalk(repo);
        RevCommit commit = revWalk.parseCommit(lastCommitId);
        RevTree tree = commit.getTree();
        TreeWalk treeWalk = new TreeWalk(repo);
        treeWalk.addTree(tree);
        treeWalk.setRecursive(true);
        treeWalk.setFilter(PathFilter.create(filename));
        if (!treeWalk.next()) {
            return null;
        }
        ObjectId objectId = treeWalk.getObjectId(0);
        ObjectLoader loader = repo.open(objectId);
        return loader;
    }
Comment

PREVIOUS NEXT
Code Example
Java :: code wars jaden casting java 
Java :: array srting line by line in textview android 
Java :: what is getService() in java 
Java :: windows menu in java swing ausscahlten 
Java :: how to make character in jframe 
Java :: in java write a code that suppose the following input is supplied to the program: 9 Then, the output should be: 12096 (99+999+9999+999) 
Sql :: mysql disable foreign key checks 
Sql :: mysql how to truncate table with foreign keys 
Sql :: change nls_date_format 
Sql :: mysql current running queries 
Sql :: create database mysql utf8 
Sql :: mysql get date difference in hours 
Sql :: mysql find tables with name 
Sql :: print in pl sql 
Sql :: oracle list columns 
Sql :: wilayah indonesia sql 
Sql :: show databases in sql server 
Sql :: start mysql server linux terminal 
Sql :: string to date postgres 
Sql :: get schema of table sql 
Sql :: Mysql query add column with default string value 
Sql :: sql concate two columns first and last 
Sql :: sqlite3 now 
Sql :: list mysql users 
Sql :: mysql remove unique constraint 
Sql :: name of today sql 
Sql :: mysql loop insert 
Sql :: sql pick random row 
Sql :: set sequence value oracle 
Sql :: alert table name mysql 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =