diff --git a/README.md b/README.md index 2892189..ecd7a33 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,11 @@ require("gitlab").setup({ config_path = nil, -- Custom path for `.gitlab.nvim` file, please read the "Connecting to Gitlab" section debug = { go_request = false, go_response = false }, -- Which values to log attachment_dir = nil, -- The local directory for files (see the "summary" section) + reviewer_settings = { + diffview = { + imply_local = false, -- If true, will attempt to use --imply_local option when calling |:DiffviewOpen| + }, + }, help = "?", -- Opens a help popup for local keymaps when a relevant view is focused (popup, discussion panel, etc) popup = { -- The popup for comment creation, editing, and replying exit = "", diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt index 638ce37..23806a9 100644 --- a/doc/gitlab.nvim.txt +++ b/doc/gitlab.nvim.txt @@ -136,6 +136,11 @@ you call this function with no values the defaults will be used: config_path = nil, -- Custom path for `.gitlab.nvim` file, please read the "Connecting to Gitlab" section debug = { go_request = false, go_response = false }, -- Which values to log attachment_dir = nil, -- The local directory for files (see the "summary" section) + reviewer_settings = { + diffview = { + imply_local = false, -- If true, will attempt to use --imply_local option when calling |:DiffviewOpen| + }, + }, help = "?", -- Opens a help popup for local keymaps when a relevant view is focused (popup, discussion panel, etc) popup = { -- The popup for comment creation, editing, and replying exit = "", diff --git a/lua/gitlab/reviewer/diffview.lua b/lua/gitlab/reviewer/diffview.lua index 9163585..79919b5 100644 --- a/lua/gitlab/reviewer/diffview.lua +++ b/lua/gitlab/reviewer/diffview.lua @@ -9,6 +9,12 @@ local M = { tabnr = nil, } +local all_git_manged_files_unmodified = function() + -- check local managed files are unmodified, matching the state in the MR + -- TODO: ensure correct CWD? + return vim.fn.trim(vim.fn.system({ "git", "status", "--short", "--untracked-files=no" })) == "" +end + M.open = function() local diff_refs = state.INFO.diff_refs if diff_refs == nil then @@ -21,9 +27,25 @@ M.open = function() return end - vim.api.nvim_command(string.format("DiffviewOpen %s..%s", diff_refs.base_sha, diff_refs.head_sha)) + local diffview_open_command = "DiffviewOpen" + local diffview_feature_imply_local = { + user_requested = state.settings.reviewer_settings.diffview.imply_local, + usable = all_git_manged_files_unmodified(), + } + if diffview_feature_imply_local.user_requested and diffview_feature_imply_local.usable then + diffview_open_command = diffview_open_command .. " --imply-local" + end + + vim.api.nvim_command(string.format("%s %s..%s", diffview_open_command, diff_refs.base_sha, diff_refs.head_sha)) M.tabnr = vim.api.nvim_get_current_tabpage() + if diffview_feature_imply_local.user_requested and not diffview_feature_imply_local.usable then + u.notify( + "There are uncommited changes in the working tree, cannot use 'imply_local' setting for gitlab reviews. Stash or commit all changes to use.", + vim.log.levels.WARN + ) + end + if state.INFO.has_conflicts then u.notify("This merge request has conflicts!", vim.log.levels.WARN) end diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index 62758cc..1531d33 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -13,6 +13,11 @@ M.settings = { log_path = (vim.fn.stdpath("cache") .. "/gitlab.nvim.log"), config_path = nil, reviewer = "diffview", + reviewer_settings = { + diffview = { + imply_local = false, + }, + }, attachment_dir = "", help = "?", popup = {