Skip to content

Commit

Permalink
108: update get commits files loop (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: Denis Neverov <dneverov@skilld.cloud>
  • Loading branch information
DeNevero and Denis Neverov authored May 13, 2024
1 parent f307246 commit 1a36376
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,30 @@ func (r *BumperRepo) getModifiedFiles(last bool) ([]string, error) {
return nil, err
}

parentCommit, err := headCommit.Parent(0)
commits, err := r.git.Log(&git.LogOptions{From: headRef.Hash()})
if err != nil {
return nil, err
}

var prevCommit *object.Commit
commitsNum := 0
for {
if commitsNum > 0 {
headCommit = parentCommit
}

headTree, _ := headCommit.Tree()
err = commits.ForEach(func(commit *object.Commit) error {
commitsNum++

parentCommit, err = headCommit.Parent(0)
if err != nil {
return nil, err
// Process last commit.
if prevCommit == nil {
prevCommit = commit
return nil
}

parentTree, _ := parentCommit.Tree()
// Process previous commits.
prevTree, _ := prevCommit.Tree()
currentTree, _ := commit.Tree()

diff, err := parentTree.Diff(headTree)
if err != nil {
return nil, err
diff, diffErr := currentTree.Diff(prevTree)
if diffErr != nil {
return diffErr
}

for _, ch := range diff {
Expand All @@ -121,12 +122,27 @@ func (r *BumperRepo) getModifiedFiles(last bool) ([]string, error) {
}

if last {
break
return storer.ErrStop
}
if strings.TrimSpace(commit.Author.Name) == r.name {
return storer.ErrStop
}

commitsNum++
if strings.TrimSpace(parentCommit.Author.Name) == r.name {
break
prevCommit = commit
return nil
})
if err != nil {
return nil, err
}

if commitsNum == 1 {
headTree, _ := headCommit.Tree()
err = headTree.Files().ForEach(func(file *object.File) error {
modifiedFiles = append(modifiedFiles, file.Name)
return nil
})
if err != nil {
return nil, err
}
}

Expand Down

0 comments on commit 1a36376

Please sign in to comment.