Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fallback bare repo (yadm support) #218

Merged
merged 1 commit into from
May 5, 2022
Merged

feat: add fallback bare repo (yadm support) #218

merged 1 commit into from
May 5, 2022

Conversation

ibhagwan
Copy link
Contributor

Title: should solve #149.

First, ty for this wonderful plugin, love the meticiousness of your code :-)

That said, before I continue further with this PR (doc, testing, etc) I want to make sure this is how you'd approach it (settings inside cli/Git.lua and my fallback_args approach).

This PR adds a test for each new GitObject coming from a buffer (i.e. has GitObject) if the current file is inside a git a dir, if not it will use a new cwd as well as supply --git-dir and --work-tree to the git command so that vgit can find the hunks, etc, basically replacing the git command with git --git-dir <path> --work-tree <path>.

In order to use the new setting you need to add the below to your setup:

require("vgit").setup {
  settings = {
    git = {
      cmd = 'git', -- optional setting, not really required
      fallback_cwd = vim.fn.expand("$HOME"),
      fallback_args = {
        "--git-dir",
        vim.fn.expand("$HOME/dots/yadm-repo"),
        "--work-tree",
        vim.fn.expand("$HOME"),
      },
    },
  }
}

Now if I my current working directory isn't a git repo or the file opened is outside the current working directory vgit is still able to show gutter signs as well as stage, reset hunks.

IMO this is better than gitsigns support for yadm where it basically falls back to running all git commands with the yadm wrapper script as this can support any git bare repo whether you have yadm installed or not.

This is WIP, wasn't tested fully and I'm pretty sure there are a few issues hiding, just wanted to gauge your interest/input before I continue.

@ibhagwan
Copy link
Contributor Author

ibhagwan commented May 1, 2022

1409788 - this commit also adds git diff stats in the same buffer variable as gitsigns, vim.b.gitsigns_status_dict requested in #157, #212.

Let me know if you prefer I can create a separate PR just for that or since it's two different commits we can leave it at that?

@tanvirtin
Copy link
Owner

@ibhagwan Thanks for this pull request, sorry for being late in getting to this, but I really appreciate this PR and your interest in this plugin :)

I recently pushed a huge update to VGit. Hopefully it's the last time I am making such a huge change. Going forward it's going to be small incremental changes only, as most of the dust around architecture has settled.

Can you pull the latest changes, some of the stuff you are working on has changed slightly.

1 similar comment
@tanvirtin
Copy link
Owner

@ibhagwan Thanks for this pull request, sorry for being late in getting to this, but I really appreciate this PR and your interest in this plugin :)

I recently pushed a huge update to VGit. Hopefully it's the last time I am making such a huge change. Going forward it's going to be small incremental changes only, as most of the dust around architecture has settled.

Can you pull the latest changes, some of the stuff you are working on has changed slightly.

@tanvirtin
Copy link
Owner

1409788 - this commit also adds git diff stats in the same buffer variable as gitsigns, vim.b.gitsigns_status_dict requested in #157, #212.

Let me know if you prefer I can create a separate PR just for that or since it's two different commits we can leave it at that?

1409788 - this commit also adds git diff stats in the same buffer variable as gitsigns, vim.b.gitsigns_status_dict requested in #157, #212.

Let me know if you prefer I can create a separate PR just for that or since it's two different commits we can leave it at that?

Having the implementation of this feature in a separate PR would be awesome!

1 similar comment
@tanvirtin
Copy link
Owner

1409788 - this commit also adds git diff stats in the same buffer variable as gitsigns, vim.b.gitsigns_status_dict requested in #157, #212.

Let me know if you prefer I can create a separate PR just for that or since it's two different commits we can leave it at that?

1409788 - this commit also adds git diff stats in the same buffer variable as gitsigns, vim.b.gitsigns_status_dict requested in #157, #212.

Let me know if you prefer I can create a separate PR just for that or since it's two different commits we can leave it at that?

Having the implementation of this feature in a separate PR would be awesome!

lua/vgit/cli/Git.lua Outdated Show resolved Hide resolved
lua/vgit/features/LiveGutter.lua Outdated Show resolved Hide resolved
lua/vgit/features/LiveGutter.lua Outdated Show resolved Hide resolved
lua/vgit/settings/git.lua Show resolved Hide resolved
lua/vgit/features/LiveGutter.lua Outdated Show resolved Hide resolved
lua/vgit/settings/git.lua Show resolved Hide resolved
Copy link
Owner

@tanvirtin tanvirtin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more comments, other than that code is looking good to me 👍🏾

lua/vgit/git/cli/Git.lua Outdated Show resolved Hide resolved
lua/vgit/git/cli/Git.lua Outdated Show resolved Hide resolved
@tanvirtin tanvirtin merged commit 78cfd5b into tanvirtin:main May 5, 2022
@lnc3l0t
Copy link

lnc3l0t commented May 6, 2023

It wasn't immediately clear to me, so I don't know if this will be helpful to anyone else.

You shouldn't set the 'fallback_cwd' to ~ if you have bare repositories pointing tracking files in home.
For example if you manage your dotfiles with a bare git repo inside a folder in HOME rather than using YADM.

If you do, VGit won't recognize any files in the home folder (like .bashrc) since it will believe the current working directory (e.g. ~) is a repository and won't use the fallback_args to handle the file as if it was inside a bare repo.

If you use ~/.dotfiles as your dotfiles' bare repo:

require("vgit").setup {
  settings = {
    git = {
      -- DON'T SET fallback_cwd to home
      -- fallback_cwd = vim.fn.expand("$HOME"),
      fallback_args = {
        "--git-dir", vim.env.HOME.."/.dotfiles"),
        "--work-tree", vim.env.HOME,
      },
    },
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants