lualine.nvim
lualine.nvim copied to clipboard
feat: commit component
Hi,
This PR adds a new component called commit which displays the difference in commits count between the current branch and the upstream or master branch. It's useful to get a visual indication in the editor that some commits are available in origin.

This is what the component looks like, next to the branch component. First, with the red color, you can see that there are 2 commits in the master branch that are conflicting, then with the gray color, you see that no commits to pull are available, and lastly, you can see that one commit is not pushed to the current branch remote (no conflict with remote).
To get updates on new commits the component watches some files in the .git/ dir. Also, the git fetch command is run from time to time to get new commits on the remote. Only the current buffer repo is actively watched. Watch on previously discovered repositories (when many buffers from different repositories are loaded) is suspended, and resumed on BufEnter. This approach makes git commands run in the repository (outside of the neovim) to be reflected in the editor.
I took some code and a general approach from the branch component. I think that the find_git_dir function could be shared between those two.
I've been using this component for about a week and looks good. This component, probably will not work on Windows due to the use of sh -c and pipes. I'm not sure if I did everything in the right way in Lua, if not please comment.
This looks quite interesting. I'm in favor of adding this component in general. There are a decent amount of changes in this pr it'll take me a while to review the whole thing.
Hey, any chance of getting this merged?
Just found this via search and bumping this, so it does not go lost amidst all the other open PRs.
This is indeed would indeed be a great feature to have.
@gzbd just gave your fork a try and so far, it looks good to me. Since your fork does not allow issues, and in the hope of taking some burden from shadmansaleh, some feedback on some minor things (only from a user perspective, haven't looked at the code)
- There is no option to remove the leading git-icon. No other lualine component has a leading icon, so for consistency this should probably be removed or made an opt-in. I tried removing it via
fmt, but apparently it's even hard-coded? (Also, the git-icon is a nerdfont, which should not be added by default, since not everyone uses nerdfonts.) - The three arrow icons do not align well in multiple fonts I tried. The component could use these arrows, which also work without nerdfont: →↓↑
- On startup, I briefly get three numbers with the same color before the component loads the correct stats. I think it'd be better if the component should nothing before the correct numbers are calculated.
show_only_divergedshould by default betrue, notfalse. That would make it consistent with the behavior of thediffcomponent.
@chrisgrieser thanks for the feedback. I'll work on this over the weekend
One issue I noted with the commit component: there seems to be some timeout for git fetch missing.
Yesterday, github was intermittently down, resulting in various git operation failing when called in the terminal. In my nvim, the result was quite peculiar, since I got a lot of errors from various plugins like nvim-lint (which have nothing to do with github) about their jobs failing. The errors stopped at the same time the github issues were fixed?
My guess what happened is that the commit component's job never got resolved, keeping it in a never-ending loop, and with each fetch-interval, there was another job added, it started blocking other plugin's jobs?
edit: false alarm, it was actually the other way round, a bug in nvim-lint created non-terminating jobs that were blocking lualine.
Hey, I applied some changes as requested. Can you take a look?