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

Bug 507018

Summary: Add option to not automatically stage files
Product: [Technology] EGit Reporter: Knut Wannheden <knut.wannheden>
Component: CoreAssignee: Project Inbox <egit.core-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: loskutov, matthias.sohn, oyvind.harboe, twolf
Version: 4.6   
Target Milestone: 4.6   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/84522
https://git.eclipse.org/c/egit/egit.git/commit/?id=5f95132e5c3a0422f53c8f886757a8f23ee7a8e6
Whiteboard:

Description Knut Wannheden CLA 2016-11-04 02:12:24 EDT
Whenever files get deleted using the Eclipse IResource#delete() API the corresponding deleted file(s) get staged in Git. I think it would make sense to have a preference with which this can be disabled so that the behavior is the same as when the files get deleted in other ways (e.g. using java.io.File#delete()).

My main use case for this is that I have some generated files which I like to version in Git. My generator runs as an Eclipse builder and will during a clean build first delete all generated files. So whenever I run a clean build I then have to unstage all deleted files, which is rather annoying.

This was also discussed some time ago in the forum: https://www.eclipse.org/forums/index.php/t/1072672/. Apparently there are more users who don't really like this automatic staging of deleted files.
Comment 1 Thomas Wolf CLA 2016-11-04 06:20:24 EDT
Took a look at the code that I _think_ is responsible for this. Looks like it should not auto-stage deletions of files for which IResource.isDerived() returns true.

Are your generated files marked as derived resources?

Probably EGit should check for IResource.isDerived(IResource.CHECK_ANCESTORS), though.

Is any parent folder of these generated resources marked as derived?
Comment 2 Matthias Sohn CLA 2016-11-04 10:21:22 EDT
We can add such an option, actually I started working on a patch implementing that.
Auto-staging of deletions is implemented in GitMoveDeleteHook.deleteFile().

Why are you versioning files generated by the build ?
Comment 3 Thomas Wolf CLA 2016-11-04 10:34:00 EDT
(In reply to Matthias Sohn from comment #2)
> We can add such an option, actually I started working on a patch
> implementing that.

Cool. In that case, we probably should also start with project-specific properties. This one, and bug 411702.

> Auto-staging of deletions is implemented in GitMoveDeleteHook.deleteFile().

Yes, that's what I was looking at.
Comment 4 Andrey Loskutov CLA 2016-11-04 10:57:30 EDT
(In reply to Matthias Sohn from comment #2)
> We can add such an option, actually I started working on a patch
> implementing that.
> Auto-staging of deletions is implemented in GitMoveDeleteHook.deleteFile().

Actually the problem is worse: due the auto-staging, if one *renames* the file, the old deleted path will be staged, and new one not, this is quite confusing.

I don't know why this was implemented at all. If I delete the file occasionally, it is also staged, if I modify the file, not. Staging should be explicit, triggered by user, not automated.
Comment 5 Eclipse Genie CLA 2016-11-05 13:41:23 EDT
New Gerrit change created: https://git.eclipse.org/r/84522
Comment 6 Matthias Sohn CLA 2016-11-06 15:25:03 EST
(In reply to Andrey Loskutov from comment #4)
> (In reply to Matthias Sohn from comment #2)
> > We can add such an option, actually I started working on a patch
> > implementing that.
> > Auto-staging of deletions is implemented in GitMoveDeleteHook.deleteFile().
> 
> Actually the problem is worse: due the auto-staging, if one *renames* the
> file, the old deleted path will be staged, and new one not, this is quite
> confusing.

this works for me (on Mac), moving or renaming a file auto-stages both the new path and the deletion of the old path

would you also like to get rid of auto-staging moves ?

> I don't know why this was implemented at all. If I delete the file
> occasionally, it is also staged, if I modify the file, not. Staging should
> be explicit, triggered by user, not automated.

do you think we should completely remove auto-staging of file deletions ?
Comment 7 Knut Wannheden CLA 2016-11-08 01:46:05 EST
(In reply to Matthias Sohn from comment #6)
> do you think we should completely remove auto-staging of file deletions ?

IMHO it would make sense to add a preference to disable all auto-staging. Without knowing things like what Thomas pointed out in comment #1 the auto-staging behavior may almost appear a but erratic.
Comment 8 Andrey Loskutov CLA 2016-11-08 03:59:15 EST
(In reply to Knut Wannheden from comment #7)
> (In reply to Matthias Sohn from comment #6)
> > do you think we should completely remove auto-staging of file deletions ?
> 
> IMHO it would make sense to add a preference to disable all auto-staging.
> Without knowing things like what Thomas pointed out in comment #1 the
> auto-staging behavior may almost appear a but erratic.

Yep. I've changed the bug title to make it clear.
Comment 9 Eclipse Genie CLA 2016-12-12 17:57:55 EST
Gerrit change https://git.eclipse.org/r/84522 was merged to [master].
Commit: http://git.eclipse.org/c/egit/egit.git/commit/?id=5f95132e5c3a0422f53c8f886757a8f23ee7a8e6
Comment 10 Thomas Wolf CLA 2017-01-13 08:34:17 EST
*** Bug 341322 has been marked as a duplicate of this bug. ***