Class GitService

java.lang.Object
edu.university.ecs.lab.common.services.GitService

public class GitService extends Object
Service to perform Git opperations
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Config
     
    private static final int
     
    private static final String
     
    private final org.eclipse.jgit.lib.Repository
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    GitService(String configPath)
    Create a Git service object from a project configuration file
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Method to clone a repository
    private String
    getContentFromTree(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.lib.ObjectId treeId, String filePath)
    Get file data from a file tree
    List<org.eclipse.jgit.diff.DiffEntry>
    getDifferences(String commitOld, String commitNew)
    Method to get differences between old and new commits
    Get head commit for the repository
    Iterable<org.eclipse.jgit.revwalk.RevCommit>
    Get Git log
    org.eclipse.jgit.lib.Repository
    Method to initialize repository from repository name
    private boolean
    isCodeChange(org.eclipse.jgit.diff.DiffEntry diff, org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit oldCommit, org.eclipse.jgit.revwalk.RevCommit newCommit)
    Method to check if a commit difference was a change to the code
    void
    resetLocal(String commitID)
    Method to reset repository to a given commit
    private String
    Remove comments and whitespace from file content
    private void
    Method to check that local directory exists

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EXIT_SUCCESS

      private static final int EXIT_SUCCESS
      See Also:
    • HEAD_COMMIT

      private static final String HEAD_COMMIT
      See Also:
    • config

      private final Config config
    • repository

      private final org.eclipse.jgit.lib.Repository repository
  • Constructor Details

    • GitService

      public GitService(String configPath)
      Create a Git service object from a project configuration file
      Parameters:
      configPath - path to project configuration file
  • Method Details

    • cloneRemote

      public void cloneRemote()
      Method to clone a repository
    • resetLocal

      public void resetLocal(String commitID)
      Method to reset repository to a given commit
      Parameters:
      commitID - commit id to reset to
    • validateLocalExists

      private void validateLocalExists()
      Method to check that local directory exists
    • initRepository

      public org.eclipse.jgit.lib.Repository initRepository()
      Method to initialize repository from repository name
      Returns:
      file repository
    • getDifferences

      public List<org.eclipse.jgit.diff.DiffEntry> getDifferences(String commitOld, String commitNew)
      Method to get differences between old and new commits
      Parameters:
      commitOld - old commit id
      commitNew - new commit id
      Returns:
      list of changes from old commit to new commit
    • isCodeChange

      private boolean isCodeChange(org.eclipse.jgit.diff.DiffEntry diff, org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit oldCommit, org.eclipse.jgit.revwalk.RevCommit newCommit)
      Method to check if a commit difference was a change to the code
      Parameters:
      diff - DiffEntry object
      repository - repository to check
      oldCommit - old commit id
      newCommit - new commit id
      Returns:
      true if difference was a change to the code, false otherwise
    • getContentFromTree

      private String getContentFromTree(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.lib.ObjectId treeId, String filePath)
      Get file data from a file tree
      Parameters:
      repository - repository to check
      treeId - id of the tree to check
      filePath - file to get data from
      Returns:
      data from the file, or an empty string if an error occurs or file is not found
    • stripCommentsAndWhitespace

      private String stripCommentsAndWhitespace(String content)
      Remove comments and whitespace from file content
      Parameters:
      content - string of all file content
      Returns:
      string of file content with whitespace and comments removed
    • getLog

      public Iterable<org.eclipse.jgit.revwalk.RevCommit> getLog()
      Get Git log
      Returns:
      Git log as a list
    • getHeadCommit

      public String getHeadCommit()
      Get head commit for the repository
      Returns:
      commit id of head commit