@@ -16,6 +16,7 @@ P.default_config = {
1616 notify_updates = false , -- Enable update notification
1717 verbose = false , -- Default verbose mode
1818 default_keymaps = false , -- Use default keymaps
19+ build_fresh = true , -- Always remove build dir before building
1920}
2021
2122P .last_status = {
116117local function update_with_retry ()
117118 if P .last_status .retry then
118119 P .last_status .retry = false
120+ utils .notify (" Removal succeeded. Retrying update..." , vim .log .levels .INFO , true )
119121 P .update_neovim ()
120122 end
121123end
@@ -128,6 +130,13 @@ function P.update_neovim(opts)
128130 local build_type = opts .build_type ~= " " and opts .build_type or P .default_config .build_type
129131 local branch = opts .branch ~= " " and opts .branch or P .default_config .branch
130132
133+ if P .default_config .build_fresh then
134+ if utils .directory_exists (source_dir .. " /build" ) then
135+ utils .rm_build_then_update (opts )
136+ return
137+ end
138+ end
139+
131140 local notification_msg = " Starting Neovim update...\n Source: "
132141 .. source_dir
133142 .. " \n Branch: "
@@ -142,12 +151,15 @@ function P.update_neovim(opts)
142151 if not dir_exists then
143152 git_commands = " git clone https://github.com/neovim/neovim " .. source_dir .. " && cd " .. source_dir
144153 else
145- git_commands = " cd " .. source_dir
154+ -- Check if we're in a git repo and get current branch
155+ git_commands = " cd " .. source_dir .. " && git fetch origin && "
156+
157+ -- Only switch branch if we're not already on the target branch
158+ git_commands = git_commands .. " test \" $(git rev-parse --abbrev-ref HEAD)\" = \" " .. branch .. " \" || "
159+ git_commands = git_commands .. " git switch " .. branch .. " && "
160+ git_commands = git_commands .. " git pull"
146161 end
147162
148- -- Checkout branch and pull latest changes
149- git_commands = git_commands .. " && git fetch origin && git checkout " .. branch .. " && git pull"
150-
151163 local build_command = " cd " .. source_dir .. " && make CMAKE_BUILD_TYPE=" .. build_type .. " && sudo make install"
152164
153165 local update_command = git_commands .. " && " .. build_command
@@ -158,14 +170,17 @@ function P.update_neovim(opts)
158170 filetype = " neovim_updater_term.updating" ,
159171 ispreupdate = false ,
160172 autoclose = true ,
173+ enter_insert = true ,
161174 callback = function (results )
162175 if results .result_code ~= 0 then
163176 utils .notify (" Neovim update failed with error code: " .. results .result_code , vim .log .levels .ERROR )
164- utils .ConfirmPrompt (" Remove build directory and try again?" , function ()
165- P .last_status .count = " ?"
166- P .last_status .retry = true
167- P .remove_source_dir ({ source_dir = source_dir .. " /build" })
168- end )
177+ if P .default_config .build_fresh == false then
178+ utils .ConfirmPrompt (" Remove build directory and try again?" , function ()
179+ P .last_status .count = " ?"
180+ P .last_status .retry = true
181+ P .remove_source_dir ({ source_dir = source_dir .. " /build" })
182+ end )
183+ end
169184 else
170185 utils .notify (" Neovim update complete!" , vim .log .levels .INFO , true )
171186 utils .notify (" Please restart Neovim for the changes to take effect." , vim .log .levels .INFO )
@@ -174,9 +189,6 @@ function P.update_neovim(opts)
174189 end
175190 end ,
176191 })
177-
178- -- Go to insert mode
179- vim .cmd (" startinsert" )
180192end
181193
182194--- Remove the Neovim source directory or a custom one.
@@ -225,7 +237,14 @@ function P.remove_source_dir(opts)
225237 end
226238
227239 -- Attempt to remove with elevated privileges
228- local rm_msg = " echo Attempting to remove "
240+
241+ local elevate_perms_explained = " "
242+ if P .default_config .verbose then
243+ elevate_perms_explained = " echo Removing the directory failed using traditional methods.\n "
244+ .. " echo This typically indicates a permissions issue with the directory.\n "
245+ end
246+ local rm_msg = elevate_perms_explained
247+ .. " echo Attempting to remove "
229248 .. source_dir
230249 .. " directory with elevated privileges.\n "
231250 .. " echo Please authorize sudo and press enter.\n "
@@ -404,12 +423,6 @@ function P.notify_new_commits(show_none, level)
404423
405424 local current_branch = vim .fn .system (current_branch_cmd ):gsub (" %s+" , " " ) -- Trim whitespace
406425
407- -- Check for errors in executing the branch command
408- if vim .v .shell_error ~= 0 then
409- utils .notify (" Failed to retrieve the current branch." , vim .log .levels .ERROR )
410- return
411- end
412-
413426 -- Build the command to count new commits in the remote branch
414427 local commit_count_cmd = (" cd %s && git rev-list --count %s..origin/%s" ):format (
415428 source_dir ,
@@ -420,7 +433,7 @@ function P.notify_new_commits(show_none, level)
420433 -- Execute the command to get the count of new commits
421434 local commit_count = vim .fn .system (commit_count_cmd ):gsub (" %s+" , " " ) -- Trim whitespace
422435
423- -- Check for errors in executing the commit count command
436+ -- Check for errors in executing the command
424437 if vim .v .shell_error == 0 then
425438 if tonumber (commit_count ) > 0 then
426439 -- Adjust the notification message based on the number of commits found
0 commit comments