Skip to content

Commit d528de8

Browse files
committed
fix: don't use branch as MR base
1 parent 6b486be commit d528de8

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

lua/gitlab/reviewer/init.lua

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ end
3030

3131
-- Opens the reviewer windows.
3232
M.open = function()
33-
local git = require("gitlab.git")
33+
local diff_refs = state.INFO.diff_refs
34+
if diff_refs == nil then
35+
u.notify("Gitlab did not provide diff refs required to review this MR", vim.log.levels.ERROR)
36+
return
37+
end
3438

35-
local remote_target_branch =
36-
string.format("%s/%s", state.settings.connection_settings.remote, state.INFO.target_branch)
37-
if not git.fetch_remote_branch(remote_target_branch) then
39+
if diff_refs.base_sha == "" or diff_refs.head_sha == "" then
40+
u.notify("Merge request contains no changes", vim.log.levels.ERROR)
3841
return
3942
end
43+
44+
local git = require("gitlab.git")
4045
git.check_current_branch_up_to_date_on_remote(vim.log.levels.WARN)
4146

4247
local diffview_open_command = "DiffviewOpen"
@@ -49,16 +54,12 @@ M.open = function()
4954
if has_clean_tree then
5055
diffview_open_command = diffview_open_command .. " --imply-local"
5156
else
52-
u.notify(
53-
"Working tree unclean, cannot use 'imply_local' for review. Stash or commit all changes to use.",
54-
vim.log.levels.WARN
55-
)
57+
u.notify("Working tree unclean. Stash or commit all changes to use 'imply_local'.", vim.log.levels.WARN)
5658
state.settings.reviewer_settings.diffview.imply_local = false
5759
end
5860
end
5961

60-
local full_command = string.format("%s %s..%s", diffview_open_command, remote_target_branch, state.INFO.source_branch)
61-
vim.api.nvim_command(full_command)
62+
vim.api.nvim_command(string.format("%s %s..%s", diffview_open_command, diff_refs.base_sha, state.INFO.source_branch))
6263

6364
M.is_open = true
6465
local cur_view = diffview_lib.get_current_view()

0 commit comments

Comments
 (0)