juneedahamed / vc.vim

Support for SVN, Git, HG and BZR
47 stars 9 forks source link

Suggestion: Provide function to get branch for statusline #12

Open idbrii opened 6 years ago

idbrii commented 6 years ago

Would be nice to have vc#BranchName() so users can add the branch name to their statusline. Even better to have vim-airline integration.

I dug through the code and frmtbranchname seems to be close to the right function, but even following the usage in vc#log#affectedfiles I couldn't get it to work (on svn).

juneedahamed commented 6 years ago

For now added branch name while browsing and viewing logs. Airline integration um need to spend some time to understand how to do it maybe some time later. Quick look for the branch name does not work slowed down vim as the call kept executing for every cursor movement, had the branch name cached. Needs a proper integration. Oh the cached call for vc#BranchName, need to set up global variable g:vc_enable_buffers to 1 for it to work. once the variable is set vc#BranchName should give u the branch name. Try :echo vc#BranchName() after setting the variable.

idbrii commented 6 years ago

Awesome!

I started working on this as well and came up with this: https://github.com/idbrii/daveconfig/blob/master/multi/vim/autoload/david/svn.vim#L48

I store the branch name for each buffer and clear the stored name when leaving a window. Should keep things pretty up to date.

I'm on an old version of airline, but it doesn't look too different. Make a new version of s:has_vcscommand and set b:airline_head to the return value of my david#svn#get_branch. No idea how you could integrate with airline without modifying it. I wanted to look into writing a PR to change that, but now that my hacked up config has branches the priority is low for me.

Also, FYI it looks like VCScommand support is disabled by default in airline so vim-vc could probably replace it as the only svn provider.

idbrii commented 6 years ago

My PR to add branch name customization support to vim-airline was accepted!

https://github.com/vim-airline/vim-airline/pull/1683

vc users should be able to set this:

let g:airline#extensions#branch#custom_head = 'vc#BranchName'

However, when I tried it I got the name of a folder instead of the branch. From a file C:/code/game/Assets/Scripts/Cameras/Scripts/OrbitCam.cs, vc#BranchName() on bef2811 returns Assets instead of trunk.

(As I said above, I have a working solution that doesn't require intrusive changes to vc, so I'm happy. I'm only replying if it's useful to you.)