Community
Participate
Working Groups
When trying to perform a hard reset through JGit, it is failing with a CheckoutConflictException. Digging through the code, JGit is seeing a checkout conflict on a directory that is a submodule. Then, in the cleanUpConflicts method it tries to delete the directory, which fails because the directory is not empty. The stacktrace is: org.eclipse.jgit.api.errors.CheckoutConflictException: Checkout conflict with file: Cannot delete file: vendor/LIBRARY at org.eclipse.jgit.api.ResetCommand.checkoutIndex(ResetCommand.java:388) at org.eclipse.jgit.api.ResetCommand.call(ResetCommand.java:203) Caused by: org.eclipse.jgit.errors.CheckoutConflictException: Checkout conflict with file: Cannot delete file: vendor/LIBRARY at org.eclipse.jgit.dircache.DirCacheCheckout.cleanUpConflicts(DirCacheCheckout.java:1031) at org.eclipse.jgit.dircache.DirCacheCheckout.doCheckout(DirCacheCheckout.java:416) at org.eclipse.jgit.dircache.DirCacheCheckout.checkout(DirCacheCheckout.java:396) at org.eclipse.jgit.api.ResetCommand.checkoutIndex(ResetCommand.java:386) As far as how the repository got into this state in the first place, I haven't been able to track down. Somehow the repository gets into a state where git status sees all files as deleted, but all files are still actually present on disk. Regardless, a hard reset works on the command line but not with JGit.
This issue is not specific to submodules only. It is about resetting directories in general. I will try to provide appropriate test cases in the next days.
Could you provide instructions how to reproduce this? E.g. some script using jgit command line [1]. Rene's test case would of course be better but to speed up working on it a script would help. [1] https://repo.eclipse.org/content/groups/releases//org/eclipse/jgit/org.eclipse.jgit.pgm/5.0.1.201806211838-r/org.eclipse.jgit.pgm-5.0.1.201806211838-r.sh
Created attachment 275207 [details] tests to reproduce "reset --hard" bugs creating & deleting a folder
Created attachment 275511 [details] possible patch to fix one part of the bug
Created attachment 275512 [details] possible patch to fix one part of the bug
New Gerrit change created: https://git.eclipse.org/r/127969
New Gerrit change created: https://git.eclipse.org/r/127968
New Gerrit change created: https://git.eclipse.org/r/127967
Gerrit change https://git.eclipse.org/r/127967 was merged to [master]. Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=dbe01e8852bec1a7ab6fda7dc85abedba2190604
(In reply to Christian Halstrick from comment #2) > Could you provide instructions how to reproduce this? E.g. some script using > jgit command line [1]. Rene's test case would of course be better but to > speed up working on it a script would help. I was wondering if there is anything else I can do? Only 1 out of 3 Gerrit changes has been reviewed and merged. The remaining 2 are the actual fixes which have not been reviewed yet.
(In reply to Rene Scheibe from comment #10) > (In reply to Christian Halstrick from comment #2) > > Could you provide instructions how to reproduce this? E.g. some script using > > jgit command line [1]. Rene's test case would of course be better but to > > speed up working on it a script would help. > I was wondering if there is anything else I can do? > Only 1 out of 3 Gerrit changes has been reviewed and merged. > The remaining 2 are the actual fixes which have not been reviewed yet. I'll try to find time to review your patches, we are all pretty busy hence sometimes it takes a while.
(In reply to Matthias Sohn from comment #11) Hi Matthias, as a month passed already, I just wanted to check if there is any chance you could have a look at it.
(In reply to Rene Scheibe from comment #12) Hi Matthias and Christian, did you have some time to make more progress on this? Is there something else I can help?
Gerrit change https://git.eclipse.org/r/127969 was merged to [master]. Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=8f9697b4c182be6f4ec3eeda130bd57237f154c7
Gerrit change https://git.eclipse.org/r/127968 was merged to [master]. Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=b4edf9ec142cd8d728800625926e12a7cecfa52e
Thanks Christian and Matthias for making this happen.
thanks for your fixes
If the file/directory conflict is not on the immediate parent, this still fails. Try in ResetCommandTest: @Test public void testHardResetWithConflicts_CreateFolderNested_UnstagedChanges() throws Exception { setupRepository(); writeTrashFile("dir-or-file/subdir/c.txt", "content"); git.add().addFilepattern("dir-or-file/subdir/c.txt").call(); git.commit().setMessage("adding dir-or-file/subdir/c.txt").call(); FileUtils.delete(new File(db.getWorkTree(), "dir-or-file"), FileUtils.RECURSIVE); writeTrashFile("dir-or-file", "content"); // bug 479266: cannot create folder "dir-or-file" git.reset().setMode(ResetType.HARD).setRef(Constants.HEAD).call(); assertTrue(new File(db.getWorkTree(), "dir-or-file/subdir/c.txt") .exists()); }