@ -95,29 +95,46 @@ end
M.commits = function ( opts )
M.commits = function ( opts )
opts = config.normalize_opts ( opts , config.globals . git.commits )
opts = config.normalize_opts ( opts , config.globals . git.commits )
if not opts then return end
if not opts then return end
opts.preview = path.git_cwd ( opts.preview , opts )
if opts.preview then
opts.preview = path.git_cwd ( opts.preview , opts )
if opts.preview_pager then
opts.preview = string.format ( " %s | %s " , opts.preview , opts.preview_pager )
end
end
return git_cmd ( opts )
return git_cmd ( opts )
end
end
M.bcommits = function ( opts )
M.bcommits = function ( opts )
opts = config.normalize_opts ( opts , config.globals . git.bcommits )
opts = config.normalize_opts ( opts , config.globals . git.bcommits )
if not opts then return end
if not opts then return end
local bufname = vim.api . nvim_buf_get_name ( 0 )
if not bufname or # bufname == 0 then
utils.info ( " 'bcommits' is not available for unnamed buffers. " )
return
end
-- if caller did not specify cwd we attempt to auto detect the
-- file's git repo from its parent folder, could be further
-- optimized to prevent the duplicate call to `git rev-parse`
-- but overall it's not a big deal as it's a pretty cheap call
-- first 'git_root' call won't print a warning to ':messages'
if not opts.cwd and not opts.git_dir then
opts.cwd = path.git_root ( { cwd = vim.fn . expand ( " %:p:h " ) } , true )
end
local git_root = path.git_root ( opts )
local git_root = path.git_root ( opts )
if not git_root then return end
if not git_root then return end
local file = path.relative ( vim.fn . expand ( " %:p " ) , git_root )
local file = path.relative ( vim.fn . expand ( " %:p " ) , git_root )
opts.cmd = opts.cmd .. " " .. file
if opts.cmd : match ( " <file " ) then
local git_ver = utils.git_version ( )
opts.cmd = opts.cmd : gsub ( " <file> " , file )
-- rotate-to first appeared with git version 2.31
else
if git_ver and git_ver >= 2.31 then
opts.cmd = opts.cmd .. " " .. file
-- check if the user added a pipe (e.g. `| delta`)
end
local before_pipe = opts.preview : match ( " [^|]+ " )
if type ( opts.preview ) == ' string ' then
local after_pipe = opts.preview : match ( " |.*$ " ) or ' '
opts.preview = opts.preview : gsub ( " <file> " , vim.fn . shellescape ( file ) )
opts.preview = before_pipe
opts.preview = path.git_cwd( opts.preview , opts )
.. " --rotate-to= "
if opts.preview_pager then
.. vim.fn . shellescape ( file )
opts.preview = string.format ( " %s | %s " , opts.preview , opts.preview_pager )
.. after_pipe
end
end
end
opts.preview = path.git_cwd ( opts.preview , opts )
return git_cmd ( opts )
return git_cmd ( opts )
end
end
@ -125,19 +142,19 @@ M.branches = function(opts)
opts = config.normalize_opts ( opts , config.globals . git.branches )
opts = config.normalize_opts ( opts , config.globals . git.branches )
if not opts then return end
if not opts then return end
opts.fzf_opts [ " --no-multi " ] = ' '
opts.fzf_opts [ " --no-multi " ] = ' '
opts.__preview = path.git_cwd ( opts.preview , opts )
if opts.preview then
opts.preview = shell.raw_preview_action_cmd ( function ( item s)
opts.__preview = path.git_cwd ( opts.preview , opt s)
local branch = items [ 1 ] : gsub ( " %* " , " " ) -- remove the * from current branch
opts.preview = shell.raw_preview_action_cmd ( function ( items )
if branch : find ( " %) " ) ~= nil then
-- all possible options;
-- (HEAD detached at origin/master)
-- branch
branch = branch : match ( " .* ([^%)]+) " ) or " "
-- * branch
else
-- remotes/origin/branch
-- remove anything past space
-- (HEAD detached at origin/branch)
branch = branch : match ( " [^ ]+ " )
local branch = items [ 1 ] : match ( " [^%s%*]*$ " ) : gsub ( " %)$ " , " " )
end
return opts.__preview : gsub ( " {.*} " , branch )
return opts.__preview : gsub ( " {.*} " , branch )
-- return "echo " .. branch
-- return "echo " .. branch
end , nil , opts.debug )
end , nil , opts.debug )
end
return git_cmd ( opts )
return git_cmd ( opts )
end
end