threads / patch / 19022

patchIgnoreAction to add to .gitignore files

Subject: [EGit PATCH] IgnoreAction to add to .gitignore files

## tl;dr

11 messages between Apr 23, 2009 and Apr 23, 2009. Diffs are folded; open one to read it.

replies: 10people: 4as markdown or json

Alex Blewitt· Apr 23, 2009, 11:50 UTC · lore
Show changes to 3 files +100 −1

org.spearce.egit.ui/plugin.properties, org.spearce.egit.ui/plugin.xml, org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/IgnoreAction.java

diff --git a/org.spearce.egit.ui/plugin.properties b/org.spearce.egit.ui/plugin.properties
index 523a959..be3b40c 100644
--- a/org.spearce.egit.ui/plugin.properties
+++ b/org.spearce.egit.ui/plugin.properties
@@ -52,10 +52,12 @@ FetchAction_tooltip=Fetch from another repository
 PushAction_label=&Push To...
 PushAction_tooltip=Push to another repository
 
+IgnoreAction_label=Add to .git&ignore...
+IgnoreAction_tooltip=Ignore the selected resources
+
 GitActions_label=Git
 GitMenu_label=&Git
 
-
 Theme_label=Git
 Theme_CommitGraphNormalFont_label=Commit graph normal font
 Theme_CommitGraphNormalFont_description=This font is used to draw the revision history.
diff --git a/org.spearce.egit.ui/plugin.xml b/org.spearce.egit.ui/plugin.xml
index a94c8bc..1f62292 100644
--- a/org.spearce.egit.ui/plugin.xml
+++ b/org.spearce.egit.ui/plugin.xml
@@ -115,6 +115,12 @@
 	       menubarPath="compareWithMenu/gitCompareWithGroup"
 	       tooltip="&CompareWithIndexAction_tooltip">
 	 </action>
+         <action
+               class="org.spearce.egit.ui.internal.actions.IgnoreAction"
+               id="org.spearce.egit.ui.internal.actions.IgnoreAction"
+               label="%IgnoreAction_label"
+               menubarPath="team.main/group1"
+               tooltip="%IgnoreAction_tooltip"/>
 	  </objectContribution>
 	  <objectContribution
          id="org.spearce.egit.ui.resetto"
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/IgnoreAction.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/IgnoreAction.java
new file mode 100644
index 0000000..501443e
--- /dev/null
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/IgnoreAction.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (C) 2009, Alex Blewitt <alex.blewitt@gmail.com>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * See LICENSE for the full license text, also available.
+ *******************************************************************************/
+package org.spearce.egit.ui.internal.actions;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.team.core.Team;
+import org.spearce.jgit.lib.Constants;
+
+/**
+ * Action for ignoring files via .gitignore
+ *
+ */
+public class IgnoreAction extends RepositoryAction {
+	
+	private static final String GITIGNORE = ".gitignore";
+
+	@SuppressWarnings("restriction")
+	@Override
+	public void run(IAction action) {
+		final IResource[] resources = getSelectedResources();
+		if (resources.length == 0)
+			return;
+		
+		WorkspaceJob job = new WorkspaceJob("Ignore Git resources") { //$NON-NLS-1$
+			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+				monitor.beginTask("Ignoring Git resources", resources.length); //$NON-NLS-1$
+				try {
+					for (IResource resource : resources) {
+						// TODO This is pretty inefficient; multiple ignores in the same directory cause multiple writes.
+						// NB This does the same thing in DecoratableResourceAdapter, but neither currently consult .gitignore
+						if (!Team.isIgnoredHint(resource)) {
+							IContainer container = resource.getParent();
+							IFile gitignore = container.getFile(new Path(GITIGNORE));
+							String entry = "/" + resource.getName() + "\n"; //$NON-NLS-1$  //$NON-NLS-2$
+							// TODO What is the character set and new-line convention?
+							if(gitignore.exists()) {
+								// This is ugly. CVS uses an internal representation of the .gitignore to re-write/overwrite each time.
+								ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
+								out.write(entry.getBytes(Constants.CHARACTER_ENCODING)); // TODO Default encoding?
+								gitignore.appendContents(new ByteArrayInputStream(out.toByteArray()),true,true,monitor);
+							} else {
+								ByteArrayInputStream bais = new ByteArrayInputStream( entry.getBytes(Constants.CHARACTER_ENCODING) ); 
+								gitignore.create( bais,true,monitor);					
+							}
+						}
+						monitor.worked(1);
+					}
+					monitor.done();
+				} catch (CoreException e) {
+					throw e;
+				} catch (Exception e) {
+					throw new CoreException(new Status(IStatus.ERROR, "org.spearce.egit.ui", "Unable to ignore resources", e)); //$NON-NLS-1$
+				}
+				return Status.OK_STATUS;			
+			}
+		};
+		job.schedule();		
+	}
+
+	@SuppressWarnings("restriction")
+	@Override
+	public boolean isEnabled() {
+		if (getProjectsInRepositoryOfSelectedResources().length == 0)
+			return false;
+
+		IResource[] resources = getSelectedResources();
+		for (IResource resource : resources) {
+			// NB This does the same thing in DecoratableResourceAdapter, but neither currently consult .gitignore
+			if (!Team.isIgnoredHint(resource))
+				return true;
+		}
+		return false;
+	}
+}
Francis Galiegue· Apr 23, 2009, 12:27 UTC · re: Alex Blewitt · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

Le jeudi 23 avril 2009, Alex Blewitt a écrit :
> diff --git a/org.spearce.egit.ui/plugin.properties 
b/org.spearce.egit.ui/plugin.properties
Show 13 quoted lines
> index 523a959..be3b40c 100644
> --- a/org.spearce.egit.ui/plugin.properties
> +++ b/org.spearce.egit.ui/plugin.properties
> @@ -52,10 +52,12 @@ FetchAction_tooltip=Fetch from another repository
>  PushAction_label=&Push To...
>  PushAction_tooltip=Push to another repository
>  
> +IgnoreAction_label=Add to .git&ignore...
> +IgnoreAction_tooltip=Ignore the selected resources
> +
>  GitActions_label=Git
>  GitMenu_label=&Git
>  
The label and tooltip are too "git-specific", IMHO. I'd rather see:

IgnoreAction_label=&Ignore file(s) for commits... IgnoreAction_tooltip=The selected file(s) will not be included by default in your commits. However, you may force the include of these files in a commit by explicitly adding them via "Team->Add" [or whatever the label is]. \n\nSelecting files to ignore by this mechanism will automatically add one or more files named .gitignore in your next commit.

-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris
Alex Blewitt· Apr 23, 2009, 12:32 UTC · re: Francis Galiegue · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

Actually, that's pretty much exactly the format that Eclipse users will be expecting.

CVS: Add to .cvsignore
SVN: Add to svn:ignore

I suggest that we go with that style of format for the menu items, in order to achieve consistency with the way that the other team providers work.

Note also that the tooltip is usually much shorter than that ... it's not a full help description, it explains what it does.

Alex
On 23 Apr 2009, at 13:27, Francis Galiegue wrote:
Show 38 quoted lines
> Le jeudi 23 avril 2009, Alex Blewitt a écrit :
>> diff --git a/org.spearce.egit.ui/plugin.properties
> b/org.spearce.egit.ui/plugin.properties
>> index 523a959..be3b40c 100644
>> --- a/org.spearce.egit.ui/plugin.properties
>> +++ b/org.spearce.egit.ui/plugin.properties
>> @@ -52,10 +52,12 @@ FetchAction_tooltip=Fetch from another repository
>> PushAction_label=&Push To...
>> PushAction_tooltip=Push to another repository
>>
>> +IgnoreAction_label=Add to .git&ignore...
>> +IgnoreAction_tooltip=Ignore the selected resources
>> +
>> GitActions_label=Git
>> GitMenu_label=&Git
>>
>
> The label and tooltip are too "git-specific", IMHO. I'd rather see:
>
> IgnoreAction_label=&Ignore file(s) for commits...
> IgnoreAction_tooltip=The selected file(s) will not be included by  
> default in
> your commits. However, you may force the include of these files in a  
> commit
> by explicitly adding them via "Team->Add" [or whatever the label is].
> \n\nSelecting files to ignore by this mechanism will automatically  
> add one or
> more files named .gitignore in your next commit.
>
> -- 
> Francis Galiegue
> ONE2TEAM
> Ingénieur système
> Mob : +33 (0) 683 877 875
> Tel : +33 (0) 178 945 552
> fge@one2team.com
> 40 avenue Raymond Poincaré
> 75116 Paris
Robin Rosenberg· Apr 23, 2009, 19:19 UTC · re: Alex Blewitt · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

torsdag 23 april 2009 14:32:46 skrev Alex Blewitt <alex@bandlem.com>:
Show 9 quoted lines
> Actually, that's pretty much exactly the format that Eclipse users  
> will be expecting.
> 
> CVS: Add to .cvsignore
> SVN: Add to svn:ignore
> 
> I suggest that we go with that style of format for the menu items, in  
> order to achieve consistency with the way that the other team  
> providers work.
Ouch, top posting....

Anyway, I agree with Alex. My motivation is that there are more than one way to specify ignore. There's .gitignore, .git/info/excludedes and the Team ignore settings themselves. This option specifically messes with .gitignore.

