Skip to content

Commit 80f7157

Browse files
committed
complete: include offset in completions for divergent changes
1 parent 1fb5a96 commit 80f7157

File tree

2 files changed

+46
-29
lines changed

2 files changed

+46
-29
lines changed

cli/src/complete.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,16 @@ fn revisions(match_prefix: &str, revset_filter: Option<&str>) -> Vec<CompletionC
390390
.arg("--revisions")
391391
.arg(revisions)
392392
.arg("--template")
393-
.arg(r#"change_id.shortest() ++ " " ++ if(description, description.first_line(), "(no description set)") ++ "\n""#)
393+
.arg(
394+
r#"
395+
join(" ",
396+
separate("/",
397+
change_id.shortest(),
398+
if(hidden || divergent, change_offset),
399+
),
400+
if(description, description.first_line(), "(no description set)"),
401+
) ++ "\n""#,
402+
)
394403
.output()
395404
.map_err(user_error)?;
396405
let stdout = String::from_utf8_lossy(&output.stdout);

cli/tests/test_completion.rs

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -809,14 +809,16 @@ fn test_revisions() {
809809
);
810810

811811
work_dir.write_file("file", "A");
812+
work_dir.run_jj(["describe", "-m", "mutable 1"]).success();
813+
work_dir.run_jj(["describe", "-m", "mutable 2"]).success();
814+
// Create divergent change
812815
work_dir
813-
.run_jj(["b", "c", "-r@", "mutable_bookmark"])
816+
.run_jj(["b", "c", "-r=at_operation(@-, @)", "mutable_bookmark"])
814817
.success();
815-
work_dir.run_jj(["describe", "-m", "mutable 1"]).success();
816818

817819
work_dir.run_jj(["new", "immutable_bookmark"]).success();
818820
work_dir.write_file("file", "B");
819-
work_dir.run_jj(["describe", "-m", "mutable 2"]).success();
821+
work_dir.run_jj(["describe", "-m", "mutable 3"]).success();
820822
work_dir.run_jj(["new", "@", "mutable_bookmark"]).success();
821823
work_dir
822824
.run_jj(["b", "c", "-r@", "conflicted_bookmark"])
@@ -840,10 +842,11 @@ fn test_revisions() {
840842
conflicted_bookmark conflicted
841843
immutable_bookmark immutable
842844
mutable_bookmark mutable 1
843-
u working_copy
844-
l conflicted
845-
k mutable 2
846-
y mutable 1
845+
x working_copy
846+
k conflicted
847+
w mutable 3
848+
y/0 mutable 2
849+
y/1 mutable 1
847850
q immutable
848851
r remote_commit
849852
z (no description set)
@@ -859,10 +862,11 @@ fn test_revisions() {
859862
..conflicted_bookmark conflicted
860863
..immutable_bookmark immutable
861864
..mutable_bookmark mutable 1
862-
..u working_copy
863-
..l conflicted
864-
..k mutable 2
865-
..y mutable 1
865+
..x working_copy
866+
..k conflicted
867+
..w mutable 3
868+
..y/0 mutable 2
869+
..y/1 mutable 1
866870
..q immutable
867871
..r remote_commit
868872
..z (no description set)
@@ -877,10 +881,11 @@ fn test_revisions() {
877881
insta::assert_snapshot!(output, @r"
878882
conflicted_bookmark conflicted
879883
mutable_bookmark mutable 1
880-
u working_copy
881-
l conflicted
882-
k mutable 2
883-
y mutable 1
884+
x working_copy
885+
k conflicted
886+
w mutable 3
887+
y/0 mutable 2
888+
y/1 mutable 1
884889
r remote_commit
885890
alias_with_newline roots(
886891
siblings @-+ ~@
@@ -892,10 +897,11 @@ fn test_revisions() {
892897
insta::assert_snapshot!(output, @r"
893898
y::conflicted_bookmark conflicted
894899
y::mutable_bookmark mutable 1
895-
y::u working_copy
896-
y::l conflicted
897-
y::k mutable 2
898-
y::y mutable 1
900+
y::x working_copy
901+
y::k conflicted
902+
y::w mutable 3
903+
y::y/0 mutable 2
904+
y::y/1 mutable 1
899905
y::r remote_commit
900906
y::alias_with_newline roots(
901907
y::siblings @-+ ~@
@@ -913,7 +919,7 @@ fn test_revisions() {
913919
let output = work_dir.complete_fish(["resolve", "-r", ""]);
914920
insta::assert_snapshot!(output, @r"
915921
conflicted_bookmark conflicted
916-
l conflicted
922+
k conflicted
917923
alias_with_newline roots(
918924
siblings @-+ ~@
919925
[EOF]
@@ -926,10 +932,11 @@ fn test_revisions() {
926932
conflicted_bookmark conflicted
927933
immutable_bookmark immutable
928934
mutable_bookmark mutable 1
929-
u working_copy
930-
l conflicted
931-
k mutable 2
932-
y mutable 1
935+
x working_copy
936+
k conflicted
937+
w mutable 3
938+
y/0 mutable 2
939+
y/1 mutable 1
933940
q immutable
934941
r remote_commit
935942
z (no description set)
@@ -953,10 +960,11 @@ fn test_revisions() {
953960
a=conflicted_bookmark conflicted
954961
a=immutable_bookmark immutable
955962
a=mutable_bookmark mutable 1
956-
a=u working_copy
957-
a=l conflicted
958-
a=k mutable 2
959-
a=y mutable 1
963+
a=x working_copy
964+
a=k conflicted
965+
a=w mutable 3
966+
a=y/0 mutable 2
967+
a=y/1 mutable 1
960968
a=q immutable
961969
a=r remote_commit
962970
a=z (no description set)

0 commit comments

Comments
 (0)