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(options): add setting to enable git integration for custom worktrees #2092

Merged

Conversation

Subjective
Copy link
Contributor

Many users (myself included) like tracking their dotfiles in bare git repos which rely on setting a custom worktree to work. Unfortunately, this also means that while editing dotfiles, it's not possible to see git diffs in the gutter or open lazygit in the correct repository as without a .git folder it is difficult to know whether a file is being tracked by a bare repo or not.

This PR adds git integration when editing files within custom worktrees, allowing toggleterm and gitsigns gutter highlighting to work as you would expect them to. It also fixes the AstroGitFile event to trigger when a file within a custom worktree is opened, allowing plugins like gitsigns to propely lazy load.

This functionality is opt-in, so those who don't rely on custom worktrees won't notice anything.

To enable it, set the global option git_worktrees to an array-like table, where each entry represents a worktree with entries toplevel and gitdir. This mirrors a similar configuration option in gitsigns (lewis6991/gitsigns.nvim/pull/600). For example, if you have a bare git repo located at ~/.cfg, you can enable git integration for it by setting the following in the AstroNvim global options table:

git_worktrees = { { toplevel = vim.env.HOME, gitdir = vim.env.HOME .. "/.cfg" } }, -- allow custom git_worktrees to be detected

@github-actions
Copy link

github-actions bot commented Jul 5, 2023

Use the following updater settings in your user/init.lua file, restart, and run :AstroUpdate to test this pull request:

  updater = {
    channel = "nightly",
    branch = "feat-git-worktree-integration",
    remote = "Subjective",
    remotes = {
      ["Subjective"] = "Subjective/AstroNvim",
    },
  },

Copy link
Member

@mehalter mehalter left a comment

Choose a reason for hiding this comment

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

This is awesome! Thanks so much! I'll play around with it and hopefully get a new minor release tagged in the coming days :)

@mehalter mehalter merged commit d064c1c into AstroNvim:nightly Jul 5, 2023
5 checks passed
mehalter pushed a commit that referenced this pull request Jul 5, 2023
* feat(options): add setting to enable git integration for custom worktrees

* fix(autocmds): add additional check for AstroGitFile to see if file is in custom worktree

* refactor(autocmds): extract `in_worktree()` to custom utility function `find_worktree()`

* feat(mappings): allow toggle lazygit to automatically load git worktrees if available

* chore(mappings): cleanup redundant toggle lazygit mapping
mehalter pushed a commit that referenced this pull request Jul 5, 2023
* feat(options): add setting to enable git integration for custom worktrees

* fix(autocmds): add additional check for AstroGitFile to see if file is in custom worktree

* refactor(autocmds): extract `in_worktree()` to custom utility function `find_worktree()`

* feat(mappings): allow toggle lazygit to automatically load git worktrees if available

* chore(mappings): cleanup redundant toggle lazygit mapping
@mehalter
Copy link
Member

mehalter commented Jul 5, 2023

@Subjective I did a slight cleanup on nightly so just let me know if I accidentally broke anything :)

@mehalter
Copy link
Member

mehalter commented Jul 5, 2023

@Subjective do you think you could also make a PR on the documentation to add a new recipe page regarding git working trees? It could give a slight introduction to them and what they are and then describe in more details how to set them up and use them :)

Also for reals, thanks again for this contribution. This is a super great new feature!!!

mehalter pushed a commit that referenced this pull request Jul 6, 2023
…ng trees (#2092)

* feat(options): add setting to enable git integration for custom worktrees

* fix(autocmds): add additional check for AstroGitFile to see if file is in custom worktree

* refactor(autocmds): extract `in_worktree()` to custom utility function `find_worktree()`

* feat(mappings): allow toggle lazygit to automatically load git worktrees if available

* chore(mappings): cleanup redundant toggle lazygit mapping
mehalter added a commit that referenced this pull request Jul 6, 2023
* fix(utils): load treesitter when making notifications

* fix(treesitter): ensure markdown treesitter parser

* feat: add `vim.g.git_worktrees` to enable usage of detached git working trees (#2092)

* feat(options): add setting to enable git integration for custom worktrees

* fix(autocmds): add additional check for AstroGitFile to see if file is in custom worktree

* refactor(autocmds): extract `in_worktree()` to custom utility function `find_worktree()`

* feat(mappings): allow toggle lazygit to automatically load git worktrees if available

* chore(mappings): cleanup redundant toggle lazygit mapping

* refactor: clean up implementation of git worktrees

* fix(ui): notifications appearing on top in unintended situations (#2093)

* fix(ui): notifications appearing on top in unintended situations

* fix(ui): increase notification zindex to 175

Co-authored-by: Micah Halter <micah@mehalter.com>

---------

Co-authored-by: Micah Halter <micah@mehalter.com>

* feat: include tables for all map modes in `mappings` and `lsp.mappings`

* chore: use `vim.ui.open` if it's available

* fix(utils): set cursor in a better position (#2094)

* fix: disable `lua_ls` formatting with Neoconf

* fix(lsp): hacky fix for neoconf lazy loading

* fix(heirline): improve lualine integration with statusline

* refactor: simplify notification formatting implementation

* fix(utils): update `is_available` to use the correct lazy API

* chore(snapshot): update lazy_snapshot

---------

Co-authored-by: Josh <56745535+Subjective@users.noreply.github.com>
Co-authored-by: Tiago Muniz de Araujo <tiagomuniz130@gmail.com>
mehalter pushed a commit that referenced this pull request Jul 6, 2023
…ng trees (#2092)

* feat(options): add setting to enable git integration for custom worktrees

* fix(autocmds): add additional check for AstroGitFile to see if file is in custom worktree

* refactor(autocmds): extract `in_worktree()` to custom utility function `find_worktree()`

* feat(mappings): allow toggle lazygit to automatically load git worktrees if available

* chore(mappings): cleanup redundant toggle lazygit mapping
@Subjective
Copy link
Contributor Author

@mehalter whoops, I didn't see the past few messages for some reason, just opened a PR that adds the configuration recipe.

@Subjective Subjective deleted the feat-git-worktree-integration branch July 21, 2023 22:00
MattCassar pushed a commit to MattCassar/AstroNvim that referenced this pull request Sep 9, 2023
…ng trees (AstroNvim#2092)

* feat(options): add setting to enable git integration for custom worktrees

* fix(autocmds): add additional check for AstroGitFile to see if file is in custom worktree

* refactor(autocmds): extract `in_worktree()` to custom utility function `find_worktree()`

* feat(mappings): allow toggle lazygit to automatically load git worktrees if available

* chore(mappings): cleanup redundant toggle lazygit mapping
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

2 participants