-- robin
Show 47 quoted lines
> Note also that the tooltip is usually much shorter than that ... it's  
> not a full help description, it explains what it does.
> 
> Alex
> 
> On 23 Apr 2009, at 13:27, Francis Galiegue wrote:
> 
> > Le jeudi 23 avril 2009, Alex Blewitt a écrit :
> >> diff --git a/org.spearce.egit.ui/plugin.properties
> > b/org.spearce.egit.ui/plugin.properties
> >> index 523a959..be3b40c 100644
> >> --- a/org.spearce.egit.ui/plugin.properties
> >> +++ b/org.spearce.egit.ui/plugin.properties
> >> @@ -52,10 +52,12 @@ FetchAction_tooltip=Fetch from another repository
> >> PushAction_label=&Push To...
> >> PushAction_tooltip=Push to another repository
> >>
> >> +IgnoreAction_label=Add to .git&ignore...
> >> +IgnoreAction_tooltip=Ignore the selected resources
> >> +
> >> GitActions_label=Git
> >> GitMenu_label=&Git
> >>
> >
> > The label and tooltip are too "git-specific", IMHO. I'd rather see:
> >
> > IgnoreAction_label=&Ignore file(s) for commits...
> > IgnoreAction_tooltip=The selected file(s) will not be included by  
> > default in
> > your commits. However, you may force the include of these files in a  
> > commit
> > by explicitly adding them via "Team->Add" [or whatever the label is].
> > \n\nSelecting files to ignore by this mechanism will automatically  
> > add one or
> > more files named .gitignore in your next commit.
> >
> > -- 
> > Francis Galiegue
> > ONE2TEAM
> > Ingénieur système
> > Mob : +33 (0) 683 877 875
> > Tel : +33 (0) 178 945 552
> > fge@one2team.com
> > 40 avenue Raymond Poincaré
> > 75116 Paris
> 
> 
Ferry Huberts (Pelagic)· Apr 23, 2009, 20:17 UTC · re: Robin Rosenberg · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

Robin Rosenberg wrote:
Show 18 quoted lines
> torsdag 23 april 2009 14:32:46 skrev Alex Blewitt <alex@bandlem.com>:
>> Actually, that's pretty much exactly the format that Eclipse users  
>> will be expecting.
>>
>> CVS: Add to .cvsignore
>> SVN: Add to svn:ignore
>>
>> I suggest that we go with that style of format for the menu items, in  
>> order to achieve consistency with the way that the other team  
>> providers work.
> 
> Ouch, top posting....
> 
> Anyway, I agree  with Alex. My motivation is that there are more
> than one way to specify ignore. There's .gitignore, .git/info/excludedes
> and the Team ignore settings themselves. This option specifically
> messes with .gitignore. 
> 

while we're on the subject... how about also adding the reverse: when a file is ignored then add it to the .gitignore file for 'un-ignoring' (the '!' pattern)

Robin Rosenberg· Apr 23, 2009, 20:26 UTC · re: Ferry Huberts (Pelagic) · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

torsdag 23 april 2009 22:17:56 skrev "Ferry Huberts (Pelagic)" <ferry.huberts@pelagic.nl>:
> while we're on the subject...
> how about also adding the reverse: when a file is ignored then add it to
> the .gitignore file for 'un-ignoring' (the '!' pattern)

I'm not convinced each and everything should have a menu entry. Advanced use of .gitignore should have a .gitignore editor. When we have that the option could perhaps launch the editor automatically if it recognized no-trivial ignore rules. For trivial cases it would just append to the file.

-- robin
Alex Blewitt· Apr 23, 2009, 20:36 UTC · re: Robin Rosenberg · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

On 23 Apr 2009, at 21:26, Robin Rosenberg wrote:
Show 14 quoted lines
> torsdag 23 april 2009 22:17:56 skrev "Ferry Huberts (Pelagic)" <ferry.huberts@pelagic.nl 
> >:
>> while we're on the subject...
>> how about also adding the reverse: when a file is ignored then add  
>> it to
>> the .gitignore file for 'un-ignoring' (the '!' pattern)
>
> I'm not convinced each and everything should have a menu entry.  
> Advanced
> use of .gitignore should have a .gitignore editor. When we have that  
> the
> option could perhaps launch the editor automatically if it  
> recognized no-trivial ignore rules. For trivial cases it would just  
> append to the file.

I don't know of any other SCM that allows you to un-ignore files in the way that Git does; my guess is that most people wouldn't miss it if it weren't there. A .gitignore customised editor is probably overkill too - after all, you can just open it up in a text editor and make changes yourself. I've amended a few .cvsignore files in my time manually, but I wouldn't want to overcomplicate the menu for that.

Alex
Ferry Huberts (Pelagic)· Apr 23, 2009, 20:48 UTC · re: Alex Blewitt · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

