Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question/Discussion] using .git/info/exclude to exclude local file instead of .gitignore #2014

Closed
gozes opened this issue Jun 24, 2022 · 15 comments

Comments

@gozes
Copy link

gozes commented Jun 24, 2022

should there be an option to use .git/info/exclude in the File window?
A bit of context from the git docs as to what .git/info/exclude is

Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the $GIT_DIR/info/exclude file.
FYI this file has the same format as .gitignore

Your thoughts
I really think it will be quite useful to have let say I in the File window to add files to the exclude file along side the i command we already have.

I use this quite a bit to put my editor config for a repo. Another good example of using this is to put the VSCode devcontainer.json used in the Remote container extension so that you can have your own container to run a project in. Has anyone else used the exclude file before if so what do you think will it be useful to have this in lazygit?

@mark2185
Copy link
Collaborator

Is this just a .gitignore that isn't committed, if I'm reading into this right?

@gozes
Copy link
Author

gozes commented Jun 24, 2022

@mark2185 yup it just goes inside of .git/info/ instead of the root of your project and I believe it has to be called exclude

@mark2185
Copy link
Collaborator

Sounds like a neat addition, didn't even know about it.

Would you be interested in opening a PR? The logic should be the same as with adding to .gitignore, only the destination differs.

@gozes
Copy link
Author

gozes commented Jun 24, 2022

@mark2185 I would love too, can you point me ate where the logic for this is. I was looking but was having a hard time finding it :)

@mark2185
Copy link
Collaborator

mark2185 commented Jun 24, 2022

Off the top of my head - look into the files changed in PR #2004, that should be a start. Look where are the changed functions called from.

Let me know if you need additional pointers and I'll take a closer look next time I'm at my laptop.

@gozes
Copy link
Author

gozes commented Jun 24, 2022

So having another look at this it seems like there are a few references to gitignore in git_commands package in working_tree.go and in file_controller.go I'm still looking at the code trying to find the best place to add this. I have yet to find how these things relate to the file window in the GUI.

@mark2185
Copy link
Collaborator

The one you're looking for is in files_controller.go, this sets the function ignore as the handler for when someone presses IgnoreFile (which is i by default).

What we're trying to go for now is adding a new mapping (I) which would do the same thing as ignore(), but write to a different file in the end. Since it does exactly the same thing, I'd suggest making ignore take an additional argument beside the filetree.FileNode, which would be a string representing the destination file and then just pass the correct one when the user presses i or I. Of course, the subsequent call to Ignore() should also be modified.

The handlers could be ordinary lambdas that do what checkSelectedFileNode does before invoking ignore(node, <correct destination file>). Maybe @jesseduffield has a better idea how to do that, but I'd rather leave that for the review.

Does that help? Do let us know if there's anything else to clear up! :)

@gozes
Copy link
Author

gozes commented Jun 24, 2022

ok so just did my first try on it and send you a draft PR for it. It probably needs some more work. One question I still have is how to actually add the I default keybind binding. Happy to keep working with you on this as I'm still finding my feet in the codebase so any guidance/support you can offer is greatly appreciated

@gozes
Copy link
Author

gozes commented Jun 24, 2022

The one you're looking for is in files_controller.go, this sets the function ignore as the handler for when someone presses IgnoreFile (which is i by default).

What we're trying to go for now is adding a new mapping (I) which would do the same thing as ignore(), but write to a different file in the end. Since it does exactly the same thing, I'd suggest making ignore take an additional argument beside the filetree.FileNode, which would be a string representing the destination file and then just pass the correct one when the user presses i or I. Of course, the subsequent call to Ignore() should also be modified.

The handlers could be ordinary lambdas that do what checkSelectedFileNode does before invoking ignore(node, <correct destination file>). Maybe @jesseduffield has a better idea how to do that, but I'd rather leave that for the review.

Does that help? Do let us know if there's anything else to clear up! :)

Just saw this after making the draft PR. will have look again at this over the weekend and amend my PR with your comments :)

It definitely helps :)

@gozes
Copy link
Author

gozes commented Jun 25, 2022

@mark2185 looking at this at the moment. I don't think your suggestion will work because it calls to WorkingTree.Ignore so I have refactored WorkingTree.Ignore into a more general Omit function in WorkingTree so I can use it for both ignoring and excluding. I'm trying to refactor ignore in file_controller so I can have a clear separation between ignoring and excluding. :)

@mark2185
Copy link
Collaborator

I have refactored WorkingTree.Ignore into a more general Omit function

That's perfectly reasonable, it could/should take a parameter as the destination file.

Of course, the subsequent call to Ignore() should also be modified.

That, as well as the rest of the steps down to the bottom, such as WorkingTree.Ignore, as you've noted :)

@gozes
Copy link
Author

gozes commented Jun 25, 2022

@mark2185 ok so the Refactoring was successful and ignore is back to working order. However, I can't get exclude (a.k.a I) to show up in the menu and I'm not sure why. Have I missed something?

@gozes
Copy link
Author

gozes commented Jun 25, 2022

BTW @jesseduffield your video on adding a feature was really helpful in getting to grips with the bits of the codebase I have to touch. Thank you for making it. I hope you will make more like it in the future

@jesseduffield
Copy link
Owner

No worries @gozes ! I'm in the process of trying to free up more time to make more videos / guides so hopefully there'll be more in the near future

@mark2185
Copy link
Collaborator

mark2185 commented Jul 5, 2022

I believe this can be closed now :)

Great work! @gozes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants