Class GitService
java.lang.Object
edu.university.ecs.lab.common.services.GitService
Service to perform Git opperations
-
Field Summary
-
Constructor Summary
ConstructorDescriptionGitService
(String configPath) Create a Git service object from a project configuration file -
Method Summary
Modifier and TypeMethodDescriptionvoid
Method to clone a repositoryprivate String
getContentFromTree
(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.lib.ObjectId treeId, String filePath) Get file data from a file treeList<org.eclipse.jgit.diff.DiffEntry>
getDifferences
(String commitOld, String commitNew) Method to get differences between old and new commitsGet head commit for the repositoryIterable<org.eclipse.jgit.revwalk.RevCommit>
getLog()
Get Git logorg.eclipse.jgit.lib.Repository
Method to initialize repository from repository nameprivate 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 codevoid
resetLocal
(String commitID) Method to reset repository to a given commitprivate String
stripCommentsAndWhitespace
(String content) Remove comments and whitespace from file contentprivate void
Method to check that local directory exists
-
Field Details
-
EXIT_SUCCESS
private static final int EXIT_SUCCESS- See Also:
-
HEAD_COMMIT
- See Also:
-
config
-
repository
private final org.eclipse.jgit.lib.Repository repository
-
-
Constructor Details
-
GitService
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
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
Method to get differences between old and new commits- Parameters:
commitOld
- old commit idcommitNew
- 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 objectrepository
- repository to checkoldCommit
- old commit idnewCommit
- 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 checktreeId
- id of the tree to checkfilePath
- file to get data from- Returns:
- data from the file, or an empty string if an error occurs or file is not found
-
stripCommentsAndWhitespace
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
Get Git log- Returns:
- Git log as a list
-
getHeadCommit
Get head commit for the repository- Returns:
- commit id of head commit
-