Alex Blewitt wrote:
Show 14 quoted lines
> On 23 Apr 2009, at 21:26, Robin Rosenberg wrote:
> 
>> torsdag 23 april 2009 22:17:56 skrev "Ferry Huberts (Pelagic)"
>> <ferry.huberts@pelagic.nl>:
>>> while we're on the subject...
>>> how about also adding the reverse: when a file is ignored then add it to
>>> the .gitignore file for 'un-ignoring' (the '!' pattern)
>>
>> I'm not convinced each and everything should have a menu entry. Advanced
>> use of .gitignore should have a .gitignore editor. When we have that the
>> option could perhaps launch the editor automatically if it recognized
>> no-trivial ignore rules. For trivial cases it would just append to the
>> file.
> 
which is my idea as well.
Show 7 quoted lines
> I don't know of any other SCM that allows you to un-ignore files in the
> way that Git does; my guess is that most people wouldn't miss it if it
> weren't there. A .gitignore customised editor is probably overkill too -
> after all, you can just open it up in a text editor and make changes
> yourself. I've amended a few .cvsignore files in my time manually, but I
> wouldn't want to overcomplicate the menu for that.
> 

just thought it would be an easy thing to do. still think that. an ignore editor can be nice. the gui would be kind of critical in making it comprehensible though.

btw. the argument that no other SCM does this is kind of BS. git does many things no other SCM does, and I also know of other SCMs that do things that git can't do...

Robin Rosenberg· Apr 23, 2009, 21:09 UTC · re: Alex Blewitt · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

torsdag 23 april 2009 22:36:49 skrev Alex Blewitt <alex@bandlem.com>:
Show 6 quoted lines
> I don't know of any other SCM that allows you to un-ignore files in  
> the way that Git does; my guess is that most people wouldn't miss it  
> if it weren't there. A .gitignore customised editor is probably  
> overkill too - after all, you can just open it up in a text editor and  
> make changes yourself. I've amended a few .cvsignore files in my time  
> manually, but I wouldn't want to overcomplicate the menu for that.
Why do we want a plugin for git? We have the command line.
-- robin
Alex Blewitt· Apr 23, 2009, 21:12 UTC · re: Robin Rosenberg · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

On 23 Apr 2009, at 22:09, Robin Rosenberg wrote:
Show 10 quoted lines
> torsdag 23 april 2009 22:36:49 skrev Alex Blewitt <alex@bandlem.com>:
>> I don't know of any other SCM that allows you to un-ignore files in
>> the way that Git does; my guess is that most people wouldn't miss it
>> if it weren't there. A .gitignore customised editor is probably
>> overkill too - after all, you can just open it up in a text editor  
>> and
>> make changes yourself. I've amended a few .cvsignore files in my time
>> manually, but I wouldn't want to overcomplicate the menu for that.
>
> Why do we want a plugin for git? We have the command line.

I mean, it's trivial to open up the .gitignore file in Eclipse as a text file. I was doing that to check the implementation worked whilst adding entries to the .gitignore.

I've seen all manner of bad UIs in applications created because the developer wanted 'total flexibility' and exposed everything via the UI. For something as simple as ignoring a file, which is already a pretty standardised operation across SCMs, I don't see any benefit in making it more complicated than it needs to be.

Alex
Robin Rosenberg· Apr 23, 2009, 23:08 UTC · re: Alex Blewitt · lore

Re: [EGit PATCH] IgnoreAction to add to .gitignore files

torsdag 23 april 2009 23:12:40 skrev Alex Blewitt <alex@bandlem.com>:
Show 23 quoted lines
> 
> On 23 Apr 2009, at 22:09, Robin Rosenberg wrote:
> 
> > torsdag 23 april 2009 22:36:49 skrev Alex Blewitt <alex@bandlem.com>:
> >> I don't know of any other SCM that allows you to un-ignore files in
> >> the way that Git does; my guess is that most people wouldn't miss it
> >> if it weren't there. A .gitignore customised editor is probably
> >> overkill too - after all, you can just open it up in a text editor  
> >> and
> >> make changes yourself. I've amended a few .cvsignore files in my time
> >> manually, but I wouldn't want to overcomplicate the menu for that.
> >
> > Why do we want a plugin for git? We have the command line.
> 
> I mean, it's trivial to open up the .gitignore file in Eclipse as a  
> text file. I was doing that to check the implementation worked whilst  
> adding entries to the .gitignore.
> 
> I've seen all manner of bad UIs in applications created because the  
> developer wanted 'total flexibility' and exposed everything via the  
> UI. For something as simple as ignoring a file, which is already a  
> pretty standardised operation across SCMs, I don't see any benefit in  
> making it more complicated than it needs to be.

A bad GUI is worse than no GUI, so we don't want that. We're not that desperate.

-- robin

← back to recent threads