eclipse-egit / egit

EGit, the git integration of Eclipse IDE
https://www.eclipse.org/egit/
Eclipse Public License 2.0
13 stars 6 forks source link

Stagingview: JGIT index lock exception when adding and removing files in one step #10

Closed eder-s closed 2 months ago

eder-s commented 7 months ago

Version

at least since EGit 5

Operating System

Windows

Eclipse version

independent

Bug description

A Jgit index lock exception occurs if you add/remove unstaged files in one single step via the "add all files including not selected ones to the index". The bug only occurs if the git repository is not an Eclipse project.

Steps to reproduce:

  1. Create an empty git repository and do not add it as Eclispe project
  2. Add some files to the repository
  3. Go to the "staging view" and add all files from step 2 to the index, do not commit, you might need to click the "refresh" button to see the unstaged files
  4. Delete a file created in step 2
  5. Add more files to the repsoitory
  6. Go to the staging view again, you might need to click the "refresh" button to see the unstaged files from step 4&5
  7. The unstaged file list contains now some files which need to be added to the index and some files which need to be removed
  8. Click on the "++" button to add/remove all unstaged files to the index
  9. A Jgit index lock error exception is shown and the operation in 8 is not fully performed

Actual behavior

An jgit index lock error is displayed and not all files are staged. You have to stage the remaining unstaged files again.

Expected behavior

No jgit index lock exception occurs, all files are staged

Relevant log output

No response

Other information

The root cause is in "RuleUtil.java" as it can create job schedule rules for repositories which have a Eclipse project linked.

    public static ISchedulingRule getRule(Repository repository) {
        IProject[] projects = getProjects(repository);
        if (projects.length == 0)
            return null;
        return new MultiRule(projects);
    }

The return null above leads to no scheduling rule being created which leads to the concurrent index access during staging.

eder-s commented 7 months ago

I provided an potential fix at https://eclipse.gerrithub.io/c/eclipse-egit/egit/+/1173395