Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 361442

Summary: 'Replace With > HEAD Revision' does not put previous version into local history
Product: [Technology] EGit Reporter: Markus Keller <markus.kell.r>
Component: UIAssignee: Project Inbox <egit.ui-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: daniel_megert, krzysztof.daniel, matthias.sohn, remy.suen, robin.rosenberg, robin, selsemore
Version: 1.2   
Target Milestone: 3.6   
Hardware: PC   
OS: Windows 7   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=389078
Whiteboard:

Description Markus Keller CLA 2011-10-19 13:47:38 EDT
1.2.0.201110141813

'Replace With > HEAD Revision' does not put the previous version into local history. The data is lost!

All Eclipse plug-ins must support the local history of the workbench. The bug probably happens because JGit doesn't use the resource model to manipulate the file contents.
Comment 1 Markus Keller CLA 2012-02-17 12:21:45 EST
This bug could void success stories like this one:
http://eclipseandlinux.blogspot.com/2012/01/life-saving-eclipse-functionality.html
Comment 2 Robin Stocker CLA 2013-11-19 14:06:11 EST
Fixing this would probably mean introducing an abstraction like WorkingTreeIterator in JGit, but for writing files instead of reading. Or maybe we could even extend WorkingTreeIterator.

The nice thing about this would be that we could also remove the expensive resource refreshes that we currently do after JGit operations. We currently refresh too much, e.g. all projects after a branch switch instead of only the changed files.
Comment 3 Robin Rosenberg CLA 2013-11-20 12:39:54 EST
A sad part is that the resource view all too often does not represent what's on disk. We can trust file system operations, but not resource operations.
Comment 4 Matthias Sohn CLA 2013-11-21 05:20:07 EST
(In reply to Robin Rosenberg from comment #3)
> A sad part is that the resource view all too often does not represent what's
> on disk. We can trust file system operations, but not resource operations.

I think this works more reliably when switching on the workspace option
"Preferences > General > Workspace > Refresh using native hooks or polling"
Comment 5 Markus Keller CLA 2013-11-21 06:23:08 EST
> We can trust file system operations, but not resource operations.

No, you can also trust resource operations -- but only if you use resources as they are meant to be used. The whole resource model assumes that resources are only accessed via workspace APIs and not directly via the file system. In Git, that assumption typically doesn't hold, since the Git command line offers features that are not available in EGit.

> works more reliably with auto-refresh enabled

But it's still not reliable, so it's not safe to depend on that. You could rely on the "Refresh on access" setting, though: If that option is disabled, then it's fair to assume that a Git repo is not touched from outside of the workspace, so you can avoid explicit refreshes in that case.

If "Refresh on access" is enabled (default setting), EGit should refresh resources before operating on them. I agree with Robin Stocker's comment 2 that resources should be accessed via the workspace APIs -- and as soon as that's implemented, there's no need to refresh anything after an EGit/JGit operation.
Comment 6 Robin Rosenberg CLA 2013-11-21 07:34:21 EST
(In reply to Matthias Sohn from comment #4)
> (In reply to Robin Rosenberg from comment #3)
> > A sad part is that the resource view all too often does not represent what's
> > on disk. We can trust file system operations, but not resource operations.
> 
> I think this works more reliably when switching on the workspace option
> "Preferences > General > Workspace > Refresh using native hooks or polling"

That only works on Windows or did that change?

I've only used it very shortly because the scanning slows down the computer due to excessive disk I/O, uses too much battery power and reacts too slowly. I.e. not useful for anything but very small workspaces. Has it improved over the last two years?
Comment 7 Markus Keller CLA 2013-11-21 08:33:10 EST
(In reply to Robin Rosenberg from comment #6)
> > "Preferences > General > Workspace > Refresh using native hooks or polling"
> 
> That only works on Windows or did that change?

Correct, native hooks are still only used on Windows.
See bug 108697 (Linux) and bug 237344 (Mac).
Comment 8 Steve Elsemore CLA 2014-01-15 13:28:10 EST
Note that this is also a problem when you do a hard reset.  Changes are discarded without being put in local history.

I've submitted a patch for code review:

https://git.eclipse.org/r/20675

Perhaps this will be considered a hack, as it resorts to performing a dummy update on the changed resources in order to trigger Eclipse to save them to local history.  But it does work.  FWIW, I implemented a similar change for the Subclipse plugin years ago.
Comment 9 Matthias Sohn CLA 2014-09-10 08:31:45 EDT
merged as f812540fa95ae0f89d853bce880920d7a2c22b17