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: configurable auto attach #918

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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
Loading