Skip to content

Commit 90576be

Browse files
committed
feat(git): update show_at_cursor to work in 'mini.deps' confirm buffer
Resolve #1191
1 parent d231729 commit 90576be

14 files changed

+346
-143
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
## mini.git
2929

3030
- FEATURE: update `show_at_cursor()` to include commit's statistics when showing commit.
31+
- FEATURE: update `show_at_cursor()` to show relevant at cursor commit data inside 'mini.deps' confirmation buffer.
3132

3233
## mini.hipatterns
3334

doc/mini-git.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ Default: "auto".
270270
`MiniGit.show_at_cursor`({opts})
271271
Show Git related data at cursor
272272

273+
- If inside |mini.deps| confirmation buffer, show in split relevant commit data.
273274
- If there is a commit-like |<cword>|, show it in split.
274275
- If possible, show diff source via |MiniGit.show_diff_source()|.
275276
- If possible, show range history via |MiniGit.show_range_history()|.

lua/mini/git.lua

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ MiniGit.config = {
300300

301301
--- Show Git related data at cursor
302302
---
303+
--- - If inside |mini.deps| confirmation buffer, show in split relevant commit data.
303304
--- - If there is a commit-like |<cword>|, show it in split.
304305
--- - If possible, show diff source via |MiniGit.show_diff_source()|.
305306
--- - If possible, show range history via |MiniGit.show_range_history()|.
@@ -309,17 +310,22 @@ MiniGit.config = {
309310
--- - __git_split_field
310311
--- - Fields appropriate for forwarding to other functions.
311312
MiniGit.show_at_cursor = function(opts)
312-
local exec = MiniGit.config.job.git_executable
313-
local cwd = H.get_git_cwd()
313+
-- Try showing commit data at cursor
314+
local commit, cwd
315+
if vim.bo.filetype == 'minideps-confirm' then
316+
commit, cwd = H.deps_pos_to_source()
317+
else
318+
local cword = vim.fn.expand('<cword>')
319+
local is_commit = string.find(cword, '^%x%x%x%x%x%x%x+$') ~= nil and string.lower(cword) == cword
320+
commit = is_commit and cword or nil
321+
cwd = is_commit and H.get_git_cwd() or nil
322+
end
314323

315-
-- Try showing commit at cursor
316-
local cword = vim.fn.expand('<cword>')
317-
local is_commit = string.find(cword, '^%x%x%x%x%x%x%x+$') ~= nil and string.lower(cword) == cword
318-
if is_commit then
324+
if commit ~= nil and cwd ~= nil then
319325
local split = H.normalize_split_opt((opts or {}).split or 'auto', 'opts.split')
320-
local args = { 'show', '--stat', '--patch', cword }
326+
local args = { 'show', '--stat', '--patch', commit }
321327
local lines = H.git_cli_output(args, cwd)
322-
if #lines == 0 then return H.notify('Can not show commit ' .. cword, 'WARN') end
328+
if #lines == 0 then return H.notify('Can not show commit ' .. commit .. ' in repo ' .. cwd, 'WARN') end
323329
H.show_in_split(split, lines, 'show', table.concat(args, ' '))
324330
vim.bo.filetype = 'git'
325331
return
@@ -1567,6 +1573,29 @@ end
15671573

15681574
H.parse_diff_source_buf_name = function(buf_name) return string.match(buf_name, '^minigit://%d+/.*show (%x+~?):(.*)$') end
15691575

1576+
H.deps_pos_to_source = function()
1577+
local lines = vim.api.nvim_buf_get_lines(0, 0, vim.fn.line('.'), false)
1578+
-- Do nothing if on the title (otherwise it operates on previous plugin info)
1579+
if lines[#lines]:find('^[%+%-!]') ~= nil then return end
1580+
1581+
-- Locate lines with commit and repo path data
1582+
local commit, commit_lnum = nil, #lines
1583+
while commit == nil and commit_lnum >= 1 do
1584+
local l = lines[commit_lnum]
1585+
commit = l:match('^[><] (%x%x%x%x%x%x%x%x*) |') or l:match('^State[^:]*: %s*(%x+)')
1586+
commit_lnum = commit_lnum - 1
1587+
end
1588+
1589+
local cwd, cwd_lnum = nil, #lines
1590+
while cwd == nil and cwd_lnum >= 1 do
1591+
cwd, cwd_lnum = lines[cwd_lnum]:match('^Path: %s*(%S+)$'), cwd_lnum - 1
1592+
end
1593+
1594+
-- Do nothing if something is not found or path corresponds to next repo
1595+
if commit == nil or cwd == nil or commit_lnum <= cwd_lnum then return end
1596+
return commit, cwd
1597+
end
1598+
15701599
-- Folding --------------------------------------------------------------------
15711600
H.is_hunk_header = function(lnum) return vim.fn.getline(lnum):find('^@@.*@@') ~= nil end
15721601

tests/dir-git/deps-confirm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
This is a confirmation report before an update.
2+
3+
Other very useful info
4+
5+
!!! plugin_a !!!
6+
7+
Some error
8+
9+
+++ plugin_b +++
10+
Path: /home/user/.local/share/nvim/site/pack/deps/opt/plugin_b
11+
Source: https://github.com/cool-plugins/plugin_b
12+
State before: aa339f6ab611da07183a7fe44daa482605392502
13+
State after: 093b29f2b409278e2ed69a90462fee54714b5a84 (master)
14+
15+
Pending updates from `master`:
16+
> 093b29f2 | 2024-09-06 06:42:29 +0000 | Neo McVim
17+
feat: very important feature
18+
19+
> bfe74a48 | 2024-09-05 13:25:50 +0000 | Neo McVim
20+
fix: very important fix
21+
22+
< 3826d0c4 | 2024-09-04 09:08:06 +0200 | Neo McVim
23+
chore: not very important chore
24+
25+
+++ plugin_c +++
26+
Path: /home/user/.local/share/nvim/site/pack/deps/opt/plugin_c
27+
Source: https://github.com/cool-plugins/plugin_c
28+
State before: 3a3c6244553f13fdd92d312c82722b57ce6c4bec
29+
State after: fe3deb7f67ce0cc4ebfe2ea6c1c7ae1c7a939d73 (main)
30+
31+
Pending updates from `main`:
32+
> fe3deb7 | 2024-09-04 03:40:17 -0500 | Caleb White
33+
fix: even more important fix
34+
35+
--- plugin_d ---
36+
Path: /home/user/.local/share/nvim/site/pack/deps/opt/plugin_d
37+
Source: https://github.com/cool-plugins/plugin_d
38+
State: d231729b13da28fd1625c3d85f2315886ddeb05d (HEAD)

tests/screenshots/tests-test_git.lua----Git---completion---works-with-explicit-paths

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
01|
33
02|~
44
03|~
5-
04|~
6-
05|~ git-repo/
7-
06|~ mocks/
5+
04|~ git-repo/
6+
05|~ mocks/
7+
06|~ deps-confirm
88
07|~ diff-output
99
08|~ file
1010
09|~ file1
@@ -19,8 +19,8 @@
1919
01|0000000000000000000000000000000000000000
2020
02|1111111111111111111111111111111111111111
2121
03|1111111111111111111111111111111111111111
22-
04|1111111111111111111111111111111111111111
23-
05|1111111111122222222222222221111111111111
22+
04|1111111111122222222222222221111111111111
23+
05|1111111111133333333333333331111111111111
2424
06|1111111111133333333333333331111111111111
2525
07|1111111111133333333333333331111111111111
2626
08|1111111111133333333333333331111111111111

tests/screenshots/tests-test_git.lua----Git---completion---works-with-not-supported-command-003

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
03|~
55
04|~
66
05|~
7-
06|~
8-
07|~ git-repo/
9-
08|~ mocks/
10-
09|~ diff-output
11-
10|~ file
12-
11|~ file1
13-
12|~ File2
14-
13|~ file3
15-
14|~ help-output
16-
15|~ log-output
7+
06|~ git-repo/
8+
07|~ mocks/
9+
08|~ deps-confirm
10+
09|~ diff-output
11+
10|~ file
12+
11|~ file1
13+
12|~ File2
14+
13|~ file3
15+
14|~ help-output
16+
15|~ log-output
1717
16|:Git doesnotexist -- git-repo/
1818
17|
1919

@@ -23,15 +23,15 @@
2323
03|11111111111111111111111111111111
2424
04|11111111111111111111111111111111
2525
05|11111111111111111111111111111111
26-
06|11111111111111111111111111111111
27-
07|11111111111111111111222222222222
28-
08|11111111111111111111333333333333
29-
09|11111111111111111111333333333333
30-
10|11111111111111111111333333333333
31-
11|11111111111111111111333333333333
32-
12|11111111111111111111333333333333
33-
13|11111111111111111111333333333333
34-
14|11111111111111111111333333333333
35-
15|11111111111111111111333333333333
26+
06|11111111111111111112222222222222
27+
07|11111111111111111113333333333333
28+
08|11111111111111111113333333333333
29+
09|11111111111111111113333333333333
30+
10|11111111111111111113333333333333
31+
11|11111111111111111113333333333333
32+
12|11111111111111111113333333333333
33+
13|11111111111111111113333333333333
34+
14|11111111111111111113333333333333
35+
15|11111111111111111113333333333333
3636
16|44444444444444444444444444444444
3737
17|44444444444444444444444444444444

tests/screenshots/tests-test_git.lua----Git---completion---works-with-subcommand-targets

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22
01|
33
02|~
44
03|~
5-
04|~
6-
05|~ git-repo/
7-
06|~ mocks/
8-
07|~ diff-output
9-
08|~ file
10-
09|~ file1
11-
10|~ File2
12-
11|~ file3
13-
12|~ help-output
14-
13|~ log-output
5+
04|~ git-repo/
6+
05|~ mocks/
7+
06|~ deps-confirm
8+
07|~ diff-output
9+
08|~ file
10+
09|~ file1
11+
10|~ File2
12+
11|~ file3
13+
12|~ help-output
14+
13|~ log-output
1515
14|:Git add git-repo/
1616
15|
1717

1818
--|---------|---------|
1919
01|00000000000000000000
2020
02|11111111111111111111
2121
03|11111111111111111111
22-
04|11111111111111111111
23-
05|11111111222222222222
24-
06|11111111333333333333
25-
07|11111111333333333333
26-
08|11111111333333333333
27-
09|11111111333333333333
28-
10|11111111333333333333
29-
11|11111111333333333333
30-
12|11111111333333333333
31-
13|11111111333333333333
22+
04|11111112222222222222
23+
05|11111113333333333333
24+
06|11111113333333333333
25+
07|11111113333333333333
26+
08|11111113333333333333
27+
09|11111113333333333333
28+
10|11111113333333333333
29+
11|11111113333333333333
30+
12|11111113333333333333
31+
13|11111113333333333333
3232
14|44444444444444444444
3333
15|44444444444444444444

tests/screenshots/tests-test_git.lua----Git---completion---works-with-subcommand-targets-002

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
01|
33
02|~
44
03|~
5-
04|~
6-
05|~ git-repo/
7-
06|~ mocks/
5+
04|~ git-repo/
6+
05|~ mocks/
7+
06|~ deps-confirm
88
07|~ diff-output
99
08|~ file
1010
09|~ file1
@@ -19,8 +19,8 @@
1919
01|00000000000000000000
2020
02|11111111111111111111
2121
03|11111111111111111111
22-
04|11111111111111111111
23-
05|11111112222222222222
22+
04|11111112222222222222
23+
05|11111113333333333333
2424
06|11111113333333333333
2525
07|11111113333333333333
2626
08|11111113333333333333

tests/screenshots/tests-test_git.lua----Git---completion---works-with-subcommand-targets-003

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22
01|
33
02|~
44
03|~
5-
04|~
6-
05|~ git-repo/
7-
06|~ mocks/
8-
07|~ diff-output
9-
08|~ file
10-
09|~ file1
11-
10|~ File2
12-
11|~ file3
13-
12|~ help-output
14-
13|~ log-output
5+
04|~ git-repo/
6+
05|~ mocks/
7+
06|~ deps-confirm
8+
07|~ diff-output
9+
08|~ file
10+
09|~ file1
11+
10|~ File2
12+
11|~ file3
13+
12|~ help-output
14+
13|~ log-output
1515
14|:Git restore git-rep
1616
15|o/
1717

1818
--|---------|---------|
1919
01|00000000000000000000
2020
02|11111111111111111111
2121
03|11111111111111111111
22-
04|11111111111111111111
23-
05|11111111222222222222
24-
06|11111111333333333333
25-
07|11111111333333333333
26-
08|11111111333333333333
27-
09|11111111333333333333
28-
10|11111111333333333333
29-
11|11111111333333333333
30-
12|11111111333333333333
31-
13|11111111333333333333
22+
04|11111112222222222222
23+
05|11111113333333333333
24+
06|11111113333333333333
25+
07|11111113333333333333
26+
08|11111113333333333333
27+
09|11111113333333333333
28+
10|11111113333333333333
29+
11|11111113333333333333
30+
12|11111113333333333333
31+
13|11111113333333333333
3232
14|44444444444444444444
3333
15|44444444444444444444

tests/screenshots/tests-test_git.lua----Git---completion---works-with-subcommand-targets-004

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
01|
33
02|~
44
03|~
5-
04|~
6-
05|~ git-repo/
7-
06|~ mocks/
5+
04|~ git-repo/
6+
05|~ mocks/
7+
06|~ deps-confirm
88
07|~ diff-output
99
08|~ file
1010
09|~ file1
@@ -19,8 +19,8 @@
1919
01|00000000000000000000
2020
02|11111111111111111111
2121
03|11111111111111111111
22-
04|11111111111111111111
23-
05|11111112222222222222
22+
04|11111112222222222222
23+
05|11111113333333333333
2424
06|11111113333333333333
2525
07|11111113333333333333
2626
08|11111113333333333333

0 commit comments

Comments
 (0)