From 463fd0876aa2e3e991d2453e24557aa956d974d9 Mon Sep 17 00:00:00 2001 From: NicolasGB Date: Sun, 25 Jan 2026 19:13:42 +0100 Subject: [PATCH] fix(parser): support for divergent changes --- lua/jj/core/parser.lua | 14 ++++++++-- tests/run_tests.lua | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/lua/jj/core/parser.lua b/lua/jj/core/parser.lua index eefe65a..9c53834 100644 --- a/lua/jj/core/parser.lua +++ b/lua/jj/core/parser.lua @@ -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 diff --git a/tests/run_tests.lua b/tests/run_tests.lua index 912c37a..f7871e2 100755 --- a/tests/run_tests.lua +++ b/tests/run_tests.lua @@ -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))