Bug 479266 - Hard reset cannot handle conflicts on submodule directories
Summary: Hard reset cannot handle conflicts on submodule directories
Status: REOPENED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 4.1   Edit
Hardware: All All
: P3 normal with 1 vote (vote)
Target Milestone: 5.5   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-07 13:01 EDT by Kevin Campbell CLA
Modified: 2019-07-22 06:59 EDT (History)
4 users (show)

See Also:


Attachments
tests to reproduce "reset --hard" bugs creating & deleting a folder (4.36 KB, patch)
2018-07-31 17:36 EDT, René Scheibe CLA
no flags Details | Diff
possible patch to fix one part of the bug (1.51 KB, patch)
2018-08-23 16:54 EDT, René Scheibe CLA
rene.scheibe: review?
Details | Diff
possible patch to fix one part of the bug (1.36 KB, patch)
2018-08-23 16:57 EDT, René Scheibe CLA
rene.scheibe: review?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Campbell CLA 2015-10-07 13:01:40 EDT
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.
Comment 1 René Scheibe CLA 2018-07-22 14:25:42 EDT
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.
Comment 2 Christian Halstrick CLA 2018-07-23 03:38:47 EDT
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
Comment 3 René Scheibe CLA 2018-07-31 17:36:49 EDT
Created attachment 275207 [details]
tests to reproduce "reset --hard" bugs creating & deleting a folder
Comment 4 René Scheibe CLA 2018-08-23 16:54:49 EDT
Created attachment 275511 [details]
possible patch to fix one part of the bug
Comment 5 René Scheibe CLA 2018-08-23 16:57:51 EDT
Created attachment 275512 [details]
possible patch to fix one part of the bug
Comment 6 Eclipse Genie CLA 2018-08-23 17:56:38 EDT
New Gerrit change created: https://git.eclipse.org/r/127969
Comment 7 Eclipse Genie CLA 2018-08-23 17:56:40 EDT
New Gerrit change created: https://git.eclipse.org/r/127968
Comment 8 Eclipse Genie CLA 2018-08-23 17:56:42 EDT
New Gerrit change created: https://git.eclipse.org/r/127967
Comment 9 Eclipse Genie CLA 2018-08-27 07:17:06 EDT
Gerrit change https://git.eclipse.org/r/127967 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=dbe01e8852bec1a7ab6fda7dc85abedba2190604
Comment 10 René Scheibe CLA 2018-09-04 00:21:10 EDT
(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.
Comment 11 Matthias Sohn CLA 2018-09-05 09:07:12 EDT
(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.
Comment 12 René Scheibe CLA 2018-10-05 05:37:14 EDT
(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.
Comment 13 René Scheibe CLA 2018-12-10 16:27:39 EST
(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?
Comment 14 Eclipse Genie CLA 2019-06-19 07:09:42 EDT
Gerrit change https://git.eclipse.org/r/127969 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=8f9697b4c182be6f4ec3eeda130bd57237f154c7
Comment 15 Eclipse Genie CLA 2019-06-19 07:09:44 EDT
Gerrit change https://git.eclipse.org/r/127968 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=b4edf9ec142cd8d728800625926e12a7cecfa52e
Comment 16 René Scheibe CLA 2019-06-20 03:47:27 EDT
Thanks Christian and Matthias for making this happen.
Comment 17 Matthias Sohn CLA 2019-06-21 02:46:22 EDT
thanks for your fixes
Comment 18 Thomas Wolf CLA 2019-07-22 06:59:44 EDT
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());
  }