oil.nvim icon indicating copy to clipboard operation
oil.nvim copied to clipboard

feature request: Showing the git status of a file

Open primeapple opened this issue 2 years ago • 9 comments

Did you check existing requests?

  • [X] I have searched the existing issues

Describe the feature

It would be very helpful to show the git status of a file (modified, untracked, etc.). A good starting point on how it should look is the following: https://github.com/tamago324/lir-git-status.nvim

Provide background

No response

Additional details

No response

primeapple avatar Apr 11 '23 18:04 primeapple

Hi! This is a very reasonable request and, judging from its inclusion in some other popular file browsers, at least somewhat popular. Unfortunately, it is a moderate amount of work to implement in a mediocre way, and a significant amount of work to do properly. What do I mean by that?

The biggest issue is that git tends to slow down on large repos. Once you start working on a repo of sufficient size, your git status operation will start to take 5, 10, 20 seconds or more. The current way the column plugins are implemented requires all data to be fetched and loaded before rendering the files. We could implement the git status today using this system, but it would mean using this feature in a large repo could experience massive performance problems. I tried nvim-tree out at work once and it took me a while to figure out that the reason I was having terrible UI freezes was its git integration :/

The ideal is to do some sort of progressive rendering. Kick off the git status, but render normally. Then, once the git status is completed, finish filling in that column. The problem with this is that it's significantly more complex. Especially given that the nature of oil as a file browser is that these buffers are also mutable. I spent a bit of time thinking about this a few weeks ago, and couldn't come up with a design that I liked. It would be a large amount of work, significantly complicate the codebase, and introduce a lot of new surface area for bugs. All for a feature that I don't personally use or care for.

That's not to say that I'm completely against git status. If someone wants to create a PR that adds it using the current column plugin methods, I would review it. If someone wants to take a stab a progressive rendering be my guest, but I will most likely not merge (unless you can come up with a better design than mine that addresses my concerns). But this is not something that I will personally be working on in the near future.

stevearc avatar Apr 16 '23 00:04 stevearc

I totally see you concerns. I had problems with slow git integrations as well in various shell prompts, so I see your concerns.

However, since this request is fairly popular (as most filebrowsers implement it), what about the following compromise:

  • Implementing the git status operation without any async (before rendering the files)
  • Make it configurable:
    1. Don't show git status at all
    2. Show only git status of files (should never be slow?)
    3. Show git status of files and directories (could be slow, but can then be turned off)

That way everyone is happy and we still can think of a way to render it async in the future if we really want that.

Btw, a good way to implement only showing the git status of files is described in here: https://stackoverflow.com/a/60318286

primeapple avatar Apr 16 '23 07:04 primeapple

Yep, if done via the current column system then it would function like you suggest. The columns are all opt-in, so if it's not selected it won't run.

I don't have any documentation written up for it yet, but you can look at the "size" column for an example of fetching data, rendering, and parsing. https://github.com/stevearc/oil.nvim/blob/fb8b101d7cb4727d8719ab6ed141330eca997d3f/lua/oil/adapters/files.lua#L50-L73

You'll probably have to do something slightly differently to fetch the git status on a per-directory basis rather than a per-file basis.

stevearc avatar Apr 17 '23 03:04 stevearc

As an additional point for using git, being able to use git mv instead of mv in the background when renaming files would be great as well imho.

Mithrandir2k18 avatar May 24 '23 21:05 Mithrandir2k18

Hi all - I had a go at this and ended up adding git status using extmarks/signs: https://github.com/refractalize/oil-git-status.nvim. The advantage being that the git status output can be added asynchronously, avoiding the performance issues mentioned above by @stevearc.

BTW @stevearc I'd be happy to make a pull request to add it to oil.nvim if you think it makes sense.

refractalize avatar Nov 29 '23 08:11 refractalize

I actually like keeping this as a separate plugin for now. LMK if there are any additional autocmds or anything that would help make the integration smoother

stevearc avatar Dec 24 '23 21:12 stevearc

@refractalize Just a thought: Wouldn't gitoxide offer an advantage in terms of performance for a plugin? Perhaps it would be worthwhile to see if an integration for lua <-> gitoxide could be made.

Uzaaft avatar Jan 02 '24 09:01 Uzaaft

@refractalize Just a thought: Wouldn't gitoxide offer an advantage in terms of performance for a plugin? Perhaps it would be worthwhile to see if an integration for lua <-> gitoxide could be made.

I hadn't seen gitoxide before but having had a quick look I wonder if it would require additional installation instructions or compatibility issues. git itself is pretty much already installed everywhere. Perhaps something to revisit if performance becomes an issue?

refractalize avatar Jan 12 '24 09:01 refractalize