Пример #1
0
 protected String doReadJsonChildContent(
     Git git, File rootDir, String branch, String path, String fileNameWildcard, String search)
     throws GitAPIException, IOException {
   checkoutBranch(git, branch);
   File file = getFile(rootDir, path);
   FileFilter filter = FileFilters.createFileFilter(fileNameWildcard);
   boolean first = true;
   StringBuilder buffer = new StringBuilder("{\n");
   List<FileInfo> children = new ArrayList<FileInfo>();
   if (file.isDirectory()) {
     if (file.exists()) {
       File[] files = file.listFiles();
       for (File child : files) {
         if (!isIgnoreFile(child) && child.isFile()) {
           String text = IOHelper.readFully(child);
           if (!Strings.isNotBlank(search) || text.contains(search)) {
             if (first) {
               first = false;
             } else {
               buffer.append(",\n");
             }
             buffer.append("\"");
             buffer.append(child.getName());
             buffer.append("\": ");
             buffer.append(text);
             children.add(FileInfo.createFileInfo(rootDir, child));
           }
         }
       }
     }
   }
   buffer.append("\n}");
   return buffer.toString();
 }
Пример #2
0
 /** Reads the file contents from the currently checked out branch */
 protected FileContents doRead(Git git, File rootDir, String branch, String pathOrEmpty)
     throws IOException, GitAPIException {
   checkoutBranch(git, branch);
   String path = Strings.isBlank(pathOrEmpty) ? "/" : pathOrEmpty;
   File file = getFile(rootDir, path);
   if (file.isFile()) {
     String contents = IOHelper.readFully(file);
     return new FileContents(false, contents, null);
   } else {
     List<FileInfo> children = new ArrayList<FileInfo>();
     if (file.exists()) {
       File[] files = file.listFiles();
       for (File child : files) {
         if (!isIgnoreFile(child)) {
           children.add(FileInfo.createFileInfo(rootDir, child));
         }
       }
     }
     return new FileContents(file.isDirectory(), null, children);
   }
 }
Пример #3
0
  protected CommitInfo doWrite(
      Git git,
      File rootDir,
      String branch,
      String path,
      String contents,
      PersonIdent personIdent,
      String commitMessage)
      throws Exception {
    File file = getFile(rootDir, path);
    file.getParentFile().mkdirs();

    IOHelper.write(file, contents);

    String filePattern = getFilePattern(path);
    AddCommand add = git.add().addFilepattern(filePattern).addFilepattern(".");
    add.call();

    CommitCommand commit =
        git.commit().setAll(true).setAuthor(personIdent).setMessage(commitMessage);
    RevCommit revCommit = commitThenPush(git, branch, commit);
    return createCommitInfo(revCommit);
  }