Ingest an existing `.gitignore` file from the disk and then run filters against that
Closed this issue · 5 comments
Hello, this class seems awesome and I apologize in advance if my question seems stupid.
I have a repo on the disk, and it has an existing .gitignore
file that I want respected. Meaning, parse the .gitignore
file and then apply the rules in it. Is there a way to do that?
Might I proceed as the following (pseudo code):
namespace Ignore
{
public class Ignore
{
/*...*/
public void Ingest(string pathname /*pathname of the .gitignore file*/)
{
try
{
if (!File.Exists(pathname)) return;
if (!".gitignore".Equals(Path.GetFileName(pathname)) return;
var lines = File.ReadAllLines(pathname).ToList();
if (lines == null) return;
if (lines.Count == 0) return;
Add(lines.ToArray());
}
catch(Exception ex)
{
/* log the exception or handle it in another fashion */
}
}
/* ... */
}
Listing 1. Proposed methodology for ingesting an existing .gitignore
file that is already on the disk.
Would the code above work?
This should work but I don't necessarily think we should add it to the library itself. The caller of the library just has to do a ReadAllLines and pass it to the Add() method so it should be pretty straightforward.
That was also my thinking but I did want to validate it. Thanks for that. At the very least, the code snippet above is offered above for educational purposes.
Question: I request permission to be allowed to contribute to your project's Wiki so I can post the snippet there. My only concern with it remaining in this issue is, once this issue is closed, I'm worried that the code snippet might no longer be easily accessible.
Sure thank you! There is no wiki right now but we can start one. Do you have permissions to edit/start the wiki?
Figure 1. Tabs displayed to me as a repository "viewer."
Hello @goelhardik I just checked and there does not seem to be a 'Wiki' tab on my display... Correct me if I am wrong, but I am thinking that starting a Wiki is only available to repo owners such as yourself. And if you can designate me as a "contributor," then it would be my speculation that doing that would then open it up to myself.
I respectfully request to be a "contributor" so I can also contribute ideas / suggestions for improving the code. Thank you.
For example, I'd like to enhance it to make it more "SOLID" (see, e.g, Wikipedia). Also, would like to make it possible to "unload" a .gitignore
file too...by clearing out the internal rules list and such so you can then load a new .gitignore
file without having to throw away the object and start fresh etc., say, when a user of this class wishes to access a new Git repo on their hard drive.
Thanks @astrohart. I have added you as a collaborator. You should be able to access the Wiki now.