Skip to content

Commit

Permalink
At limit commit read file content at previous commit
Browse files Browse the repository at this point in the history
When processing the earliest commit of the commit history, no data from the file
outside of the history is present. This means that no changes can be calculated
for the first commit.

This issue was likely always present but surfaced by the introduction of the
`--global-revisions` flag. Previously, the issue would only appear when reaching
the commit that introduced a file.

To address the problem, we now read the file's content at the previous commit in the
repo.

This still does not resolve the problem caused by a file simply not being
present at the previous commit.
  • Loading branch information
felixjung authored and daveshanley committed Oct 22, 2024
1 parent e103ec0 commit 14fddcb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions git/read_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
var oldBits, newBits []byte
if len(commitHistory) == c+1 {
newBits = commitHistory[c].Data

// Obtain data from the previous commit
var err []error
oldBits, err = readFile(commitHistory[c].RepoDirectory, fmt.Sprintf("%s~1", commitHistory[c].Hash), commitHistory[c].FilePath)
if err != nil {
return nil, err
}
} else {
oldBits = commitHistory[c+1].Data
commitHistory[c].OldData = oldBits
Expand Down

0 comments on commit 14fddcb

Please sign in to comment.