Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions rebase-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ find_correspondence () {
echo "${match#* }"
}

# Run git range-diff and mark up the output with ```diff code blocks for
# Markdown rendering. Accepts the same arguments as git range-diff.
# Propagates the range-diff exit code on failure.
range_diff_with_markup () {
_rdi=$(git range-diff "$@") || return
printf '%s\n' "$_rdi" | markup_range_diff
}

# Apply range-diff markup to already-produced range-diff text on stdin.
markup_range_diff () {
sed -e '/^ \{0,3\}\(-\|[1-9][0-9]*\):/{a\
\
``````diff
s/^ */* /;1b;i\
``````\

}' -e 's/^ / /' -e '$a\
``````' |
sed -e '/^$/{
N
/^\n ``````diff/{
N
/diff\n ``````/{
$d
N
d}}}'
}

# Run a rebase, automatically skipping commits that match upstream exactly
# and trying to reuse sibling resolutions via merge-tree
# Usage: run_rebase <rebase-args...>
Expand Down Expand Up @@ -280,9 +308,7 @@ Your FINAL line must be exactly: skip <oid>, skip -- <reason>, continue -- <summ
<details>
<summary>Range-diff</summary>

\`\`\`
$(git range-diff --creation-factor=999 "$rebase_head_oid^!" "$upstream_oid^!" || echo "Unable to generate range-diff")
\`\`\`
$(range_diff_with_markup --creation-factor=999 "$rebase_head_oid^!" "$upstream_oid^!" || echo "Unable to generate range-diff")

</details>

Expand Down Expand Up @@ -382,7 +408,7 @@ Your FINAL line must be exactly: continue or fail"
else
git commit -C REBASE_HEAD ||
die "git commit failed for $rebase_head_oneline"
resolution_rangediff=$(git range-diff --creation-factor=999 "$rebase_head_oid^!" HEAD^! || echo "Unable to generate range-diff")
resolution_rangediff=$(range_diff_with_markup --creation-factor=999 "$rebase_head_oid^!" HEAD^! || echo "Unable to generate range-diff")
cat >>"$REPORT_FILE" <<-CONTINUE_EOF

#### Resolved: $rebase_head_ref
Expand All @@ -392,9 +418,7 @@ Your FINAL line must be exactly: continue or fail"
<details>
<summary>Range-diff</summary>

\`\`\`
$resolution_rangediff
\`\`\`

</details>

Expand Down Expand Up @@ -630,9 +654,7 @@ cat >>"$REPORT_FILE" <<EOF
<details>
<summary>Range-diff (click to expand)</summary>

\`\`\`
$RANGE_DIFF
\`\`\`
$(printf '%s\n' "$RANGE_DIFF" | markup_range_diff)

</details>

Expand Down