Skip to content

Commit 9a64630

Browse files
authored
Merge branch 'TimUntersberger:master' into fix/turn-it-back-to-gitcommit-filetype
2 parents cac8329 + 84cf7ef commit 9a64630

File tree

17 files changed

+268
-135
lines changed

17 files changed

+268
-135
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test:
2-
NEOGIT_LOG_CONSOLE=true NEOGIT_LOG_LEVEL="debug" nvim --headless --noplugin -c "lua require(\"plenary.test_harness\").test_directory_command('tests {minimal_init = \"tests/minimal-init.nvim\"}')"
2+
NEOGIT_LOG_CONSOLE=true NEOGIT_LOG_LEVEL="debug" nvim --headless -c "lua require('plenary.test_harness').test_directory('./tests//', {minimal_init='./tests/init.lua', sequential=true})"
33

44
lint:
55
selene --config selene/config.toml lua

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ neogit.setup {}
3333

3434
## Usage
3535

36-
You can either open neogit by using the `Neogit` command
36+
You can either open neogit by using the `Neogit` command
3737

3838
```vim
3939
:Neogit " uses tab
@@ -112,13 +112,17 @@ neogit.setup {
112112
disable_hint = false,
113113
disable_context_highlighting = false,
114114
disable_commit_confirmation = false,
115-
-- Neogit refreshes its internal state after specific events, which can be expensive depending on the repository size.
115+
-- Neogit refreshes its internal state after specific events, which can be expensive depending on the repository size.
116116
-- Disabling `auto_refresh` will make it so you have to manually refresh the status after you open it.
117117
auto_refresh = true,
118118
disable_builtin_notifications = false,
119119
use_magit_keybindings = false,
120120
-- Change the default way of opening neogit
121121
kind = "tab",
122+
-- The time after which an output console is shown for slow running commands
123+
console_timeout = 2000,
124+
-- Automatically show console if a command takes more than console_timeout milliseconds
125+
auto_show_console = true,
122126
-- Change the default way of opening the commit popup
123127
commit_popup = {
124128
kind = "split",
@@ -139,15 +143,15 @@ neogit.setup {
139143
-- The diffview integration enables the diff popup, which is a wrapper around `sindrets/diffview.nvim`.
140144
--
141145
-- Requires you to have `sindrets/diffview.nvim` installed.
142-
-- use {
143-
-- 'TimUntersberger/neogit',
144-
-- requires = {
146+
-- use {
147+
-- 'TimUntersberger/neogit',
148+
-- requires = {
145149
-- 'nvim-lua/plenary.nvim',
146-
-- 'sindrets/diffview.nvim'
150+
-- 'sindrets/diffview.nvim'
147151
-- }
148152
-- }
149153
--
150-
diffview = false
154+
diffview = false
151155
},
152156
-- Setting any section to `false` will make the section not render at all
153157
sections = {
@@ -311,11 +315,11 @@ The todo file does not represent ALL of the missing features. This file just sho
311315

312316
## Testing
313317

314-
Assure that you have [plenary.nvim](https://github.com/nvim-lua/plenary.nvim)
318+
Assure that you have [plenary.nvim](https://github.com/nvim-lua/plenary.nvim)
315319
installed as a plugin for your neovim instance. Afterwards, run `make test`
316320
to run the unit test suite.
317321

318322
Plenary uses it's own port of busted and a bundled luassert, so consult their
319-
code and the respective [busted](http://olivinelabs.com/busted/) and
320-
[luassert](http://olivinelabs.com/busted/#asserts) docs for what methods are
323+
code and the respective [busted](http://olivinelabs.com/busted/) and
324+
[luassert](http://olivinelabs.com/busted/#asserts) docs for what methods are
321325
available.

lua/neogit/buffers/commit_editor/init.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,23 @@ function M:open()
4040
modifiable = true,
4141
readonly = false,
4242
autocmds = {
43-
["BufWritePost"] = function()
43+
["BufWritePre"] = function()
4444
written = true
4545
end,
4646
["BufUnload"] = function()
4747
if written then
4848
if
49-
config.values.disable_commit_confirmation
50-
or input.get_confirmation("Are you sure you want to commit?")
49+
not config.values.disable_commit_confirmation
50+
and not input.get_confirmation("Are you sure you want to commit?")
5151
then
52-
vim.cmd("silent g/^#/d | silent w!")
52+
vim.cmd("silent v/^#/d | w!")
5353
end
5454
end
5555

5656
if self.on_unload then
5757
self.on_unload(written)
5858
end
59+
5960
require("neogit.process").defer_show_preview_buffers()
6061
end,
6162
},

lua/neogit/buffers/commit_select_view/init.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ local function line_pos()
1212
end
1313

1414
---Opens a popup for selecting a commit
15-
---@param commits CommitLogEntry[]
15+
---@param commits CommitLogEntry[]|nil
1616
---@return CommitSelectViewBuffer
17-
function M.new(commits, action)
17+
function M.new(commits)
1818
local instance = {
19-
action = action,
2019
commits = commits,
2120
buffer = nil,
2221
}
@@ -33,6 +32,14 @@ end
3332

3433
---@param action fun(commit: CommitLogEntry|nil)|nil
3534
function M:open(action)
35+
local _, item = require("neogit.status").get_current_section_item()
36+
37+
local commit_at_cursor
38+
39+
if item and item.commit then
40+
commit_at_cursor = item.commit
41+
end
42+
3643
self.buffer = Buffer.create {
3744
name = "NeogitCommitSelectView",
3845
filetype = "NeogitCommitSelectView",
@@ -46,7 +53,12 @@ function M:open(action)
4653
self:close()
4754
end)
4855

49-
action(self.commits[pos])
56+
if pos == 1 and commit_at_cursor then
57+
action(commit_at_cursor)
58+
else
59+
-- Subtract the top commit and blankline
60+
action(self.commits[pos - (commit_at_cursor and 2 or 0)])
61+
end
5062
action = nil
5163
end
5264
end,
@@ -61,7 +73,7 @@ function M:open(action)
6173
end,
6274
},
6375
render = function()
64-
return ui.View(self.commits)
76+
return ui.View(self.commits, commit_at_cursor)
6577
end,
6678
}
6779
end
Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
local Ui = require("neogit.lib.ui")
2-
local util = require("neogit.lib.util")
32

43
local row = Ui.row
54
local text = Ui.text
6-
local map = util.map
75

86
local M = {}
97

10-
function M.View(commits)
8+
function M.View(commits, commit_at_cursor)
119
local show_graph = true
12-
return map(commits, function(commit)
13-
return row {
14-
text(commit.oid:sub(1, 7), { highlight = "Number" }),
15-
text(" "),
16-
text(show_graph and ("* "):rep(commit.level + 1) or "* ", { highlight = "Character" }),
17-
text(" "),
18-
text(table.concat(commit.description)),
19-
}
20-
end)
10+
11+
local res = {}
12+
if commit_at_cursor then
13+
table.insert(
14+
res,
15+
row {
16+
text(commit_at_cursor.oid:sub(1, 7), { highlight = "Number" }),
17+
text(" "),
18+
text(show_graph and ("* "):rep(commit_at_cursor.level + 1) or "* ", { highlight = "Character" }),
19+
text(" "),
20+
text(table.concat(commit_at_cursor.description)),
21+
}
22+
)
23+
24+
table.insert(res, row {})
25+
end
26+
27+
for _, commit in ipairs(commits) do
28+
table.insert(
29+
res,
30+
row {
31+
text(commit.oid:sub(1, 7), { highlight = "Number" }),
32+
text(" "),
33+
text(show_graph and ("* "):rep(commit.level + 1) or "* ", { highlight = "Character" }),
34+
text(" "),
35+
text(table.concat(commit.description)),
36+
}
37+
)
38+
end
39+
40+
return res
2141
end
2242

2343
return M

lua/neogit/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ M.values = {
1212
kind = "tab",
1313
-- The time after which an output console is shown for slow running commands
1414
console_timeout = 2000,
15+
-- Automatically show console if a command takes more than console_timeout milliseconds
16+
auto_show_console = true,
1517
status = {
1618
recent_commit_count = 10,
1719
},

lua/neogit/lib/git/log.lua

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,31 +193,33 @@ local function parse_log(output)
193193
return commits
194194
end
195195

196+
local M = {}
197+
196198
local function update_recent(state)
197199
local count = config.values.status.recent_commit_count
198200
if count < 1 then
199201
return
200202
end
201203

202-
local result = cli.log.oneline.max_count(count).show_popup(false).call():trim()
204+
local result = M.list { "--max-count", tostring(count) }
203205

204-
state.recent.items = util.map(result.stdout, function(x)
205-
return { name = x }
206+
state.recent.items = util.map(result, function(v)
207+
return { name = string.format("%s %s", v.oid, v.description[1] or "<empty>"), oid = v.oid, commit = v }
206208
end)
207209
end
208210

209-
return {
210-
---@param options any
211-
---@param max_count number|nil
212-
---@return CommitLogEntry[]
213-
list = function(options, max_count)
214-
options = util.split(options or "", " ")
215-
local result = cli.log.oneline.max_count(max_count or 36).args(unpack(options)).call()
216-
return parse_log(result.stdout)
217-
end,
218-
register = function(meta)
219-
meta.update_recent = update_recent
220-
end,
221-
parse_log = parse_log,
222-
parse = parse,
223-
}
211+
---@param options any
212+
---@return CommitLogEntry[]
213+
function M.list(options)
214+
local result = cli.log.oneline.max_count(36).arg_list(options or {}).call()
215+
return parse_log(result.stdout)
216+
end
217+
218+
M.parse_log = parse_log
219+
M.parse = parse
220+
221+
function M.register(meta)
222+
meta.update_recent = update_recent
223+
end
224+
225+
return M

lua/neogit/lib/git/push.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ local function update_unmerged(state)
1717
return
1818
end
1919

20-
local result = cli.log.oneline.for_range("@{upstream}..").show_popup(false).call(false, true):trim().stdout
20+
-- local result = cli.log.oneline.for_range("@{upstream}..").show_popup(false).call(false, true):trim().stdout
2121

22-
state.unmerged.items = util.filter_map(result, function(x)
23-
if x == "" then
24-
return
25-
end
26-
return { name = x }
22+
local result = require("neogit.lib.git.log").list { "@{upstream}.." }
23+
24+
state.unmerged.items = util.map(result, function(v)
25+
return { name = string.format("%s %s", v.oid, v.description[1] or "<empty>"), oid = v.oid, commit = v }
2726
end)
2827
end
2928

lua/neogit/lib/git/rebase.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local logger = require("neogit.logger")
22
local client = require("neogit.client")
3-
local log = require("neogit.lib.git.log")
43
local notif = require("neogit.lib.notification")
54

65
local M = {}
@@ -11,7 +10,7 @@ local function rebase_command(cmd)
1110
local git = require("neogit.lib.git")
1211
cmd = cmd or git.cli.rebase
1312
local envs = client.get_envs_git_editor()
14-
return cmd.env(envs).show_popup(false):in_pty(true).call(true)
13+
return cmd.env(envs).show_popup(true):in_pty(true).call(true)
1514
end
1615

1716
function M.rebase_interactive(...)
@@ -26,10 +25,10 @@ function M.rebase_interactive(...)
2625
status.refresh(true, "rebase_interactive")
2726
end
2827

29-
function M.rebase_onto(branch)
28+
function M.rebase_onto(branch, args)
3029
a.util.scheduler()
3130
local git = require("neogit.lib.git")
32-
local result = rebase_command(git.cli.rebase.args(branch))
31+
local result = rebase_command(git.cli.rebase.args(branch).arg_list(args))
3332
if result.code ~= 0 then
3433
notif.create("Rebasing failed. Resolve conflicts before continuing", vim.log.levels.ERROR)
3534
end

lua/neogit/lib/git/stash.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ end
6767

6868
local function update_stashes(state)
6969
local result = cli.stash.args("list").call():trim()
70-
state.stashes.items = parse(result)
70+
state.stashes.items = parse(result.stdout)
7171
end
7272

7373
return {

0 commit comments

Comments
 (0)