Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worktree.Status() always fail #299

Closed
kyoh86 opened this issue Apr 15, 2021 · 15 comments · Fixed by #1066
Closed

Worktree.Status() always fail #299

kyoh86 opened this issue Apr 15, 2021 · 15 comments · Fixed by #1066
Labels
bug Something isn't working help wanted Extra attention is needed no-autoclose Issues/PRs to be ignored by stale bot

Comments

@kyoh86
Copy link

kyoh86 commented Apr 15, 2021

It always return invalid checksum for any repository.

$ go version
go version go1.16.3 linux/amd64
@JanDeDobbeleer
Copy link

JanDeDobbeleer commented May 22, 2021

@kyoh86 same for me. Falls back to this check, which, if I remove it, resolves the issue and things actually work. So I have no idea why this check is in there.

@c-carpenter
Copy link

I am running into the same issue. Oddly others on my team are able to run the code in question, but I am not.

@c-carpenter
Copy link

In my case the issue was that I had enabled a new git feature: FSMonitor. go-git does not support the header for this feature yet and thus was causing it to barf.

@c-carpenter
Copy link

After a night of sleep, the probable best direction to take this issue is to improve the error handling on the plumbing/format/index/decoder.go. It currently assumes that an error means it has reached EOF and thus is done. But there are many possible error cases that can happen within the loop. Better handling of the errors that happen within the for loop will result in better understanding of what is happening for the users.

@maticrivo
Copy link

I'm facing the same issue even with FSMonitor turned off..
is there a fix for this?

@kyoh86
Copy link
Author

kyoh86 commented Nov 26, 2022

@mcuadros how about this?

@maticrivo
Copy link

any news on having a fix/workaround for this?

@zkmoney
Copy link

zkmoney commented Feb 15, 2023

I ran into this issue as well, and ended up building from source and mucking around a bit to try and figure out what was going on. Not sure if it's helpful for anyone else, but my issue was that I had in my .gitconfig

core.untrackedCache = true

and that was causing a git index header of UNTR to be in the mix, and was throwing off the Decoder.readExtension method, as the package didn't know how to handle that. (I don't really know much about all of these internals, and got pretty lucky I think, so unfortunately don't have much context for what any of this means).

Anyway, I remove the setting from my .gitconfig and it worked great.

@florianrusch
Copy link

I created for testing purposes a small repo locally with only one commit in it. If I now try to execute worktree.Status() on this repo it's throwing the same error.

I already checked, the described workarounds/fixes from this Issue, but none of them worked so far:

  • I'm not using the FSMonitor at all
  • untrackedCache was set to true, but setting this to false doesn't helped

I also tested to comment out most of my .gitconfig stuff - still the same result 😕

@pjbgf
Copy link
Member

pjbgf commented Jun 11, 2023

@florianrusch would you be able to share a concise steps to reproduce? Does this happen on a specific public repository?

@florianrusch
Copy link

florianrusch commented Jun 11, 2023

Okay, I have it reproducible 💪 and I think I found my problem too. So first I will describe my problem and solution and then below you will find my setup/steps to reproduce it.

My problem & solution

  • When I created the repo, I had set core.untrackedCache = true in my global .gitconfig. As described by @zkmoney, this triggers the error => error: invalid checksum
  • Only changing core.untrackedCache to false in my .gitconfig did not work and I still have the same error
  • BUT: If I run a git command (e.g. git status) in the repo after changing core.untrackedCache, the error is gone 🥳

So I guess that something must be executed that changes/updates the git index (maybe the term index is wrong - I don't have deep insight into how git works). Just changing core.untrackedCache without doing anything in the repo itself did nothing.


Steps to reproduce

Have the following in you .gitconfig

[core]
	untrackedCache = true

Do the following steps to create the repo:

git init
touch README.md
git add README.md
git commit -m "INIT"
git status

And this is my go program. I received the error from the worktree.Status() method.

path := "/path/to/my/repo"

r, err := g.PlainOpen(path)
if err != nil {
	return err
}

worktree, err := r.Worktree()
if err != nil {
	return err
}

status, err := worktree.Status()
if err != nil {
	return err
}

Copy link

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!

@github-actions github-actions bot added the stale Issues/PRs that are marked for closure due to inactivity label Feb 13, 2024
@kyoh86
Copy link
Author

kyoh86 commented Feb 16, 2024

it's still alive.

@github-actions github-actions bot removed the stale Issues/PRs that are marked for closure due to inactivity label Feb 17, 2024
@pjbgf pjbgf added no-autoclose Issues/PRs to be ignored by stale bot help wanted Extra attention is needed labels Feb 19, 2024
@pjbgf
Copy link
Member

pjbgf commented Apr 6, 2024

A fix for this has been proposed on #1066. It would be great if anyone still experiencing it could confirm that it fixes the issue for them.

@apodznoev
Copy link

apodznoev commented Jun 25, 2024

The issue does not reproduce anymore when unsupported extensions are met, e.g. I had the "invalid checksum" issue when my Git configuration was

[core]
	untrackedCache = true

and I used at least once git status on the repository. This is not the case anymore.

However, when using

[feature]
	manyFiles = true

the index of a repository is initialized using index.version=4, so any attempt to read status of the repository using go-git fails with the same error.

Very suspicious is the following part fromstorage/filesystem/index.go:

func (s *IndexStorage) Index() (i *index.Index, err error) {
	idx := &index.Index{
		Version: 2,
	}

	f, err := s.dir.Index()
	if err != nil {
		if os.IsNotExist(err) {
			return idx, nil
		}

		return nil, err
	}

	defer ioutil.CheckClose(f, &err)

	d := index.NewDecoder(f)
	err = d.Decode(idx)
	return idx, err
}

The index is being read using version 2.
I think it might cause the problem in Decoder when reading entries since it has a switch on this version:

func (d *Decoder) readEntryName(idx *Index, e *Entry, flags uint16) error {
	...
	switch idx.Version {
	case 2, 3:
		len := flags & nameMask
		name, err = d.doReadEntryName(len)
	case 4:
		name, err = d.doReadEntryNameV4()
	default:
		return ErrUnsupportedVersion
	}
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed no-autoclose Issues/PRs to be ignored by stale bot
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants