@@ -51,6 +51,8 @@ M.config = {
5151 },
5252 -- UI configuration.
5353 ui = {
54+ -- Whether to enable builtin output buffer or fallback to `vim.notify`.
55+ enabled = true ,
5456 -- Auto-close window after repository was opened.
5557 auto_close = true ,
5658 -- Delay window closing.
@@ -162,6 +164,7 @@ M.open = function(repo, ref, opts)
162164 local config = vim .tbl_deep_extend (" force" , M .config , opts or {})
163165 local ui = M .ui
164166 ui :show ()
167+ ui :print (" Opening " .. repo ):emit ()
165168
166169 local gitcmd = require (" git-dev.gitcmd" ):init {
167170 cmd = config .git .command ,
@@ -189,7 +192,7 @@ M.open = function(repo, ref, opts)
189192 or parsed_repo .branch
190193
191194 if not branch and parsed_repo .full_blob then
192- ui :print " Could not detect branch / tag / commit in given URI."
195+ ui :print " Could not detect a ref in given URI, falling back to default ."
193196 end
194197
195198 local repo_dir = config .repositories_dir
@@ -200,7 +203,7 @@ M.open = function(repo, ref, opts)
200203 ui :print (parsed_repo )
201204 end
202205
203- local post_action_callback = vim . schedule_wrap ( function ()
206+ local post_action_callback = function ()
204207 if vim .fn .isdirectory (repo_dir ) == 0 then
205208 ui :print (
206209 " Repository not found at: " .. parsed_repo .repo_url .. " , aborting..."
@@ -279,6 +282,10 @@ M.open = function(repo, ref, opts)
279282 M .history :add (repo , ref , opts , parsed_repo )
280283
281284 ui :print " Done."
285+ end
286+
287+ local clone_callback = vim .schedule_wrap (function ()
288+ pcall (post_action_callback )
282289 if config .ui .auto_close then
283290 ui :close (config .ui .close_after_ms )
284291 end
@@ -288,7 +295,7 @@ M.open = function(repo, ref, opts)
288295 ui :print " Repository directory exists, refreshing..."
289296 gitcmd :refresh (
290297 { repo_dir = repo_dir , extra_args = config .git .fetch_args },
291- post_action_callback
298+ clone_callback
292299 )
293300 else
294301 -- Fresh clone
@@ -298,7 +305,7 @@ M.open = function(repo, ref, opts)
298305 repo_dir = repo_dir ,
299306 branch = parsed_repo .branch ,
300307 extra_args = config .git .clone_args ,
301- }, post_action_callback )
308+ }, clone_callback )
302309 end
303310end
304311
@@ -462,26 +469,37 @@ M.setup = function(opts)
462469 vim .fn .mkdir (vim .fs .dirname (M .config .history .path ), " p" )
463470
464471 -- Prepare UI
465- local win_config
466- if M .config .ui .mode == " split" then
467- local v = vim .version ()
468- -- `nvim_open_win` supports splitting in Neovim>=0.10.0
469- -- `ge` was added in 0.10.0.
470- if vim .version .lt ({ v .major , v .minor , v .patch }, { 0 , 10 , 0 }) == false then
471- win_config = M .config .ui .split_win_config
472+ if M .config .ui .enabled then
473+ local win_config
474+ if M .config .ui .mode == " split" then
475+ local v = vim .version ()
476+ -- `nvim_open_win` supports splitting in Neovim>=0.10.0
477+ -- `ge` was added in 0.10.0.
478+ if
479+ vim .version .lt ({ v .major , v .minor , v .patch }, { 0 , 10 , 0 }) == false
480+ then
481+ win_config = M .config .ui .split_win_config
482+ else
483+ vim .notify (
484+ " Split mode is not supported in Neovim < 0.10.0. "
485+ .. " Falling back to floating mode."
486+ )
487+ win_config = M .config .ui .floating_win_config
488+ end
472489 else
473- vim .notify (
474- " Split mode is not supported in Neovim < 0.10.0. "
475- .. " Falling back to floating mode."
476- )
477490 win_config = M .config .ui .floating_win_config
478491 end
492+ M .ui = require (" git-dev.ui" ):init {
493+ win_config = win_config ,
494+ }
495+ vim .api .nvim_create_user_command (" GitDevToggleUI" , function (_ )
496+ require (" git-dev" ).toggle_ui ()
497+ end , {
498+ desc = " Toggle output window." ,
499+ })
479500 else
480- win_config = M . config . ui . floating_win_config
501+ M . ui = require ( " git-dev.uistub " ): init {}
481502 end
482- M .ui = require (" git-dev.ui" ):init {
483- win_config = win_config ,
484- }
485503
486504 -- Initialize store
487505 --- @type GitDevHistory
@@ -496,7 +514,7 @@ M.setup = function(opts)
496514 xdg .enable (M .config .xdg_handler )
497515 vim .api .nvim_create_user_command (" GitDevXDGHandle" , function (cmd_args )
498516 local uri = U .parse_cmd_args (cmd_args )
499- M . ui : print ( xdg .handle (uri ) )
517+ xdg .handle (uri )
500518 end , {
501519 desc = " xdg-open handler for git-dev.nvim URIs." ,
502520 nargs = " *" ,
@@ -541,12 +559,6 @@ M.setup = function(opts)
541559 complete = complete_from_session ,
542560 })
543561
544- vim .api .nvim_create_user_command (" GitDevToggleUI" , function (_ )
545- require (" git-dev" ).toggle_ui ()
546- end , {
547- desc = " Toggle output window." ,
548- })
549-
550562 vim .api .nvim_create_user_command (
551563 " GitDevRecents" ,
552564 " Telescope git_dev recents" ,
0 commit comments