Skip to content

Commit

Permalink
Start impl git diff
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Feb 2, 2025
1 parent d502603 commit 915e9ec
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions utils/gitutils/gitmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,33 @@ func (gm *GitManager) IsClean() (bool, error) {
return status.IsClean(), nil
}


func (gm *GitManager) Diff(reference string) (err error) {
// Get the current branch
currentBranch, err := gm.localGitRepository.Head()
if err != nil {
return
}
// Get the commit object of the current branch
currentCommit, err := gm.localGitRepository.CommitObject(currentBranch.Hash())
if err != nil {
return
}
// Get the commit object of the reference
referenceCommit, err := gm.localGitRepository.CommitObject(currentCommit.Hash)
if err != nil {
return
}
// Get the diff between the current branch and the reference
diff, err := currentCommit.Patch(referenceCommit)
if err != nil {
return
}
// Print the diff
fmt.Println(diff)
return
}

// Detect git information
func (gm *GitManager) GetGitContext() (gitInfo *services.XscGitInfoContext, err error) {
remoteUrl, err := getRemoteUrl(gm.remote)
Expand Down

0 comments on commit 915e9ec

Please sign in to comment.