@@ -188,44 +188,71 @@ M.git_log_grepper_on_file = function(bufnr)
188
188
end , git_log_entry_maker )
189
189
end
190
190
191
+ local previous_commit_hash = function (commit_hash )
192
+ local command = " git rev-parse " .. commit_hash .. " ~"
193
+ local handle = io.popen (command )
194
+ local output = handle :read (" *a" )
195
+ handle :close ()
196
+
197
+ output = string.gsub (output , " \n " , " " )
198
+ return output
199
+ end
200
+
191
201
local determine_historic_file_name = function (commit_hash , bufnr )
192
- local current_file_name = file .relative_path (bufnr )
202
+ local current_file_name = file .git_relative_path (bufnr )
193
203
194
- local command = " git log -M --diff-filter=R --follow --name-status --summary "
204
+ local command = " cd "
205
+ .. file .git_dir ()
206
+ .. " && "
207
+ .. " git --no-pager log -M --follow --name-status --summary "
195
208
.. commit_hash
196
- .. " .. -- "
209
+ .. " ~ .. -- "
197
210
.. current_file_name
198
- .. " | grep ^R | tail -1 | cut -f2,2 "
211
+ .. " | tail -1"
199
212
200
213
local handle = io.popen (command )
201
214
local output = handle :read (" *a" )
202
215
handle :close ()
203
216
204
217
output = string.gsub (output , " \n " , " " )
205
- if output == " " then
206
- output = file .git_relative_path (bufnr )
218
+
219
+ if output == nil or output == " " then
220
+ return nil
207
221
end
208
222
209
- -- output is relative to git root
210
- return output
223
+ local split_output = utils . split_string ( output )
224
+ return split_output [ # split_output ]
211
225
end
212
226
213
227
M .git_diff_previewer_file = function (bufnr )
214
228
return previewers .new_termopen_previewer ({
215
229
get_command = function (entry )
216
230
local commit_hash = entry .opts .commit_hash
217
231
218
- local prev_commit = string.format (" %s~" , commit_hash )
219
- return git_diff_command ({
220
- " git" ,
221
- " diff" ,
222
- prev_commit
223
- .. " :"
224
- .. determine_historic_file_name (prev_commit , bufnr ),
225
- commit_hash
226
- .. " :"
227
- .. determine_historic_file_name (commit_hash , bufnr ),
228
- })
232
+ local prev_commit = previous_commit_hash (commit_hash )
233
+ if determine_historic_file_name (prev_commit , bufnr ) == nil then
234
+ return git_diff_command ({
235
+ " git" ,
236
+ " diff" ,
237
+ prev_commit ,
238
+ commit_hash ,
239
+ " --" ,
240
+ file .git_dir ()
241
+ .. " /"
242
+ .. determine_historic_file_name (commit_hash , bufnr ),
243
+ })
244
+ else
245
+ return git_diff_command ({
246
+ " git" ,
247
+ " diff" ,
248
+ prev_commit
249
+ .. " :"
250
+ .. determine_historic_file_name (prev_commit , bufnr ),
251
+ commit_hash
252
+ .. " :"
253
+ .. determine_historic_file_name (commit_hash , bufnr ),
254
+ })
255
+ end
229
256
end ,
230
257
})
231
258
end
0 commit comments