Bug 428363 - clean fails after checkout if current branch has submodules but target branch has not
Summary: clean fails after checkout if current branch has submodules but target branch...
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-17 10:13 EST by Stephan Windmüller CLA
Modified: 2016-09-08 09:14 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Windmüller CLA 2014-02-17 10:13:05 EST
I am using JGit to navigate in the Git repository of the Mantis bugtracker:

https://github.com/mantisbt/mantisbt

As of late, this repository has two submodules: "library/adodb" and "library/phpmailer".

If I am trying to checkout to an older version (e.g. "release-1.2.11"), JGit performs the command but some additional files are still present:

#       library/phpmailer/.gitignore
#       library/phpmailer/README.md
#       library/phpmailer/changelog.md
#       library/phpmailer/language/phpmailer.lang-eo.php
#       library/phpmailer/language/phpmailer.lang-he.php
#       library/phpmailer/language/phpmailer.lang-sk.php

A "git clean -f" would remove those files, but calling a CleanCommand results in this exception:

Exception in thread "main" org.eclipse.jgit.api.errors.JGitInternalException: Could not delete file $DIR/mantisbt/library/adodb

Why does JGit try to remove adodb?
Comment 1 Alex L. CLA 2016-09-08 09:14:21 EDT
Hi,

I ran into a similar issue and it seems it is still existing in org.eclipse.jgit 4.4.1.201607150455-r package.
Namely, git.clean().setCleanDirectories(true).setIgnore(false).call() throws and exception like below after a successful checkout of a branch where a submodule existed before the checkout, but it is not part of the checked out branch.

org.eclipse.jgit.api.errors.JGitInternalException: Could not delete file /path/to/unrelated/submodule/directory
	at org.eclipse.jgit.api.CleanCommand.call(CleanCommand.java:138)
:
Caused by: java.io.IOException: Could not delete file /path/to/unrelated/submodule/directory
	at org.eclipse.jgit.util.FileUtils.delete(FileUtils.java:197)
	at org.eclipse.jgit.util.FileUtils.delete(FileUtils.java:125)
	at org.eclipse.jgit.api.CleanCommand.call(CleanCommand.java:125)
	... 2 more

I suppose a force(boolean) additional method in Git.clean() would be good for the reported problem.

Please let me know your opinion or investigation so far if any.

Thanks,

  A.L.