rbong / vim-flog

A blazingly fast, stunningly beautiful, exceptionally powerful git branch viewer for Vim/Neovim.
795 stars 22 forks source link

None of the collapse bindings/functions seem to work #130

Closed ferdinandyb closed 3 months ago

ferdinandyb commented 4 months ago

Coming from the Flog -patch not showing commit bodies, I checked what the available tools are for checking it, and I found the bindings for collapsing/opening the commit body, but they don't seem to do anything as far as I can tell. I even tried :call flog#floggraph#collapse#Toggle("ee2e7236abbf657d4f9dc44fa1a4150b2130f6eb") to no effect. Am I misunderstanding something here? Also is there an alternative way to show output similar to plain git log?

rbong commented 4 months ago

Are you trying to use the collapse/expand bindings with multiline commits or single-line commits? They only work with commits that have more than one line according to the options you specify. In other words, the commit has to actually have a body to show/hide.

So if I open a repo with -patch, which causes the commit body to consist of the commit diff, and I press < over some commits, this is how the commits look.

2024-07-20-182844_984x146_scrot

If you are trying this with multiline commits and it isn't working, please post the steps to recreate including whether you're using vim/nvim, your vimrc/init file, the repo it's not working with, and the command/keybindings you're trying to use.

I even tried :call flog#floggraph#collapse#Toggle("ee2e7236abbf657d4f9dc44fa1a4150b2130f6eb")

That probably wouldn't work regardless unless if you have very long commit hashes in your output according to your git settings. Generally commit hashes it expects are the short hash.

Also is there an alternative way to show output similar to plain git log?

You can use -no-graph or gx to hide the graph branches, and if you want a format closer to the default git log, you'll have to specify -format=.... For more information on the placeholders you can use in your format, see man git-log and see format:<format-string> for all the different options. I'm sorry I don't know a similar format to the default git-log you can use.

ferdinandyb commented 4 months ago

Ah, ok I tested it with -patch and indeed it works. What confused me, was the documentation

Collapse the body of the commit under the cursor.

Where I assumed by the commit body you mean, well, the commit body :D But it's actually any extra lines associated with the output format specified to flog. I'd probably change the wording here because the commit body is a very specific thing.

Btw, have you considered allowing to pass something like --pretty=email directly? Anyhow I did come up with this:

git log --pretty=format:"commit %H%nAuthor%an%n%ad%n%n%s%n%n%b"

which is not direclty git log default, but good enough for poking around now. It's a bit weird, but you can pass it with some escaping: :Flog -format=commit\ %H%nAuthor\ %an%n%ad%n%n%s%n%n%b. So I guess a bit of time and I can figure it out (although being able to essentially run git log --pretty=medium would make it easier, :Flog -raw-args=--pretty=medium gives very weird results).

Last question is: is it possible to open Flog collapsed by default?

rbong commented 4 months ago

What confused me, was the documentation

Sorry, I can see how it would be confusing. I'll fix it when I get a chance.

Btw, have you considered allowing to pass something like --pretty=email directly?

being able to essentially run git log --pretty=medium would make it easier

Simply not possible unless if git log allows embedding predefined formats inside custom formats.

The way Flog works is it passes a custom format to git log that looks something like this:

__ARBITRARY_TOKEN_VALUE__
(format that contains data Flog needs)
__SOME_OTHER_TOKEN__
(user format)
__ANOTHER_TOKEN__

So when you pass something like --pretty=medium or --pretty-email, Flog can get absolutely no data out of git log.

The best choice if you need these formats fast, unfortunately, is to use git log --graph --pretty=format on the command line.

I suppose I could recreate these formats as best I could in Flog and offer them as predefined format, but I don't think that would be a good fit. Flog is different than the git log command because commit details are visible in splits and don't have to be inside of the graph window.

is it possible to open Flog collapsed by default?

Not yet but I want to add a way to do this. I will keep this issue open to implement this.

ferdinandyb commented 3 months ago

Thanks. You actually convinced me about flog != git log. Thanks for considering implementing the auto-collapse!

rbong commented 3 months ago

I added options for -default-expanded and -default-collapsed.

Let me explain how these arguments work; they will work with :Flog -default-expanded and :Flog -default-collapsed, or with :Flogsetargs -default-expanded and :Flogsetargs -default-collapsed. But how I mostly expect them to be used is with let g:flog_permanent_default_opts = { 'default_collapsed': true }. By default, commits are still expanded.

I mostly expect this to to be used with g:flog_permanent_default_opts for now. I think it could be useful to have an option to toggle expanding/collapsing all commits and turn on/off the option at the same time, but much like this feature I will wait for someone to request it.

rbong commented 3 months ago

I added g< and g> (<Plug>(FlogCollapseAll)/<Plug>(FlogExpandAll)). These mappings clear all expanded/collapsed commits and set default_collapsed on/off respectively.

Please start a new issue if there's any problems with the new mappings.