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

git clean is destructive and undocumented #62

Open
nojnhuh opened this issue May 1, 2024 · 1 comment
Open

git clean is destructive and undocumented #62

nojnhuh opened this issue May 1, 2024 · 1 comment

Comments

@nojnhuh
Copy link

nojnhuh commented May 1, 2024

I have some gitignored local configuration I maintain locally in the same directory as a git repo. Running go-apidiff irrecoverably deletes all of those files because of the git clean it does here:

go-apidiff/pkg/diff/run.go

Lines 199 to 201 in 00f8d2e

if err := wt.Clean(&git.CleanOptions{Dir: true}); err != nil {
return nil, nil, err
}

This behavior is destructive and essentially impossible to know about until it's too late. This behavior should be documented and put behind a descriptive flag like --force-clean.

@joelanford
Copy link
Owner

Oh no! Sorry about that!

It took quite a bit of trial and error to make go-apidiff robustly handle various scenarios with what it might encounter in a git tree. The main guard that I thought protected against destructive actions is this IsClean() check:

} else if !stat.IsClean() {
return nil, &GitStatusError{stat, fmt.Errorf("current git tree is dirty")}
}

It's been quite a long time since I wrote most of this code, and I unfortunately don't even remember why wt.Clean() is called there.

There are definitely some oddities I've encountered with go-git, where it behaves a little bit different to the git CLI, so that might partly explain it.

I don't have a lot of time to work on this project, but I'd definitely be willing to accept a PR that either:

  • handles this scenario in a non-destructive way
  • adds additional checks for potential destructive actions and just fails out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants