mirror of
https://github.com/zoriya/jj.nvim.git
synced 2026-08-15 23:53:18 +00:00
fix(parser): support for divergent changes
This commit is contained in:
+12
-2
@@ -162,12 +162,22 @@ function M.get_revset(line)
|
||||
allowed_prefix = allowed_prefix .. "]+" -- close class, match one or more (not zero)
|
||||
|
||||
-- Match first alphanumeric sequence after graph prefix
|
||||
-- Only match if it's followed by whitespace or end of string (not part of text)
|
||||
local revset = line:match("^" .. allowed_prefix .. "(%w+)%s")
|
||||
-- Supports divergent changes: revset\0, revset\1, etc.
|
||||
-- Only match if it's followed by whitespace, backslash (for divergent), or end of string
|
||||
|
||||
-- Try matching with divergent suffix first: revset\N where N is a number
|
||||
local revset, divergent_num = line:match("^" .. allowed_prefix .. "(%w+)\\(%d+)")
|
||||
if revset and divergent_num then
|
||||
return revset .. "\\" .. divergent_num
|
||||
end
|
||||
|
||||
-- Try regular match followed by whitespace
|
||||
revset = line:match("^" .. allowed_prefix .. "(%w+)%s")
|
||||
if not revset then
|
||||
-- Try matching at end of line without trailing whitespace
|
||||
revset = line:match("^" .. allowed_prefix .. "(%w+)$")
|
||||
end
|
||||
|
||||
return revset
|
||||
end
|
||||
|
||||
|
||||
@@ -283,6 +283,67 @@ run_test("still parses correctly with box chars and symbol", function()
|
||||
assert_equals("go", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("still parses correctly with divergent change suffix \\0", function()
|
||||
local line = "├─○ go\\0 some description"
|
||||
assert_equals("go\\0", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
-- Divergent changes tests
|
||||
run_test("parses divergent change with \\0", function()
|
||||
local line = "◆ abc123\\0 first divergent copy"
|
||||
assert_equals("abc123\\0", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses divergent change with \\1", function()
|
||||
local line = "○ def456\\1 second divergent copy"
|
||||
assert_equals("def456\\1", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses divergent change with \\2", function()
|
||||
local line = "◆ ghi789\\2 third divergent copy"
|
||||
assert_equals("ghi789\\2", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses divergent change with higher number \\10", function()
|
||||
local line = "○ jkl012\\10 tenth divergent copy"
|
||||
assert_equals("jkl012\\10", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses divergent change with graph chars", function()
|
||||
local line = "│ │ ◆ mno345\\0 divergent on branch"
|
||||
assert_equals("mno345\\0", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses divergent change with @ symbol", function()
|
||||
local line = "@ pqr678\\1 working copy divergent"
|
||||
assert_equals("pqr678\\1", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses divergent change with conflict symbol", function()
|
||||
local line = "× stu901\\0 conflicted divergent"
|
||||
assert_equals("stu901\\0", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses divergent change with merge connector", function()
|
||||
local line = "├─○ vwx234\\2 divergent after merge"
|
||||
assert_equals("vwx234\\2", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses divergent change deeply nested", function()
|
||||
local line = "│ │ │ │ ◆ yza567\\0 deeply nested divergent"
|
||||
assert_equals("yza567\\0", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses short revset with divergent suffix", function()
|
||||
local line = "○ a\\0 single char divergent"
|
||||
assert_equals("a\\0", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
run_test("parses divergent change at end of line", function()
|
||||
local line = "◆ bcd890\\1"
|
||||
assert_equals("bcd890\\1", parser.get_revset(line))
|
||||
end)
|
||||
|
||||
-- Print summary
|
||||
print(string.format("\n=== Test Summary ==="))
|
||||
print(string.format("Passed: %d", tests_passed))
|
||||
|
||||
Reference in New Issue
Block a user