Exemplo n.º 1
0
 /**
  * Gets type of git object.
  *
  * @param gitObject revision object e.g. commit, tree, blob, tag.
  * @return type of git object
  */
 private String getRevisionType(String gitObject) throws GitException {
   EmptyGitCommand command =
       nativeGit
           .createEmptyGitCommand()
           .setNextParameter("cat-file")
           .setNextParameter("-t")
           .setNextParameter(gitObject);
   command.execute();
   return command.getText();
 }
Exemplo n.º 2
0
  /**
   * Gets branch ref by branch name.
   *
   * @param branchName existing git branch name
   * @return ref to the branch
   * @throws GitException when it is not possible to get branchName ref
   */
  private String getBranchRef(String branchName) throws GitException {
    EmptyGitCommand command = nativeGit.createEmptyGitCommand();
    command.setNextParameter("show-ref").setNextParameter(branchName).execute();
    final String output = command.getText();

    if (output.isEmpty()) {
      throw new GitException("Error getting reference of branch.");
    }

    return output.split(" ")[1];
  }
Exemplo n.º 3
0
 /**
  * Ensure existence repository root directory inside working directory and in our virtual file
  * system
  *
  * @throws GitException if git root folder is not in working directory
  */
 void ensureExistenceRepoRootInWorkingDirectory() throws GitException {
   if (isInsideWorkTree()) {
     final EmptyGitCommand emptyGitCommand = nativeGit.createEmptyGitCommand();
     emptyGitCommand.setNextParameter("rev-parse").setNextParameter("--git-dir").execute();
     final String gitDir = emptyGitCommand.getText();
     // here we check that git repo inside our file system mount point
     if (!gitDir.startsWith(mountRoot.getAbsolutePath()) && !gitDir.equals(".git")) {
       throw new GitException("Project is not a git repository.");
     }
   } else {
     throw new GitException("Project is not a git repository.");
   }
 }
Exemplo n.º 4
0
  /**
   * Ensure existence repository root directory inside working directory
   *
   * @throws GitException if git root folder is not in working directory
   */
  boolean isInsideWorkTree() throws GitException {
    final EmptyGitCommand emptyGitCommand = nativeGit.createEmptyGitCommand();
    // command "rev-parse --is-inside-work-tree" returns true/false
    try {
      emptyGitCommand
          .setNextParameter("rev-parse")
          .setNextParameter("--is-inside-work-tree")
          .execute();

      final String output = emptyGitCommand.getText();
      return Boolean.valueOf(output);
    } catch (GitException ge) {
      String msg = ge.getMessage();
      if (msg != null && notInGitRepoErrorPattern.matcher(msg).matches()) {
        return false;
      }
      throw ge;
    }
  }