Skip to content

Commit

Permalink
feat: configurable auto attach (#918)
Browse files Browse the repository at this point in the history
* feat: configurable auto attach

* fixup! feat: configurable auto attach
  • Loading branch information
martinra committed Jan 5, 2024
1 parent d195f0c commit 3e6e91b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ require('gitsigns').setup {
watch_gitdir = {
follow_files = true
},
auto_attach = true,
attach_to_untracked = true,
current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
current_line_blame_opts = {
Expand Down
6 changes: 6 additions & 0 deletions doc/gitsigns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ of the default settings:
watch_gitdir = {
follow_files = true
},
auto_attach = true,
attach_to_untracked = true,
current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
current_line_blame_opts = {
Expand Down Expand Up @@ -713,6 +714,11 @@ preview_config *gitsigns-config-preview_config*
Option overrides for the Gitsigns preview window. Table is passed directly
to `nvim_open_win`.

auto_attach *gitsigns-config-auto_attach*
Type: `boolean`, Default: `true`

Automatically attach to files.

attach_to_untracked *gitsigns-config-attach_to_untracked*
Type: `boolean`, Default: `true`

Expand Down
5 changes: 4 additions & 1 deletion lua/gitsigns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ M.setup = async.void(function(cfg)
require('gitsigns.git')._set_version(config._git_version)
end

setup_attach()

if config.auto_attach then
setup_attach()
end
setup_cwd_head()

M._setup_done = true
Expand Down
9 changes: 9 additions & 0 deletions lua/gitsigns/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
--- @field current_line_blame_formatter_nc string|Gitsigns.CurrentLineBlameFmtFun
--- @field current_line_blame_opts Gitsigns.CurrentLineBlameOpts
--- @field preview_config table<string,any>
--- @field auto_attach boolean
--- @field attach_to_untracked boolean
--- @field yadm { enable: boolean }
--- @field worktrees {toplevel: string, gitdir: string}[]
Expand Down Expand Up @@ -562,6 +563,14 @@ M.schema = {
]],
},

auto_attach = {
type = 'boolean',
default = true,
description = [[
Automatically attach to files.
]],
},

attach_to_untracked = {
type = 'boolean',
default = true,
Expand Down

0 comments on commit 3e6e91b

Please sign in to comment.