Skip to content

Worktree.Status() fails with index decoder: invalid checksum in a specific repository, works elsewhere #1868

@con-cat

Description

@con-cat

Bug Description

When I run Worktree.Status() in a specific repository it fails with the error index decoder: invalid checksum.

This doesn't happen in a newly-initialised repo in a new directory on the same machine - it's specific to this one. I'm not using worktrees with this repository, and I don't get errors when running equivalent commands in the git CLI .

I've included code to reproduce the issue below. The repo is private and contains proprietary code so I can't share it directly. Can you suggest diagnosis steps to find the issue in the repo?

go-git Version

v6.0.0-20260225231818-d48496f29db9

Steps to Reproduce

package main

import (
	"fmt"

	"github.com/davecgh/go-spew/spew"
	"github.com/go-git/go-git/v6" // with go modules enabled (GO111MODULE=on or outside GOPATH)
)

func main() {
	if err := Run(); err != nil {
		fmt.Printf("whoops! error!\n%+v\n", err)
	}
}

func Run() error {

	fmt.Println("hi")
	repo, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{
		EnableDotGitCommonDir: true,
	})
	if err != nil {
		return fmt.Errorf("could not open: %w", err)
	}

	ref, err := repo.Head()
	if err != nil {
		return fmt.Errorf("could not head: %w", err)
	}

	spew.Dump(ref)

	worktree, err := repo.Worktree()
	if err != nil {
		return fmt.Errorf("could not worktree: %w", err)
	}

	spew.Dump(worktree)

	//	status, err := worktree.StatusWithOptions(git.StatusOptions{Strategy: git.Empty})
	status, err := worktree.Status()
	if err != nil {
		return fmt.Errorf("could not status: %w", err)
	}
	spew.Dump(status)

	return nil
}

Additional Information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions