コード例 #1
0
 public void commit(
     final String fileName,
     final String fileContent,
     final PersonIdent author,
     final PersonIdent committer,
     final String message)
     throws GitException, InterruptedException {
   FilePath file = gitDirPath.child(fileName);
   try {
     file.write(fileContent, null);
   } catch (Exception e) {
     throw new GitException("unable to write file", e);
   }
   git.add(fileName);
   git.setAuthor(author);
   git.setCommitter(committer);
   git.commit(message);
 }
コード例 #2
0
 /**
  * Commit fileName to this git repository
  *
  * @param fileName name of file to create
  * @throws GitException
  * @throws InterruptedException
  */
 protected void commitNewFile(final String fileName) throws GitException, InterruptedException {
   File newFile = new File(testGitDir, fileName);
   assert !newFile.exists(); // Not expected to use commitNewFile to update existing file
   PrintWriter writer = null;
   try {
     writer = new PrintWriter(newFile, "UTF-8");
     writer.println("A file named " + fileName);
     writer.close();
     testGitClient.add(fileName);
     testGitClient.commit("Added a file named " + fileName);
   } catch (FileNotFoundException notFound) {
     throw new GitException(notFound);
   } catch (UnsupportedEncodingException unsupported) {
     throw new GitException(unsupported);
   } finally {
     if (writer != null) {
       writer.close();
     }
   }
 }