purarue / yadm-git.vim

Integrates yadm with vim-fugitive and vim-gitgutter, so you can manage your dotfiles without leaving vim
MIT License
12 stars 2 forks source link

Is there a chance to have the same support for Gitsigns plugin ? #3

Closed eshepelyuk closed 5 months ago

eshepelyuk commented 5 months ago

The question.

purarue commented 5 months ago

Hi, I've been thinking about this a bit since gitsigns dropped yadm support.

I don't really use fugitive as much as I used to, so I have disabled the plugin and just use a terminal whenever I want to commit stuff on my dotfiles.

I was able to figure out how to show modified git hunks with gitsigns, my lazy file here, by adding the _on_attach_pre function:

        -- yadm support. checks if the current file is tracked by yadm.
        -- If it is, set the gitdir and toplevel, otherwise just return
        -- and call callback with no arguments
        _on_attach_pre = function(_, callback)
            -- a global I set on nvim launch, so I dont have to check
            -- each time this is run
            if not has_yadm then
                return callback()
            end
            vim.schedule(function()
                -- if buffer is not a file, don't change anything
                local file = vim.fn.expand("%:p")
                if not vim.fn.filereadable(file) then
                    return callback()
                end
                local repo = vim.fn.expand("~/.local/share/yadm/repo.git")
                -- use yadm ls-files to check if the file is tracked
                require("plenary.job")
                    :new({
                        command = "yadm",
                        args = { "ls-files", "--error-unmatch", file },
                        on_exit = vim.schedule_wrap(function(_, return_val)
                            if return_val == 0 then
                                return callback({
                                    gitdir = repo,
                                    toplevel = os.getenv("HOME"),
                                })
                            else
                                return callback()
                            end
                        end),
                    })
                    :sync()
            end)
        end,

Not sure if there are edge cases I haven't encountered yet, but it seems to work so far.

Have been weighing if I should document that somewhere here, or archive this plugin and create a new thing that just works with gitsigns.

In any case, I dont think I would add the lua code here as well, it would likely be a separate repository that just gets required when config for gitsigns is run.

If anyone has suggestions for how to proceed, let me know

purarue commented 5 months ago

Pushed it as a plugin here if you want to test: https://github.com/seanbreckenridge/gitsigns-yadm-callback/

eshepelyuk commented 5 months ago

Hello,

Thank you for picking this up and creating a dedicated plugin. I will definitely give it a try a bit later and provide a feedback.

May I suggest to rename it to the anem without suffix -callback, maybe gitsigns-yadm.nvim` or smth like this ?

purarue commented 5 months ago

May I suggest to rename it to the anem without suffix -callback, maybe gitsigns-yadm.nvim` or smth like this ?

Yeah, probably a good idea. Done

eshepelyuk commented 5 months ago

Great, thank you !

WDYT will it be a good idea to leverage more APIs from gitsigns.nvim, i.e. I've tried to research their codebase and maybe it's possible to revive "old" YADM support using plugins's own API.

eshepelyuk commented 5 months ago

i am closign this issue, any other can be tracked in the new plugin.

purarue commented 5 months ago

WDYT will it be a good idea to leverage more APIs from gitsigns.nvim, i.e. I've tried to research their codebase and maybe it's possible to revive "old" YADM support using plugins's own API.

I've gone through the removal commit and matched any of the logic that was used there here:

https://github.com/seanbreckenridge/gitsigns-yadm.nvim/commit/c993b83d6c080c16a6087217e5517d25359c9838

I think thats all the integration did, if you notice some other feature missing let me know

eshepelyuk commented 5 months ago

Hello @seanbreckenridge Tried it, for now - works fine. Thanks for the plugin.