Skip to content

Commit 6ced56d

Browse files
committed
chore: refactor
1 parent f6afe8f commit 6ced56d

92 files changed

Lines changed: 3668 additions & 7192 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.githooks/commit-msg

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
commit_msg_file="$1"
5+
commit_msg=$(head -1 "$commit_msg_file")
6+
7+
# Allow merge commits
8+
if echo "$commit_msg" | grep -qE '^Merge '; then
9+
exit 0
10+
fi
11+
12+
# Conventional commits pattern: type(optional-scope): description
13+
# Types aligned with webiny/action-conventional-commits used in CI
14+
types="feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert"
15+
pattern="^($types)(\(.+\))?(!)?: .+"
16+
17+
if ! echo "$commit_msg" | grep -qE "$pattern"; then
18+
echo "FAILED: Commit message does not follow Conventional Commits format."
19+
echo ""
20+
echo "Expected: <type>(<optional-scope>): <description>"
21+
echo "Types: $types"
22+
echo ""
23+
echo "Examples:"
24+
echo " feat: add blame lens support"
25+
echo " fix(ui): prevent layout overflow"
26+
echo " chore: refactor"
27+
echo ""
28+
echo "Your message: $commit_msg"
29+
exit 1
30+
fi

.githooks/pre-commit

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
echo "Running pre-commit checks..."
5+
6+
failed=0
7+
8+
if command -v stylua >/dev/null 2>&1; then
9+
echo "=> stylua format check"
10+
if ! stylua --check --config-path stylua.toml lua/ tests/; then
11+
echo "FAILED: stylua format check. Run 'make format' to fix."
12+
failed=1
13+
fi
14+
else
15+
echo "SKIPPED: stylua not installed"
16+
fi
17+
18+
if command -v luacheck >/dev/null 2>&1; then
19+
echo "=> luacheck"
20+
if ! luacheck lua/ tests/ --config .luacheckrc; then
21+
echo "FAILED: luacheck found issues."
22+
failed=1
23+
fi
24+
else
25+
echo "SKIPPED: luacheck not installed"
26+
fi
27+
28+
if [ $failed -ne 0 ]; then
29+
echo ""
30+
echo "Pre-commit checks failed. Commit aborted."
31+
exit 1
32+
fi
33+
34+
echo "Pre-commit checks passed."

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test test-filter test-file lint format format-check check ci install-deps clean
1+
.PHONY: test test-filter test-file lint format format-check check ci install-deps clean setup-hooks
22

33
LUA_VERSION ?= 5.1
44

@@ -41,4 +41,8 @@ install-deps:
4141
clean:
4242
rm -rf luacov.stats.out luacov.report.out
4343

44+
setup-hooks:
45+
git config core.hooksPath .githooks
46+
@echo "Git hooks activated from .githooks/"
47+
4448
ci: check test

lua/vgit.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ controller.execute_command = event.async(function(args)
220220
debug = true,
221221
stash = true,
222222
worktree = true,
223-
commit = true
223+
commit = true,
224224
}
225225

226226
if porcelain_commands[cmd] then

lua/vgit/cli/commands/worktree_spec.lua

Lines changed: 76 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ describe('worktree_command:', function()
77
local function make_mock_repo(overrides)
88
overrides = overrides or {}
99
return {
10-
get_path = function() return '/tmp/repo' end,
11-
worktree_add = overrides.worktree_add or function() return {}, nil end,
12-
worktree_remove = overrides.worktree_remove or function() return {}, nil end,
13-
worktree_list = overrides.worktree_list or function() return {}, nil end,
10+
get_path = function()
11+
return '/tmp/repo'
12+
end,
13+
worktree_add = overrides.worktree_add or function()
14+
return {}, nil
15+
end,
16+
worktree_remove = overrides.worktree_remove or function()
17+
return {}, nil
18+
end,
19+
worktree_list = overrides.worktree_list or function()
20+
return {}, nil
21+
end,
1422
}
1523
end
1624

@@ -20,13 +28,16 @@ describe('worktree_command:', function()
2028
save_package('vgit.git.repository')
2129
package.loaded['vgit.git.repository'] = overrides.repository
2230
or {
23-
current = function() return make_mock_repo(overrides.repo_methods), nil end,
31+
current = function()
32+
return make_mock_repo(overrides.repo_methods), nil
33+
end,
2434
}
2535

2636
save_package('vgit.ui.display_service')
27-
package.loaded['vgit.ui.display_service'] = overrides.display_service or {
28-
show_worktree = function() end,
29-
}
37+
package.loaded['vgit.ui.display_service'] = overrides.display_service
38+
or {
39+
show_worktree = function() end,
40+
}
3041

3142
save_package('vgit.core.console')
3243
package.loaded['vgit.core.console'] = overrides.console
@@ -53,10 +64,14 @@ describe('worktree_command:', function()
5364
local worktrees = { { path = '/tmp/wt', head = 'abc', branch = 'feat' } }
5465
setup_defaults({
5566
repo_methods = {
56-
worktree_list = function() return worktrees, nil end,
67+
worktree_list = function()
68+
return worktrees, nil
69+
end,
5770
},
5871
display_service = {
59-
show_worktree = function(data) show_data = data end,
72+
show_worktree = function(data)
73+
show_data = data
74+
end,
6075
},
6176
})
6277
load_cmd().execute({})
@@ -114,10 +129,14 @@ describe('worktree_command:', function()
114129
local error_msg = nil
115130
setup_defaults({
116131
repository = {
117-
current = function() return nil, 'not a git repository' end,
132+
current = function()
133+
return nil, 'not a git repository'
134+
end,
118135
},
119136
console = {
120-
error = function(msg) error_msg = msg end,
137+
error = function(msg)
138+
error_msg = msg
139+
end,
121140
info = function() end,
122141
},
123142
})
@@ -129,7 +148,9 @@ describe('worktree_command:', function()
129148
local error_msg = nil
130149
setup_defaults({
131150
console = {
132-
error = function(msg) error_msg = msg end,
151+
error = function(msg)
152+
error_msg = msg
153+
end,
133154
info = function() end,
134155
},
135156
})
@@ -141,7 +162,9 @@ describe('worktree_command:', function()
141162
local error_msg = nil
142163
setup_defaults({
143164
console = {
144-
error = function(msg) error_msg = msg end,
165+
error = function(msg)
166+
error_msg = msg
167+
end,
145168
info = function() end,
146169
},
147170
})
@@ -153,7 +176,9 @@ describe('worktree_command:', function()
153176
local error_msg = nil
154177
setup_defaults({
155178
console = {
156-
error = function(msg) error_msg = msg end,
179+
error = function(msg)
180+
error_msg = msg
181+
end,
157182
info = function() end,
158183
},
159184
})
@@ -165,10 +190,14 @@ describe('worktree_command:', function()
165190
local error_msg = nil
166191
setup_defaults({
167192
repo_methods = {
168-
worktree_add = function() return nil, { 'fatal: path already exists' } end,
193+
worktree_add = function()
194+
return nil, { 'fatal: path already exists' }
195+
end,
169196
},
170197
console = {
171-
error = function(msg) error_msg = msg end,
198+
error = function(msg)
199+
error_msg = msg
200+
end,
172201
info = function() end,
173202
},
174203
})
@@ -180,10 +209,14 @@ describe('worktree_command:', function()
180209
local error_msg = nil
181210
setup_defaults({
182211
repo_methods = {
183-
worktree_remove = function() return nil, { 'fatal: not a valid worktree' } end,
212+
worktree_remove = function()
213+
return nil, { 'fatal: not a valid worktree' }
214+
end,
184215
},
185216
console = {
186-
error = function(msg) error_msg = msg end,
217+
error = function(msg)
218+
error_msg = msg
219+
end,
187220
info = function() end,
188221
},
189222
})
@@ -195,10 +228,14 @@ describe('worktree_command:', function()
195228
local error_msg = nil
196229
setup_defaults({
197230
repo_methods = {
198-
worktree_list = function() return nil, { 'failed to list' } end,
231+
worktree_list = function()
232+
return nil, { 'failed to list' }
233+
end,
199234
},
200235
console = {
201-
error = function(msg) error_msg = msg end,
236+
error = function(msg)
237+
error_msg = msg
238+
end,
202239
info = function() end,
203240
},
204241
})
@@ -210,11 +247,15 @@ describe('worktree_command:', function()
210247
local info_msg = nil
211248
setup_defaults({
212249
repo_methods = {
213-
worktree_list = function() return {}, nil end,
250+
worktree_list = function()
251+
return {}, nil
252+
end,
214253
},
215254
console = {
216255
error = function() end,
217-
info = function(msg) info_msg = msg end,
256+
info = function(msg)
257+
info_msg = msg
258+
end,
218259
},
219260
})
220261
load_cmd().execute({})
@@ -227,11 +268,15 @@ describe('worktree_command:', function()
227268
local info_msg = nil
228269
setup_defaults({
229270
repo_methods = {
230-
worktree_add = function() return {}, nil end,
271+
worktree_add = function()
272+
return {}, nil
273+
end,
231274
},
232275
console = {
233276
error = function() end,
234-
info = function(msg) info_msg = msg end,
277+
info = function(msg)
278+
info_msg = msg
279+
end,
235280
},
236281
})
237282
load_cmd().execute({ 'add', '/tmp/new-wt' })
@@ -242,11 +287,15 @@ describe('worktree_command:', function()
242287
local info_msg = nil
243288
setup_defaults({
244289
repo_methods = {
245-
worktree_remove = function() return {}, nil end,
290+
worktree_remove = function()
291+
return {}, nil
292+
end,
246293
},
247294
console = {
248295
error = function() end,
249-
info = function(msg) info_msg = msg end,
296+
info = function(msg)
297+
info_msg = msg
298+
end,
250299
},
251300
})
252301
load_cmd().execute({ 'remove', '/tmp/old-wt' })

lua/vgit/features/buffer/Hunks.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ function Hunks:cursor_stage()
8383
if buffer:is_modified() then return end
8484

8585
-- Performance: Deferred sync of only the current buffer after staging
86-
event.defer(event.async(function()
87-
if buffer:is_valid() then git_buffer_store.dispatch(buffer, 'sync') end
88-
end), 200)
86+
event.defer(
87+
event.async(function()
88+
if buffer:is_valid() then git_buffer_store.dispatch(buffer, 'sync') end
89+
end),
90+
200
91+
)
8992

9093
if not buffer:is_tracked() then
9194
local _, err = buffer:stage()

lua/vgit/features/buffer/LiveBlame_spec.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ describe('LiveBlame blame flow (integration):', function()
157157

158158
after_each(function()
159159
for _, bufnr in ipairs(created_bufnrs) do
160-
if vim.api.nvim_buf_is_valid(bufnr) then
161-
vim.api.nvim_buf_delete(bufnr, { force = true })
162-
end
160+
if vim.api.nvim_buf_is_valid(bufnr) then vim.api.nvim_buf_delete(bufnr, { force = true }) end
163161
end
164162
if repo then test_repo.cleanup(repo) end
165163
end)

lua/vgit/features/buffer/LiveConflict_spec.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ describe('LiveConflict conflict flow (integration):', function()
109109

110110
after_each(function()
111111
for _, bufnr in ipairs(created_bufnrs) do
112-
if vim.api.nvim_buf_is_valid(bufnr) then
113-
vim.api.nvim_buf_delete(bufnr, { force = true })
114-
end
112+
if vim.api.nvim_buf_is_valid(bufnr) then vim.api.nvim_buf_delete(bufnr, { force = true }) end
115113
end
116114
if repo then test_repo.cleanup(repo) end
117115
end)

lua/vgit/features/buffer/LiveGutter_spec.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,7 @@ describe('LiveGutter fetch (integration):', function()
209209

210210
after_each(function()
211211
for _, bufnr in ipairs(created_bufnrs) do
212-
if vim.api.nvim_buf_is_valid(bufnr) then
213-
vim.api.nvim_buf_delete(bufnr, { force = true })
214-
end
212+
if vim.api.nvim_buf_is_valid(bufnr) then vim.api.nvim_buf_delete(bufnr, { force = true }) end
215213
end
216214
if repo then test_repo.cleanup(repo) end
217215
end)

0 commit comments

Comments
 (0)