Clone a git repository into an InMemoryRepository with JGit

后端 未结 3 1982
温柔的废话
温柔的废话 2020-12-06 07:34

I need to clone an existing git repository into an InMemoryRepository, using JGit, change a file\'s content and push the changes back to the remote repository.<

3条回答
  •  悲哀的现实
    2020-12-06 07:52

    Also, with a small tweak on previous answer:

    • Listing all files in commit
    • Filtering files by extension

      public Function> lastCommitFiles = (extension) -> {
      
      final List paths = new ArrayList<>();
      try {
      
          ...
      
          try (TreeWalk walk = new TreeWalk(inMemoryRepository)) {
              walk.addTree(revTree);
              walk.setRecursive(true);
              walk.setPostOrderTraversal(true);
              while (walk.next()) {
                  if ((extension != null && extension.length() > 0)) {
                      if (walk.getPathString().lastIndexOf(extension) != -1) {
                          paths.add(walk.getPathString());
                      }
                  } else paths.add(walk.getPathString());
              }
          }
          return paths;
      } catch (GitAPIException | IOException e) {
          log.error(e.getMessage());
      }
      
      return paths;
      

      };

提交回复
热议问题