Repository navigation
Expand file tree
/
Copy pathsetup.lua
More file actions
95 lines (83 loc) · 3.33 KB
/
Copy pathsetup.lua
File metadata and controls
95 lines (83 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
if vim.g.minidiff_dev_setup_loaded then
return
end
vim.g.minidiff_dev_setup_loaded = true
local script_path = debug.getinfo(1, "S").source:sub(2)
local repo = vim.fs.dirname(vim.fs.dirname(script_path))
local dev_dir = vim.fs.dirname(script_path)
local repo_lua = vim.fs.joinpath(repo, "lua")
package.path = vim.fs.joinpath(repo_lua, "?.lua") .. ";" .. vim.fs.joinpath(repo_lua, "?", "init.lua") .. ";" .. package.path
vim.opt.runtimepath:append(vim.fs.joinpath(vim.fs.dirname(repo), "fastgit.nvim"))
vim.g.minidiff_dev_dir = dev_dir
vim.g.minidiff_repo_dir = repo
vim.g.mapleader = " "
vim.opt.number = true
local function run(args, dir)
local result = vim.system(args, { cwd = dir, text = true }):wait()
if result.code ~= 0 then
error(table.concat(args, " ") .. "\n" .. (result.stderr or "") .. (result.stdout or ""))
end
return result.stdout or ""
end
local function file_lines(id)
local lines = {}
for line = 1, 80 do
lines[line] = ("file_%02d original line %02d"):format(id, line)
end
return lines
end
local function create_test_repo()
local worktree = vim.fs.joinpath(dev_dir, "mini-diff-dev-worktree")
if vim.uv.fs_stat(vim.fs.joinpath(worktree, ".git")) then
run({ "git", "reset", "--hard", "--quiet", "HEAD" }, worktree)
run({ "git", "clean", "-fd", "--quiet" }, worktree)
for id = 1, 5 do
local path = vim.fs.joinpath(worktree, ("file_%02d.txt"):format(id))
local lines = vim.fn.readfile(path)
lines[10] = ("file_%02d changed line 10"):format(id)
lines[30] = ("file_%02d changed line 30"):format(id)
vim.fn.writefile(lines, path)
end
return vim.fs.joinpath(worktree, "file_01.txt")
end
vim.fn.delete(worktree, "rf")
vim.fn.mkdir(worktree, "p")
run({ "git", "init", "--quiet" }, worktree)
for id = 1, 5 do
vim.fn.writefile(file_lines(id), vim.fs.joinpath(worktree, ("file_%02d.txt"):format(id)))
end
run({ "git", "add", "." }, worktree)
run({ "git", "-c", "user.email=mini.diff@example.invalid", "-c", "user.name=mini.diff", "commit", "--quiet", "-m", "base" }, worktree)
for id = 1, 5 do
local path = vim.fs.joinpath(worktree, ("file_%02d.txt"):format(id))
local lines = vim.fn.readfile(path)
lines[10] = ("file_%02d changed line 10"):format(id)
lines[30] = ("file_%02d changed line 30"):format(id)
vim.fn.writefile(lines, path)
end
return vim.fs.joinpath(worktree, "file_01.txt")
end
vim.opt.swapfile = false
vim.cmd.edit(vim.fn.fnameescape(create_test_repo()))
local MiniDiff = require("mini.diff")
require("util.log").enabled = true
MiniDiff.setup({ source = require("fastgit").source() })
MiniDiff.enable(0)
MiniDiff.toggle_overlay(0)
vim.keymap.set("n", "<leader>lal", function()
require("util.log").open()
end, { desc = "Open dev log" })
vim.keymap.set("n", "]c", function()
MiniDiff.goto_hunk("next")
end, { desc = "Next hunk" })
vim.keymap.set("n", "[c", function()
MiniDiff.goto_hunk("prev")
end, { desc = "Previous hunk" })
vim.keymap.set("n", "<leader>las", function()
local line = vim.api.nvim_win_get_cursor(0)[1]
MiniDiff.do_hunks(0, "apply", { line_start = line, line_end = line })
MiniDiff.goto_hunk("next")
end, { desc = "Stage hunk and jump next" })
vim.keymap.set("n", "<C-j>", "<cmd>cnext<cr>", { desc = "Next quickfix item" })
vim.keymap.set("n", "<C-k>", "<cmd>cprevious<cr>", { desc = "Previous quickfix item" })
vim.keymap.set("n", "<M-q><M-q>", "<cmd>qa!<cr>", { desc = "Quit dev session" })