Skip to content

Commit 7351be3

Browse files
authored
rebase-branch: mark up range-diffs with ```diff code blocks (#157)
The range-diffs in the shears-builds PRs (e.g. git-for-windows/shears-builds#12) are currently rendered as plain monochrome text. By wrapping each range-diff entry in ```diff fenced code blocks instead, GitHub applies diff-style syntax highlighting, making them noticeably more readable. This is the same markup used in the "Rebase to Git <version>" PRs at git-for-windows/git. All three user-facing range-diff sites are updated (per-skip, per-resolution, and final summary); the correspondence-map generation and AI agent prompts are untouched.
2 parents 4f62410 + aac388a commit 7351be3

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

.github/workflows/rebase-shears.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,14 @@ jobs:
356356
}
357357
358358
title="Rebase shears/$name (#$run_id)"
359+
stats="$worktree/conflict-stats.txt"
360+
if test -f "$stats"; then
361+
eval "$(cat "$stats")"
362+
total=$((skipped + resolved))
363+
if test "$total" -gt 0; then
364+
title="Rebase shears/$name: $total conflict(s) ($skipped skipped, $resolved resolved) (#$run_id)"
365+
fi
366+
fi
359367
{
360368
echo "[Workflow run]($run_url)"
361369
echo

rebase-branch.sh

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,34 @@ find_correspondence () {
4444
echo "${match#* }"
4545
}
4646

47+
# Run git range-diff and mark up the output with ```diff code blocks for
48+
# Markdown rendering. Accepts the same arguments as git range-diff.
49+
# Propagates the range-diff exit code on failure.
50+
range_diff_with_markup () {
51+
_rdi=$(git range-diff "$@") || return
52+
printf '%s\n' "$_rdi" | markup_range_diff
53+
}
54+
55+
# Apply range-diff markup to already-produced range-diff text on stdin.
56+
markup_range_diff () {
57+
sed -e '/^ \{0,3\}\(-\|[1-9][0-9]*\):/{a\
58+
\
59+
``````diff
60+
s/^ */* /;1b;i\
61+
``````\
62+
63+
}' -e 's/^ / /' -e '$a\
64+
``````' |
65+
sed -e '/^$/{
66+
N
67+
/^\n ``````diff/{
68+
N
69+
/diff\n ``````/{
70+
$d
71+
N
72+
d}}}'
73+
}
74+
4775
# Run a rebase, automatically skipping commits that match upstream exactly
4876
# and trying to reuse sibling resolutions via merge-tree
4977
# Usage: run_rebase <rebase-args...>
@@ -280,9 +308,7 @@ Your FINAL line must be exactly: skip <oid>, skip -- <reason>, continue -- <summ
280308
<details>
281309
<summary>Range-diff</summary>
282310
283-
\`\`\`
284-
$(git range-diff --creation-factor=999 "$rebase_head_oid^!" "$upstream_oid^!" || echo "Unable to generate range-diff")
285-
\`\`\`
311+
$(range_diff_with_markup --creation-factor=999 --remerge-diff "$rebase_head_oid^!" "$upstream_oid^!" || echo "Unable to generate range-diff")
286312
287313
</details>
288314
@@ -382,7 +408,7 @@ Your FINAL line must be exactly: continue or fail"
382408
else
383409
git commit -C REBASE_HEAD ||
384410
die "git commit failed for $rebase_head_oneline"
385-
resolution_rangediff=$(git range-diff --creation-factor=999 "$rebase_head_oid^!" HEAD^! || echo "Unable to generate range-diff")
411+
resolution_rangediff=$(range_diff_with_markup --creation-factor=999 --remerge-diff "$rebase_head_oid^!" HEAD^! || echo "Unable to generate range-diff")
386412
cat >>"$REPORT_FILE" <<-CONTINUE_EOF
387413
388414
#### Resolved: $rebase_head_ref
@@ -392,9 +418,7 @@ Your FINAL line must be exactly: continue or fail"
392418
<details>
393419
<summary>Range-diff</summary>
394420
395-
\`\`\`
396421
$resolution_rangediff
397-
\`\`\`
398422
399423
</details>
400424
@@ -597,7 +621,7 @@ test "$PARENT_COUNT" -eq 3 || # commit itself + 2 parents
597621
die "Marker should have 2 parents, found $((PARENT_COUNT - 1))"
598622

599623
# Generate range-diff comparing original patches with rebased patches
600-
RANGE_DIFF=$(git range-diff "$ORIG_OLD_MARKER..$ORIG_TIP_OID" \
624+
RANGE_DIFF=$(git range-diff --remerge-diff "$ORIG_OLD_MARKER..$ORIG_TIP_OID" \
601625
"$MARKER_IN_RESULT..HEAD" || echo "Unable to generate range-diff")
602626

603627
# Annotate range-diff with upstream OIDs for skipped commits
@@ -630,9 +654,7 @@ cat >>"$REPORT_FILE" <<EOF
630654
<details>
631655
<summary>Range-diff (click to expand)</summary>
632656
633-
\`\`\`
634-
$RANGE_DIFF
635-
\`\`\`
657+
$(printf '%s\n' "$RANGE_DIFF" | markup_range_diff)
636658
637659
</details>
638660
@@ -641,6 +663,10 @@ EOF
641663
echo "Rebase completed: $(git rev-parse --short HEAD)"
642664
cat "$REPORT_FILE"
643665

666+
# Write conflict stats for the workflow to pick up in PR titles
667+
echo "skipped=$CONFLICTS_SKIPPED resolved=$CONFLICTS_RESOLVED" \
668+
>"$WORKTREE_DIR/conflict-stats.txt"
669+
644670
# Write to GitHub Actions job summary
645671
if test -n "$GITHUB_STEP_SUMMARY"; then
646672
cat "$REPORT_FILE" >>"$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)