Skip to content
Open
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
7 changes: 7 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
<!-- Each feature gets its own ## section below. -->
<!-- Only edit YOUR feature's section. Delete it after merging to main. -->

## Fix: git worktree HEAD resolution

- [x] Slice 1: Enable `EnableDotGitCommonDir` in `gitview.New()` so HEAD resolves in worktrees
- [x] Test: `New()` succeeds when called from a git worktree path
- [x] Test: `BranchName()` returns correct branch when called from a worktree
- [x] Test: `GetCommitInfoFromCommitSHA("HEAD", ...)` works from a worktree

## kosli evaluate trail

- [x] Slice 1: Skeleton `evaluate` parent + `evaluate trail` fetches trail JSON
Expand Down
4 changes: 3 additions & 1 deletion internal/gitview/gitView.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const redactedCommitInfoValue = "**REDACTED**"
// 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.PlainOpen(repositoryRoot)
repository, err := git.PlainOpenWithOptions(repositoryRoot, &git.PlainOpenOptions{
EnableDotGitCommonDir: true,
})
if err != nil {
return nil, fmt.Errorf("failed to open git repository at %s: %v", repositoryRoot, err)
}
Expand Down
26 changes: 26 additions & 0 deletions internal/gitview/gitView_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gitview
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"

Expand Down Expand Up @@ -54,6 +55,31 @@ func (suite *GitViewTestSuite) TestNewGitView() {
require.Error(suite.T(), err)
}

func (suite *GitViewTestSuite) TestNewGitViewFromWorktree() {
dirPath := filepath.Join(suite.tmpDir, "repoName")
_, _, err := initializeRepoAndCommit(dirPath, 1)
require.NoError(suite.T(), err)

worktreePath := filepath.Join(suite.tmpDir, "myWorktree")
cmd := exec.Command("git", "worktree", "add", "-b", "worktree-branch", worktreePath)
cmd.Dir = dirPath
output, err := cmd.CombinedOutput()
require.NoError(suite.T(), err, "git worktree add failed: %s", string(output))

gv, err := New(worktreePath)
require.NoError(suite.T(), err)
require.NotNil(suite.T(), gv)

branchName, err := gv.BranchName()
require.NoError(suite.T(), err)
require.Equal(suite.T(), "worktree-branch", branchName)

commitInfo, err := gv.GetCommitInfoFromCommitSHA("HEAD", true, []string{})
require.NoError(suite.T(), err)
require.NotEmpty(suite.T(), commitInfo.Sha1)
require.Equal(suite.T(), "worktree-branch", commitInfo.Branch)
}

func (suite *GitViewTestSuite) TestCommitsBetween() {
for i, t := range []struct {
name string
Expand Down
Loading