Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab48eeb

Browse files
committed
feat(picker.git_diff): show proper git status for git diff files
1 parent765d50e commitab48eeb

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

‎lua/snacks/picker/source/diff.lua‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local M = {}
1111

1212
---@classsnacks.picker.diff.Block
1313
---@fieldtype?"new"|"delete"|"rename"|"copy"|"mode"
14+
---@fieldunmerged?boolean
1415
---@fieldfilestring
1516
---@fieldleft?string
1617
---@fieldright?string
@@ -54,13 +55,15 @@ function M.diff(opts, ctx)
5455
---@paramfilestring
5556
---@paramline?number
5657
---@paramdiffstring[]
57-
localfunctionadd(file,line,diff)
58+
---@paramblocksnacks.picker.diff.Block
59+
localfunctionadd(file,line,diff,block)
5860
line=lineor1
5961
cb({
6062
text=file..":"..line,
6163
diff=table.concat(diff,"\n"),
6264
file=file,
6365
cwd=cwd,
66+
block=block,
6467
pos= {line,0 },
6568
})
6669
end
@@ -72,12 +75,12 @@ function M.diff(opts, ctx)
7275
ifopts.groupthen
7376
vim.list_extend(diff,h.diff)
7477
else
75-
add(block.file,h.line,vim.list_extend(vim.deepcopy(block.header),h.diff))
78+
add(block.file,h.line,vim.list_extend(vim.deepcopy(block.header),h.diff),block)
7679
end
7780
end
7881
ifopts.groupor#block.hunks==0then
7982
localline=block.hunks[1]andblock.hunks[1].lineor1
80-
add(block.file,line,vim.list_extend(vim.deepcopy(block.header),diff))
83+
add(block.file,line,vim.list_extend(vim.deepcopy(block.header),diff),block)
8184
end
8285
end
8386
end
@@ -190,6 +193,7 @@ function M.parse(lines)
190193
localline=1
191194
iftext:find("@@@",1,true)==1then
192195
line=tonumber(text:match("^@@@ %-%d+,?%d* %-%d+,?%d* %+(%d+),?%d* @@@"))or1
196+
block.unmerged=true
193197
else
194198
line=tonumber(text:match("^@@ %-%d+,?%d* %+(%d+),?%d* @@"))or1
195199
end

‎lua/snacks/picker/source/git.lua‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ end
256256
---@typesnacks.picker.finder
257257
functionM.diff(opts,ctx)
258258
opts=optsor {}
259-
localargs=M.git("diff","--no-color","--no-ext-diff", {args= {"--no-pager"} },opts)
259+
localargs=M.git("diff","--no-color","--no-ext-diff","--diff-filter=u",{args= {"--no-pager"} },opts)
260260
ifopts.basethen
261261
vim.list_extend(args, {"--merge-base",opts.base })
262262
end
@@ -290,11 +290,9 @@ function M.diff(opts, ctx)
290290
finder(function(item)
291291
ifnotopts.basethen
292292
item.staged=opts.stagedorf==2
293-
ifitem.stagedthen
294-
item.status="M"
295-
else
296-
item.status=" M"
297-
end
293+
localblock=item.block---@typesnacks.picker.diff.Block
294+
localstatus= ({new="A",delete="D",rename="R",copy="C"})[block.type]or"M"
295+
item.status=block.unmergedand (status..status)oritem.stagedand (status.."")or (""..status)
298296
end
299297
items[#items+1]=item
300298
end)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp