You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to delete file when the repository will be empty #723
I did a quick test and this is definitely a bug. The issue is that the option CommitOptions.AllowEmptyCommits is checking the wrong thing. It is checking if the repo will be empty after the commit rather than the commit not making any changes.
Eg if you modify the test TestNothingToCommit and make sure the repo is not empty before running the empty commit tests then the test will fail.
I can't see that function? I can see Status.IsClean() however I wouldn't want to require a full status every time we want to commit, I think we need a WorkTree.IsClean() that does the same as WorkTree.Status() but bails out as soon as it finds the first change.
Although WorkTree.Status() is checking both staging and the worktree, I would think we should only need to check staging?
Possibly, I would need to read that code carefully to confirm. However that is doing waaay more work than we would want, and could cause performance issues on large repos (I'm not qualified to know how optimised w.Status() is). But I would think we would want to add to merkletrie something like:
type DiffTreeOptions struct {
// Should the diff stop after finding the first difference
OnlyFirstDif bool
}
func DiffTreeContextWithOptions(ctx context.Context, fromTree, toTree noder.Noder,
hashEqual noder.Equal, options DiffTreeOptions) (Changes, error) {
...
if options.OnlyFirstDif && len(ret) > 0 {
return ret, nil
}
...
}
So that we can just search for any change... As long as there is 1.
@Erouan50 thank you for filing the issue and for providing good steps to reproduce. 🙇
if you agree it is a bug
I agree this is a bug.
The issue is that the option CommitOptions.AllowEmptyCommits is checking the wrong thing. It is checking if the repo will be empty after the commit rather than the commit not making any changes.
You are absolutely right.
I wouldn't want to require a full status every time we want to commit
+1
My suggestion here is that we change the logic to compare the new vs previous Tree hash:
I really don't know the inner working to be able to tell if the tree hash check will be enough.
Although reading the man page for --allow-empty sounds like that is correct:
--allow-empty
Usually recording a commit that has the exact same tree as its sole parent commit is a mistake, and the command prevents you from making such a commit. This option bypasses the safety, and is primarily for use by foreign SCM interface scripts.
This is still happening today, I downloaded the code referenced in the first post to confirm I'm not doing anything special and I got the same exact result.
This is still happening today, I downloaded the code referenced in the first post to confirm I'm not doing anything special and I got the same exact result.
Activity
clavinjune commentedon Jun 23, 2023
this is happening on my side too 😢
AriehSchneier commentedon Jun 25, 2023
I did a quick test and this is definitely a bug. The issue is that the option
CommitOptions.AllowEmptyCommitsis checking the wrong thing. It is checking if the repo will be empty after the commit rather than the commit not making any changes.Eg if you modify the test
TestNothingToCommitand make sure the repo is not empty before running the empty commit tests then the test will fail.clavinjune commentedon Jun 25, 2023
can we use
FileSystem.IsClean()Status.IsClean()instead?AriehSchneier commentedon Jun 25, 2023
I can't see that function? I can see Status.IsClean() however I wouldn't want to require a full status every time we want to commit, I think we need a WorkTree.IsClean() that does the same as WorkTree.Status() but bails out as soon as it finds the first change.
Although WorkTree.Status() is checking both staging and the worktree, I would think we should only need to check staging?
@pjbgf what are your thoughts on this?
clavinjune commentedon Jun 26, 2023
something like this @AriehSchneier ?
AriehSchneier commentedon Jun 26, 2023
Possibly, I would need to read that code carefully to confirm. However that is doing waaay more work than we would want, and could cause performance issues on large repos (I'm not qualified to know how optimised
w.Status()is). But I would think we would want to add tomerkletriesomething like:So that we can just search for
anychange... As long as there is 1.g13013 commentedon Jul 31, 2023
Hi,
Any updates on this ? for me it's the opposite, AllowEmptyCommits is a NOP
pjbgf commentedon Sep 27, 2023
@Erouan50 thank you for filing the issue and for providing good steps to reproduce. 🙇
I agree this is a bug.
You are absolutely right.
+1
My suggestion here is that we change the logic to compare the new vs previous Tree hash:
@AriehSchneier what do you think?
@Erouan50 are you happy to create a PR with the fix? The logic for getting the Tree hash is already within
opts.Amend.AriehSchneier commentedon Sep 28, 2023
I really don't know the inner working to be able to tell if the tree hash check will be enough.
Although reading the man page for --allow-empty sounds like that is correct:
ThinkChaos commentedon Jan 25, 2024
Ran into this today. There's a proposed fix above, is there anything holding it back besides motion?
AriehSchneier commentedon Jan 25, 2024
@ThinkChaos if you create a PR and test it, I assume it would get merged pretty quickly.
git: worktree_commit, Modify checking empty commit. Fixes go-git#723
git: worktree_commit, Modify checking empty commit. Fixes go-git#723
git: worktree_commit, Modify checking empty commit. Fixes go-git#723
git: worktree_commit, Modify checking empty commit. Fixes go-git#723
git: worktree_commit, Modify checking empty commit. Fixes go-git#723
Merge pull request #1050 from onee-only/fix-empty-commit
nour-s commentedon Sep 14, 2024
Hi there 👋
This is still happening today, I downloaded the code referenced in the first post to confirm I'm not doing anything special and I got the same exact result.
I'm using the latest version
go.sum:
AriehSchneier commentedon Sep 16, 2024
@nour-s The fix is on master but no release has been created yet. Try using the master branch.
nour-s commentedon Sep 17, 2024
@AriehSchneier I see, it is for company production so I would stick with the releases I think. I did a workaround by allowing empty commits.
Thanks for the help
Update module github.com/go-git/go-git/v5 to v5.13.1 (forgejo) (#6495)
Update module github.com/go-git/go-git/v5 to v5.13.1 (v10.0/forgejo) …