aboutsummaryrefslogtreecommitdiff
diff refs
from:
to:
flip
diff options
context:
space:
mode:
-rw-r--r--cgit.css5
-rwxr-xr-xtests/t0106-diff.sh21
-rw-r--r--ui-diff.c8
3 files changed, 34 insertions, 0 deletions
diff --git a/cgit.css b/cgit.css
index 7892eca..8563462 100644
--- a/cgit.css
+++ b/cgit.css
@@ -674,6 +674,11 @@ div#cgit a.button {
padding: 0em 0.5em;
}
+div#cgit form.diff-ctrls div.cgit-panel a.button {
+ border: solid 1px var(--border-mid);
+ background-color: var(--bg-hl);
+}
+
div#cgit a.primary {
font-size: 100%;
}
diff --git a/tests/t0106-diff.sh b/tests/t0106-diff.sh
index e4751e9..1100596 100755
--- a/tests/t0106-diff.sh
+++ b/tests/t0106-diff.sh
@@ -45,6 +45,15 @@ test_expect_success 'ref picker: auto-submit on change' '
grep "onchange=.this.form.submit()." tmp
'
+test_expect_success 'flip link present' '
+ grep "<a title=.swap from and to. class=.button. href=./foo/diff/?" tmp
+'
+
+test_expect_success 'flip link swaps the default refs' '
+ old=$(git --git-dir="$PWD/repos/foo/.git" rev-parse master~1) &&
+ grep "/foo/diff/?id=$old&amp;id2=master" tmp
+'
+
test_expect_success 'compare two refs: foo/diff?id=master&id2=HEAD' '
cgit_query "url=foo/diff&id=master&id2=HEAD" >tmp
'
@@ -77,4 +86,16 @@ test_expect_success 'diff with HEAD and root shows content' '
grep "diffstat" tmp
'
+test_expect_success 'flip link swaps explicit refs' '
+ cgit_query "url=foo/diff&id=master&id2=HEAD" >tmp &&
+ new=$(git --git-dir="$PWD/repos/foo/.git" rev-parse HEAD) &&
+ grep "/foo/diff/?id=$new&amp;id2=master" tmp
+'
+
+test_expect_success 'flip link omits id for a diff against a root commit' '
+ root=$(git --git-dir="$PWD/repos/foo/.git" rev-list --max-parents=0 HEAD) &&
+ cgit_query "url=foo/diff&id=$root" >tmp &&
+ grep "href=./foo/diff/?id2=$root." tmp
+'
+
test_done
diff --git a/ui-diff.c b/ui-diff.c
index 5ee3830..13c1e32 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -409,6 +409,14 @@ void cgit_print_diff_ctrls(void)
html("<td class='ctrl'>");
cgit_print_ref_select("id", new_ref);
html("</td></tr>");
+
+ html("<tr><td/><td class='ctrl'>");
+ cgit_diff_link("flip", "swap from and to", "button",
+ ctx.qry.head,
+ is_null_oid(old_rev_oid) ? NULL :
+ oid_to_hex(old_rev_oid),
+ new_ref, ctx.qry.path);
+ html("</td></tr>");
}
html("</table>");
html("</div>");