66local List = require (" gitlab.utils.list" )
77local u = require (" gitlab.utils" )
88local state = require (" gitlab.state" )
9- local git = require (" gitlab.git" )
109local hunks = require (" gitlab.hunks" )
1110local async = require (" diffview.async" )
1211local diffview_lib = require (" diffview.lib" )
@@ -29,18 +28,16 @@ M.init = function()
2928 end
3029end
3130
32- -- Opens the reviewer window .
31+ -- Opens the reviewer windows .
3332M .open = function ()
34- local diff_refs = state .INFO .diff_refs
35- if diff_refs == nil then
36- u .notify (" Gitlab did not provide diff refs required to review this MR" , vim .log .levels .ERROR )
37- return
38- end
33+ local git = require (" gitlab.git" )
3934
40- if diff_refs .base_sha == " " or diff_refs .head_sha == " " then
41- u .notify (" Merge request contains no changes" , vim .log .levels .ERROR )
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
4238 return
4339 end
40+ git .check_current_branch_up_to_date_on_remote (vim .log .levels .WARN )
4441
4542 local diffview_open_command = " DiffviewOpen"
4643
@@ -53,17 +50,22 @@ M.open = function()
5350 diffview_open_command = diffview_open_command .. " --imply-local"
5451 else
5552 u .notify (
56- " Your working tree has changes , cannot use 'imply_local' setting for gitlab reviews. \n Stash or commit all changes to use." ,
53+ " Working tree unclean , cannot use 'imply_local' for review. Stash or commit all changes to use." ,
5754 vim .log .levels .WARN
5855 )
5956 state .settings .reviewer_settings .diffview .imply_local = false
6057 end
6158 end
6259
63- vim .api .nvim_command (string.format (" %s %s..%s" , diffview_open_command , diff_refs .base_sha , diff_refs .head_sha ))
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 )
6462
6563 M .is_open = true
6664 local cur_view = diffview_lib .get_current_view ()
65+ if cur_view == nil then
66+ u .notify (" Could not find Diffview view" , vim .log .levels .ERROR )
67+ return
68+ end
6769 M .diffview_layout = cur_view .cur_layout
6870 M .tabnr = vim .api .nvim_get_current_tabpage ()
6971
@@ -94,7 +96,6 @@ M.open = function()
9496 require (" gitlab" ).toggle_discussions () -- Fetches data and opens discussions
9597 end
9698
97- git .check_current_branch_up_to_date_on_remote (vim .log .levels .WARN )
9899 git .check_mr_in_good_condition ()
99100end
100101
0 commit comments