blob: ed51bdf01e73e47a8d8e91a7d3194f4c789b6b68 [file] [log] [blame]
Copybara botca5ce642024-11-08 17:38:08 +01001#!/usr/bin/env bash
2# Adapted from https://gist.github.com/thoughtpolice/8f2fd36ae17cd11b8e7bd93a70e31ad6
3
4set -euo pipefail
5
6CID=$(jj log --no-graph -r @ -T "change_id" | sha256sum | head -c 40)
7
8CHGSTR="Change-Id: I${CID}"
9
10contents=$(<"$1")
11readarray -t lines <<<"$contents"
12
13body=''
14last=''
15for x in "${lines[@]}"; do
16 [[ "$x" =~ ^"JJ:" ]] && continue
17 [[ "$x" =~ ^"Change-Id:" ]] && continue
18
19 [[ "$x" == '' ]] && [[ "$last" == '' ]] && continue
20
21 last="$x"
22 body+="$x\n"
23done
24
25body+="$CHGSTR\n"
26
27if [[ "$body" == "$CHGSTR\n" ]]; then
28 body="\n\n$body"
29fi
30
31t=$(mktemp)
32printf "$body" > "$t"
33mv "$t" "$1"
34
35exec nvim "$1"