Skip to content

Commit 0a6cdeb

Browse files
authored
Merge pull request #11 from rootiest/v2.2.0
V2.2.0 A lot of bugfixes
2 parents 6c124b6 + be6b569 commit 0a6cdeb

File tree

4 files changed

+122
-183
lines changed

4 files changed

+122
-183
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,19 @@ The `setup` function accepts an optional table to configure the plugin’s behav
232232
`number` - Update interval in seconds.
233233

234234
- **`notify_updates`**: (boolean) Produce update notifications
235-
Default is `false`
235+
Default is `false`.
236236

237237
Possible values are:
238238
`true` - Produce update notifications at update_interval.
239239
`false` - Do not produce update notifications.
240240

241+
- **`build_fresh`**: (boolean) Remove the build directory before compiling.
242+
Default is `true`.
243+
244+
Possible values are:
245+
`true` - Always remove the build directory before compiling.
246+
`false` - Do not remove the build directory before compiling.
247+
241248
- **`default_keymaps`**: (boolean) Enable default keymaps.
242249
Default is `false`.
243250

@@ -260,6 +267,7 @@ require("nvim_updater").setup({
260267
update_interval = (60 * 60) * 6, -- 6 hours default update interval
261268
notify_updates = false, -- Disable update notifications
262269
verbose = false, -- Disable verbose output
270+
build_fresh = true, -- Remove the build directory before compiling
263271
default_keymaps = false, -- Disable default keymaps
264272
})
265273
```
@@ -388,7 +396,7 @@ Available `[options]`:
388396
#### Show new commits
389397

390398
```lua
391-
require("nvim_updater.utils").show_new_commits( [options] )
399+
require("nvim_updater").show_new_commits( [options] )
392400
```
393401

394402
This function opens a floating terminal with the new commits/changes on
@@ -406,13 +414,13 @@ Options may be specified in the following manners:
406414
1. Specify parameters directly: (must follow the same order as shown above)
407415

408416
```lua
409-
require("nvim_updater.utils").show_new_commits(true, false)
417+
require("nvim_updater").show_new_commits(true, false)
410418
```
411419

412420
2. Use a table: (may be specified in any order or combination)
413421

414422
```lua
415-
require("nvim_updater.utils").show_new_commits({
423+
require("nvim_updater").show_new_commits({
416424
isupdate = true,
417425
short = false
418426
})
@@ -473,6 +481,8 @@ Available `[TerminalOptions]`:
473481
Default is `false`.
474482
- **`autoclose`**: Whether the terminal buffer will be closed when the process ends.
475483
Default is `false`.
484+
- **`enter_insert`**: Whether the terminal should start in insert mode and maintain it when focused.
485+
Default is `false`.
476486
- **`callback`**: A function to call when the terminal buffer is closed.
477487
Default is `nil`.
478488

@@ -489,6 +499,7 @@ Available `[TerminalOptions]`:
489499
- `ev`: The [event object](https://neovim.io/doc/user/api.html#event-args)
490500
received from the terminal close event.
491501
- `exit_code`: The exit code of the process that was run in the terminal buffer.
502+
- `output`: The output of the process that was run in the terminal buffer.
492503

493504
In most cases, this will occur after the process has completed.
494505

doc/nvim_updater.txt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ Options may be specified in the following manners:
225225

226226
1. Specify parameters directly: (must follow the same order as in docs)
227227
>lua
228-
require("nvim_updater.utils").show_new_commits(true, false)
228+
require("nvim_updater").show_new_commits(true, false)
229229
<
230230
2. Use a table: (may be specified in any order or combination)
231231
>lua
232-
require("nvim_updater.utils").show_new_commits({
232+
require("nvim_updater").show_new_commits({
233233
isupdate = true,
234234
short = false
235235
})
@@ -274,7 +274,7 @@ Available `[options]`:
274274

275275
--- Show new commits ---
276276
>lua
277-
require("nvim_updater.utils").show_new_commits( [options] )
277+
require("nvim_updater").show_new_commits( [options] )
278278
<
279279
This function opens a floating terminal with the new commits/changes on
280280
the remote repository vs the local src directory.
@@ -330,7 +330,8 @@ Available `[options]`:
330330
Default is `false`.
331331
- `autoclose` -> Whether the terminal buffer will be closed when the process ends.
332332
Default is `false`.
333-
333+
- `enter_insert` -> Whether the terminal should start in insert mode and
334+
maintain it when focused. Default is `false`.
334335
- `callback` -> A function to call when the terminal buffer is closed.
335336
Default is `nil`.
336337

@@ -344,6 +345,7 @@ Available `[options]`:
344345
- `ev`: -> The event object received from the terminal close event.
345346
See: *event-args*
346347
- `exit_code`: -> The exit code of the process that was run in the terminal buffer.
348+
- `output`: -> The output of the process that was run in the terminal buffer.
347349

348350
In most cases, this will occur after the process has completed.
349351

@@ -423,15 +425,15 @@ Available configuration fields:
423425
Default is `false`.
424426
When set to `false`, `INFO` and `DEBUG`
425427
notifications from the plugin are suppressed.
426-
Opts: `true` - Enable verbose output
427-
`false` - Disable verbose output.
428+
Opts: `true` - Enable verbose output
429+
`false` - Disable verbose output.
428430

429431
- `check_for_updates`: (boolean) -> Enable automatic update checks.
430432
Default is `false`.
431433
When set to `false`, the plugin will not
432434
check for updates automatically.
433-
Opts: `true` - Enable automatic update checks.
434-
`false` - Disable automatic update checks.
435+
Opts: `true` - Enable automatic update checks.
436+
`false` - Disable automatic update checks.
435437

436438
- `update_interval`: (number) -> Update interval in seconds.
437439
Default is `(60 * 60 * 6)` (6 hours).
@@ -443,6 +445,18 @@ Available configuration fields:
443445
Default is `false`
444446
When set to `true`, the plugin will produce
445447
notifications for new commits.
448+
Opts: `true` - Enable periodic update notifications.
449+
`false` - Disable periodic update notifications.
450+
451+
- `build_fresh`: (boolean) -> Remove the build directory before compiling.
452+
Default is `true`
453+
When set to `true`, the plugin will always
454+
remove the build directory before performing an
455+
update.
456+
Opts: `true` - Always remove the build directory before
457+
compiling.
458+
`false` - Do not attempt to remove the build
459+
directory before compiling.
446460

447461
- `default_keymaps`: (boolean) -> Enable default keymaps.
448462
Default is `false`.

lua/nvim_updater/init.lua

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2122
P.last_status = {
@@ -116,6 +117,7 @@ end
116117
local 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
121123
end
@@ -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...\nSource: "
132141
.. source_dir
133142
.. "\nBranch: "
@@ -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")
180192
end
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

Comments
 (0)