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

Bug 338430

Summary: Most recent in-IDE edit of a file not stored in the local history => data loss if file is modified externally
Product: [Eclipse Project] Platform Reporter: James Blackburn <jamesblackburn+eclipse>
Component: ResourcesAssignee: Platform-Resources-Inbox <platform-resources-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
Whiteboard: stalebug

Description James Blackburn CLA 2011-02-28 11:13:41 EST
Using 3.7M5.

If you then change the file externally, there appears to be no way to restore the file to the most recent version as saved within the IDE. It appears that all (non garbage-collected) versions, other than the most recent are available to restore to.
This seems to be quite a big flaw in local history -- it should be possible to restore to the most recent saved version as saved within the IDE...

1) Create a text file and save
2) Externally: Copy the file to <file>.bak
3) Change the file in eclipse
4) Verify that the two changes are in local history.
5) Externally to eclipse: cp <file>.bak to <file>
6) In eclipse you've now lost the most recent changes that were made in the IDE.

Local history should keep the most recent IDE version.
Comment 1 John Arthorne CLA 2011-02-28 14:28:01 EST
(In reply to comment #0)
> Local history should keep the most recent IDE version.

By most recent, you mean the *current* revision of the file should be in local history?
Comment 2 John Arthorne CLA 2011-02-28 14:32:34 EST
See also for example bug 10589.
Comment 3 James Blackburn CLA 2011-02-28 14:50:08 EST
(In reply to comment #1)
> (In reply to comment #0)
> > Local history should keep the most recent IDE version.
> 
> By most recent, you mean the *current* revision of the file should be in local
> history?

No, I mean the last version saved in an Eclipse editor.  

Having changed a file externally, there doesn't seem to be a way to get back eclipse's last saved version.  This may be a UI artifact as afaics every save calls through to the history store.  Haven't dug too deeply into where the issue might be...
Comment 4 John Arthorne CLA 2011-02-28 17:42:58 EST
Ok, just to be clear, when a file is modified in Eclipse, the *previous* contents are moved to local history. There is nothing in the local history for the current file contents after saving in Eclipse. I'm not sure if I'm making sense in explaining it...
Comment 5 James Blackburn CLA 2011-02-28 17:53:18 EST
(In reply to comment #4)
> There is nothing in the local history for
> the current file contents after saving in Eclipse. I'm not sure if I'm making
> sense in explaining it...

That does make sense and seems to be exactly what I'm seeing, having re-read bug 10589 this does seem to be a similar request.

It's great to save the previous version, but the current version should be saved too or there's a sort of off-by-one as external operations can cause the most recent internal change to be lost.

For example, the case I had today, was a user doing a git reset --hard causing a merge to be aborted and their files to be reset to HEAD.  They expected the most recent saves they'd done in the IDE to be in the local history.  Instead they had the most recent-but-one in the local history.
Comment 6 James Blackburn CLA 2011-02-28 18:12:55 EST
Ah, I see that the behaviour also matches the JavaDoc.

I think the confusion arose because I can see the most recent version of the file in the Local history view, indistinguishable from the previous revisions there.  As the other history elements are immutable, I thought the most recent one would also be immutable...

Would it be a bad thing to add the history to the state after a save as well as before:
  getHistoryStore().addState(target.getFullPath(), store, fileInfo, false);
?
I guess there could be performance implications, but in the usual case the previous version has already been added at the end of the last setContents, so should be optimizable to a NOP.
Comment 7 Lars Vogel CLA 2019-11-14 02:23:17 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

If the bug is still relevant, please remove the "stalebug" whiteboard tag.