diff --git a/lua/vgit/features/screens/ProjectDiffScreen/Store.lua b/lua/vgit/features/screens/ProjectDiffScreen/Store.lua index 3352afb9..5ea166e8 100644 --- a/lua/vgit/features/screens/ProjectDiffScreen/Store.lua +++ b/lua/vgit/features/screens/ProjectDiffScreen/Store.lua @@ -21,6 +21,7 @@ function Store:constructor() state = { lnum = 1, diffs = {}, + reponame = nil, mark_index = 1, list_folds = {}, list_entries = {}, @@ -34,6 +35,7 @@ function Store:reset() self.data = nil self.state = { diffs = {}, + reponame = nil, mark_index = 1, list_entries = {}, } @@ -111,6 +113,7 @@ function Store:fetch(shape, opts) self.shape = shape self.data = data + self.state.reponame = reponame return self.data end @@ -136,6 +139,16 @@ function Store:get_filename() return entry.status.filename end +function Store:get_filepath() + local reponame = self.state.reponame + local filename = self:get_filename() + + filename = fs.make_relative(reponame, filename) + filename = string.format('%s/%s', reponame, filename) + + return filename +end + function Store:get_filetype() local entry, err = self:get() if err then return nil, err end @@ -161,13 +174,12 @@ function Store:set_list_folds(list_folds) end function Store:conflict_status() - local reponame = git_repo.discover() - return git_conflict.status(reponame) + return git_conflict.status(self.state.reponame) end function Store:get_lines(status, type) local filename = status.filename - local reponame = git_repo.discover() + local reponame = self.state.reponame if type == 'unmerged' then if status:has_both('UD') then return git_show.lines(reponame, filename, ':2') end @@ -180,13 +192,12 @@ function Store:get_lines(status, type) if status:has('D ') then return git_show.lines(reponame, filename, 'HEAD') end if type == 'staged' or status:has(' D') then return git_show.lines(reponame, filename) end - loop.free_textlock() - return fs.read_file(filename) + return fs.read_file(self:get_filepath()) end function Store:get_hunks(status, type, lines) local filename = status.filename - local reponame = git_repo.discover() + local reponame = self.state.reponame if type == 'unmerged' then if status:has_both('UD') then return git_hunks.custom(lines, { deleted = true }) end diff --git a/lua/vgit/features/screens/ProjectDiffScreen/init.lua b/lua/vgit/features/screens/ProjectDiffScreen/init.lua index 4438e625..6541cdb0 100644 --- a/lua/vgit/features/screens/ProjectDiffScreen/init.lua +++ b/lua/vgit/features/screens/ProjectDiffScreen/init.lua @@ -398,12 +398,13 @@ function ProjectDiffScreen:show() local mark, _ = self.diff_view:get_current_mark_under_cursor() if not mark then return end - local filename = self.store:get_filename() - if not filename then return end + local filepath = self.store:get_filepath() + loop.free_textlock() + if not filepath then return end self:destroy() - fs.open(filename) + fs.open(filepath) Window(0):set_lnum(mark.top_relative):position_cursor('center') end), @@ -479,7 +480,9 @@ function ProjectDiffScreen:show() key = '', handler = loop.coroutine(function() local mark, _ = self.diff_view:get_current_mark_under_cursor() - local filename = self.store:get_filename() + local filename = self.store:get_filepath() + loop.free_textlock() + if not filename then self.foldable_list_view:toggle_current_list_item() self.foldable_list_view:render()