Skip to content

Commit 9962628

Browse files
committed
fix(project_diff_preview): show diff on UD unmerged changes
1 parent 13ada52 commit 9962628

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lua/vgit/features/screens/ProjectDiffScreen/Store.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ function Store:get_file_lines(file, status)
8585

8686
if file_status:has_both('DU') then
8787
err, lines = self.git:show(filename, ':3')
88+
elseif file_status:has_both('UD') then
89+
err, lines = self.git:show(filename, ':2')
8890
elseif file_status:has('D ') then
8991
err, lines = self.git:show(filename, 'HEAD')
9092
elseif status == 'staged' or file_status:has(' D') then
@@ -103,7 +105,9 @@ function Store:get_file_hunks(file, status, lines)
103105
local hunks_err, hunks
104106

105107
if file_status:has_both('DU') then
106-
hunks_err, hunks = self.git:unmerged_hunks(filename)
108+
hunks_err, hunks = self.git:unmerged_hunks(filename, ':3', ':1')
109+
elseif file_status:has_both('UD') then
110+
hunks_err, hunks = self.git:unmerged_hunks(filename, ':1', ':2')
107111
elseif file_status:has_both('??') then
108112
hunks = self.git:untracked_hunks(lines)
109113
elseif file_status:has_either('DD') then
@@ -228,7 +232,7 @@ function Store:get_diff_dto()
228232
end
229233

230234
local file_status = file.status
231-
local is_deleted = not file_status:has_both('DU') and file_status:has_either('DD')
235+
local is_deleted = not (file_status:has_both('DU') or file_status:has_both('UD')) and file_status:has_either('DD')
232236
local diff_dto = diff_service:generate(hunks, lines, self.shape, { is_deleted = is_deleted })
233237

234238
self._cache.diff_dtos[cache_key] = diff_dto

lua/vgit/git/cli/Git.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ Git.remote_hunks = loop.promisify(function(self, filename, parent_hash, commit_h
463463
}, spec)):start()
464464
end, 6)
465465

466-
Git.unmerged_hunks = loop.promisify(function(self, filename, spec, callback)
466+
Git.unmerged_hunks = loop.promisify(function(self, filename, stage_a, stage_b, spec, callback)
467467
local result = {}
468468
local err = {}
469469
local args = utils.list.merge(self.fallback_args, {
@@ -477,8 +477,8 @@ Git.unmerged_hunks = loop.promisify(function(self, filename, spec, callback)
477477
string.format('--diff-algorithm=%s', self.diff_algorithm),
478478
'--patch-with-raw',
479479
'--unified=0',
480-
string.format(':3:%s', filename),
481-
string.format(':1:%s', filename),
480+
string.format('%s:%s', stage_a, filename),
481+
string.format('%s:%s', stage_b, filename),
482482
})
483483

484484
GitReadStream(utils.object.defaults({
@@ -505,7 +505,7 @@ Git.unmerged_hunks = loop.promisify(function(self, filename, spec, callback)
505505
return callback(nil, hunks)
506506
end,
507507
}, spec)):start()
508-
end, 4)
508+
end, 6)
509509

510510
Git.staged_hunks = loop.promisify(function(self, filename, spec, callback)
511511
local result = {}

0 commit comments

Comments
 (0)