diff options
author | jakob.stendahl <jakob.stendahl@infomedia.dk> | 2024-06-19 18:14:39 +0200 |
---|---|---|
committer | jakob.stendahl <jakob.stendahl@infomedia.dk> | 2024-06-19 18:14:39 +0200 |
commit | 91adf175d2d6041ac909d9916b16158433b803d9 (patch) | |
tree | 740a5f466803547bc180f2240a4df3c03cd5cbe3 | |
parent | 9d44f2c198d7bd5d347362c00c1afbc48a0c4140 (diff) | |
download | dotfiles-91adf175d2d6041ac909d9916b16158433b803d9.tar.gz dotfiles-91adf175d2d6041ac909d9916b16158433b803d9.zip |
Allow specifying revision
-rwxr-xr-x | Common/nvim/lua/helper_functions.lua | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Common/nvim/lua/helper_functions.lua b/Common/nvim/lua/helper_functions.lua index 7f2be82..3067fd7 100755 --- a/Common/nvim/lua/helper_functions.lua +++ b/Common/nvim/lua/helper_functions.lua @@ -137,8 +137,9 @@ vnoremap <leader><leader>s :'<,'>GitHistoryForLine<CR> ]] -- Compare git to revision -function GRevisionDiff() - local handle = io.popen("git diff --name-only $(git merge-base HEAD master)") +function GRevisionDiff(args) + local branch = args.args ~= "" and args.args or "master" + local handle = io.popen("git diff --name-only $(git merge-base HEAD " .. branch .. ")") local files = handle:read("*a") handle:close() @@ -146,18 +147,18 @@ function GRevisionDiff() vim.fn.setqflist({}) for _, file in ipairs(files) do if file ~= '' then - local handle = io.popen("git diff --stat HEAD master " .. file .. " | head -n 1 | awk -F '|' '{print $2}'") + local handle = io.popen("git diff --stat HEAD " .. branch .. " " .. file .. " | head -n 1 | awk -F '|' '{print $2}'") local diffstat = handle:read("*a") handle:close() vim.fn.setqflist({}, 'a', { - title = 'GRevisionDiff: changed files', + title = 'GRevisionDiff: with ' .. branch, items= {{filename = file, text = diffstat}} }) end end vim.cmd("copen") end -vim.api.nvim_create_user_command('GRevisionDiff', GRevisionDiff, {bang=false, desc=''}) +vim.api.nvim_create_user_command('GRevisionDiff', GRevisionDiff, {nargs = "?", desc = 'Show diff of current branch with the specified branch (default: master)'}) function close_existing_diff_windows() local windows = vim.api.nvim_list_wins() @@ -172,11 +173,12 @@ end function GRevisionDiffOpen() vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<CR>", true, false, true), "n", true) local qf_title = vim.fn.getqflist({title = 0}).title - if qf_title == 'GRevisionDiff: changed files' then + if qf_title:match('GRevisionDiff: with') then local filename = vim.fn.expand("<cfile>") + local branch = qf_title:match('with (.+)$') or "master" close_existing_diff_windows() vim.defer_fn(function() - vim.cmd("Gvdiffsplit master ") + vim.cmd("Gvdiffsplit " .. branch) end, 50) end end |