@@ -104,12 +104,9 @@ local git_validate_ref = function(opts, ref)
104104 return true
105105end
106106
107- --- @param opts fzf-lua.config.GitDiff |{}?
108- --- @return thread ?, string ?, table ?
109- M .diff = function (opts )
110- --- @type fzf-lua.config.GitDiff
111- opts = config .normalize_opts (opts , " git.diff" )
112- if not opts then return end
107+ --- @param opts fzf-lua.config.GitDiff | fzf-lua.config.GitHunks
108+ --- @return table ?
109+ local normalize_diff_opts = function (opts )
113110 -- Backward compat `compare_against` -> `ref1`
114111 --- @diagnostic disable-next-line : undefined-field
115112 opts .ref1 = opts .compare_against or opts .ref1
@@ -137,15 +134,44 @@ M.diff = function(opts)
137134 end
138135 opts .cmd = opts .cmd :gsub (" [<{]ref[}>]" , opts .ref or " " )
139136 opts .cmd = opts .cmd :gsub (" [<{]ref1[}>]" , opts .ref1 or " " )
140- opts .preview = opts .preview :gsub (" [<{]ref[}>]" , opts .ref or " " )
141- opts .preview = opts .preview :gsub (" [<{]ref1[}>]" , opts .ref1 or " " )
142- opts = set_git_cwd_args (opts )
143- if not opts .cwd then return end
144- opts .preview = git_preview (opts , " {-1}" )
137+ opts .cmd = opts .cmd :gsub (" [<{]file[}>]" , opts .file and libuv .shellescape (opts .file ) or " " )
138+ if type (opts .preview ) == " string" then
139+ opts .preview = opts .preview :gsub (" [<{]ref[}>]" , opts .ref or " " )
140+ opts .preview = opts .preview :gsub (" [<{]ref1[}>]" , opts .ref1 or " " )
141+ opts .preview = git_preview (opts , " {-1}" )
142+ end
145143 if type (opts ._headers ) == " table" then
146144 table.insert (opts ._headers , " ref" )
147145 table.insert (opts ._headers , " ref1" )
148146 end
147+ return set_git_cwd_args (opts )
148+ end
149+
150+ --- @param opts fzf-lua.config.GitDiff |{}?
151+ --- @return thread ?, string ?, table ?
152+ M .diff = function (opts )
153+ --- @type fzf-lua.config.GitDiff
154+ opts = config .normalize_opts (opts , " git.diff" )
155+ if not opts then return end
156+ opts = normalize_diff_opts (opts )
157+ if not opts or not opts .cwd then return end
158+ return core .fzf_exec (opts .cmd , opts )
159+ end
160+
161+
162+ --- @param opts fzf-lua.config.GitHunks |{}?
163+ --- @return thread ?, string ?, table ?
164+ M .hunks = function (opts )
165+ --- @type fzf-lua.config.GitHunks
166+ opts = config .normalize_opts (opts , " git.hunks" )
167+ if not opts then return end
168+ opts = normalize_diff_opts (opts )
169+ if not opts or not opts .cwd then return end
170+
171+ -- we don't need git icons since we get them
172+ -- as part of our `git status -s`
173+ opts .git_icons = false
174+
149175 return core .fzf_exec (opts .cmd , opts )
150176end
151177
@@ -317,27 +343,4 @@ M.stash = function(opts)
317343 return core .fzf_exec (opts .cmd , opts )
318344end
319345
320- --- @param opts fzf-lua.config.GitHunks |{}?
321- --- @return thread ?, string ?, table ?
322- M .hunks = function (opts )
323- --- @type fzf-lua.config.GitHunks
324- opts = config .normalize_opts (opts , " git.hunks" )
325- if not opts then return end
326- if type (opts .ref ) == " string" and # opts .ref > 0 and not git_validate_ref (opts , opts .ref ) then
327- return
328- end
329- opts .cmd = opts .cmd :gsub (" [<{]ref[}>]" , opts .ref or " " )
330- opts = set_git_cwd_args (opts )
331- if not opts .cwd then return end
332-
333- -- we don't need git icons since we get them
334- -- as part of our `git status -s`
335- opts .git_icons = false
336-
337- opts .header_prefix = opts .header_prefix or " + - "
338- opts .header_separator = opts .header_separator or " |"
339-
340- return core .fzf_exec (opts .cmd , opts )
341- end
342-
343346return M
0 commit comments