From 8d5c8cda665023fa1e0139b6d84a5d806fe18e60 Mon Sep 17 00:00:00 2001 From: Felix Jung Date: Fri, 11 Oct 2024 15:51:25 +0200 Subject: [PATCH] Fail gracefully when readFile fails --- git/read_local.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/git/read_local.go b/git/read_local.go index 256a448..e07d71f 100644 --- a/git/read_local.go +++ b/git/read_local.go @@ -216,12 +216,10 @@ func BuildCommitChangelog(commitHistory []*model.Commit, 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 - } + // Obtain data from the previous commit and fail gracefully, if git + // errors. This might happen when the file does not exist in the git + // history. + oldBits, _ = readFile(commitHistory[c].RepoDirectory, fmt.Sprintf("%s~1", commitHistory[c].Hash), commitHistory[c].FilePath) } else { oldBits = commitHistory[c+1].Data commitHistory[c].OldData = oldBits