Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/gitview/gitView.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gitview

import (
"errors"
"fmt"
"net/url"
"strings"
Expand Down Expand Up @@ -45,13 +46,26 @@ type GitView struct {

const redactedCommitInfoValue = "**REDACTED**"

// TODO: remove this guard once go-git supports sha256 (v6) and the Kosli backend accepts sha256 commits.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking comment:
Do we track these somehow?
Otherwise, I fear they just become noise over time. 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but I do get it highlighted in my editor and sometimes would grep for those 😅


// ErrUnsupportedObjectFormat is returned by New for a repository using the sha256 object format.
var ErrUnsupportedObjectFormat = errors.New("the repository uses the sha256 object format, which the Kosli CLI does not support yet")

func isUnsupportedObjectFormat(err error) bool {
return (errors.Is(err, git.ErrUnsupportedExtensionRepositoryFormatVersion) || errors.Is(err, git.ErrUnknownExtension)) &&
strings.Contains(err.Error(), "objectformat")
}

// New opens a git repository from the given path. It detects if the
// repository is bare or a normal one. If the path doesn't contain a valid
// repository ErrRepositoryNotExists is returned
func New(repositoryRoot string) (*GitView, error) {
repository, err := git.PlainOpenWithOptions(repositoryRoot, &git.PlainOpenOptions{
EnableDotGitCommonDir: true,
})
if isUnsupportedObjectFormat(err) {
return nil, fmt.Errorf("failed to open git repository at %s: %w (%v)", repositoryRoot, ErrUnsupportedObjectFormat, err)
}
if err != nil {
return nil, fmt.Errorf("failed to open git repository at %s: %v", repositoryRoot, err)
}
Expand Down
12 changes: 12 additions & 0 deletions internal/gitview/gitView_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ func (suite *GitViewTestSuite) TestNewGitView() {

_, err = New(filepath.Join(suite.tmpDir, "non-existing"))
require.Error(suite.T(), err)
require.NotErrorIs(suite.T(), err, ErrUnsupportedObjectFormat)
}

func (suite *GitViewTestSuite) TestNewGitViewSha256Repo() {
dirPath := filepath.Join(suite.tmpDir, "sha256Repo")
cmd := exec.Command("git", "init", "--object-format=sha256", dirPath)
output, err := cmd.CombinedOutput()
require.NoError(suite.T(), err, "git init failed: %s", string(output))

_, err = New(dirPath)
require.ErrorIs(suite.T(), err, ErrUnsupportedObjectFormat)
require.Contains(suite.T(), err.Error(), "sha256")
}

func (suite *GitViewTestSuite) TestNewGitViewFromWorktree() {
Expand Down
Loading