| 1 | # shellcheck shell=bash |
| 2 | # Paths and fixtures come from the derivation environment. |
| 3 | # shellcheck disable=SC2154 |
| 4 | export HOME="$TMPDIR" XDG_STATE_HOME="$TMPDIR/state" TERM=xterm |
| 5 | export GIT_CONFIG_NOSYSTEM=1 |
| 6 | unset VISUAL || true |
| 7 | git config --global user.name valley-check |
| 8 | git config --global user.email valley-check@localhost |
| 9 | git config --global init.defaultBranch main |
| 10 | |
| 11 | # A project with an origin and one branch to review: two |
| 12 | # files, changed twice and once, far enough apart that the |
| 13 | # diff has two hunks in the first file and one in the second. |
| 14 | git init --quiet --bare "$TMPDIR/origin.git" |
| 15 | git init --quiet "$TMPDIR/work" |
| 16 | cd "$TMPDIR/work" || exit 1 |
| 17 | git remote add origin "$TMPDIR/origin.git" |
| 18 | seq 1 20 | sed 's/^/alpha /' > alpha.md |
| 19 | seq 1 10 | sed 's/^/beta /' > beta.md |
| 20 | git add -A |
| 21 | git commit --quiet -m seed |
| 22 | git push --quiet -u origin main |
| 23 | git checkout --quiet -b scratch |
| 24 | sed -i -e '3s/.*/alpha 3 changed/' -e '15s/.*/alpha 15 changed/' alpha.md |
| 25 | sed -i -e '5s/.*/beta 5 changed/' beta.md |
| 26 | git commit --quiet -am "touch both files" |
| 27 | git push --quiet origin scratch |
| 28 | git checkout --quiet main |
| 29 | git fetch --quiet origin |
| 30 | |
| 31 | # A pager filter that restructures the diff, as delta's |
| 32 | # rendering does: if v were handed what less displays, every |
| 33 | # anchor below would be wrong. |
| 34 | git config --global pager.diff "sed -e 's/^/| /'" |
| 35 | export EDITOR="$reviewer" |
| 36 | mkdir -p "$XDG_STATE_HOME" |
| 37 | |
| 38 | # wait_for <log> <pattern>: wait until <log> shows <pattern>, and fail |
| 39 | # after a minute. A review reads every key from the one terminal, so a |
| 40 | # verdict typed before the prompt that takes it would go to whatever held |
| 41 | # the terminal then, such as less. Each log waited on here is written by |
| 42 | # one review only, so no earlier review's output can match. |
| 43 | wait_for() { |
| 44 | local i=0 |
| 45 | until grep -q -- "$2" "$1" 2> /dev/null; do |
| 46 | if [ "$i" -ge 600 ]; then |
| 47 | printf 'review-notes: %s never showed %s\n' "$1" "$2" >&2 |
| 48 | return 1 |
| 49 | fi |
| 50 | sleep 0.1 |
| 51 | i=$((i + 1)) |
| 52 | done |
| 53 | } |
| 54 | |
| 55 | # answer_after <log> <prompt> <command> <answers>: wait until the review |
| 56 | # writing to <log> has asked <prompt>, run <command>, then answer. A page |
| 57 | # is shown before its prompt, so the command runs after the page is shown |
| 58 | # and before the answer. |
| 59 | answer_after() { |
| 60 | wait_for "$1" "$2" |
| 61 | eval "$3" |
| 62 | printf '%b' "$4" |
| 63 | } |
| 64 | |
| 65 | # v opens the editor, RETURN dismisses less's LESSOPEN |
| 66 | # warning, q leaves the pager, s is the verdict. The verdict |
| 67 | # waits for its prompt, and the keys stay open until the |
| 68 | # notes are printed. |
| 69 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 70 | { |
| 71 | printf 'v\nq' |
| 72 | answer_after session.log '\]kip: ' : 's\n' |
| 73 | wait_for session.log '5 note(s) on scratch' |
| 74 | } | script -qec "valley review scratch" /dev/null > session.log 2>&1 |
| 75 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' session.log > plain.log |
| 76 | |
| 77 | # The anchors, exactly: above every file, on a file header |
| 78 | # above the first hunk, mid-hunk, in a second hunk whose |
| 79 | # numbering starts elsewhere, and in a second file. |
| 80 | diff -u - "$XDG_STATE_HOME/valley/notes/scratch.md" <<EOF |
| 81 | ## scratch at $(git rev-parse --short origin/scratch) |
| 82 | |
| 83 | (unanchored): a note above every file |
| 84 | alpha.md: alpha reads like two files |
| 85 | alpha.md:3: why is 3 changed at all? |
| 86 | alpha.md:13: and this hunk is fine |
| 87 | beta.md:5: beta wants the same treatment |
| 88 | |
| 89 | EOF |
| 90 | |
| 91 | # The editor was given the buffer valley wrote, not the |
| 92 | # rendering less displayed, and given a line to open at. |
| 93 | grep -qE 'editor got: \+[0-9]+ .*/review\.diff$' \ |
| 94 | "$XDG_STATE_HOME/editor.log" |
| 95 | # The filter did run: what the pager showed was its output. |
| 96 | grep -q '^| @@ ' plain.log |
| 97 | # The line the reviewer edited instead of inserting is gone, |
| 98 | # and said so. |
| 99 | grep -q 'changed or deleted diff line(s) ignored' plain.log |
| 100 | if grep -q 'alpha SEVENTEEN' "$XDG_STATE_HOME/valley/notes/scratch.md"; then exit 1; fi |
| 101 | |
| 102 | # The verdict is unchanged, and the notes come after it. |
| 103 | grep -q 'skipped scratch; nothing done' plain.log |
| 104 | verdict="$(grep -n 'skipped scratch' plain.log | cut -d: -f1)" |
| 105 | notes="$(grep -n '5 note(s) on scratch' plain.log | cut -d: -f1)" |
| 106 | [ "$verdict" -lt "$notes" ] |
| 107 | |
| 108 | # Piped, review is what it always was: the diff on stdout, |
| 109 | # the verdict from stdin, and no notes to take. |
| 110 | printf 's\n' | valley review scratch > piped.log |
| 111 | grep -q '^diff --git a/alpha.md b/alpha.md$' piped.log |
| 112 | grep -q 'skipped scratch; nothing done' piped.log |
| 113 | if grep -q 'note(s) on scratch' piped.log; then exit 1; fi |
| 114 | |
| 115 | # The pending list titles each branch by the subject of its first own |
| 116 | # commit, on the line under its name, and cuts a long one short with … to |
| 117 | # fit 80 columns when stdout is no terminal. Nothing it prints there is an |
| 118 | # escape code. |
| 119 | valley pending > pending.log |
| 120 | grep -A1 '^scratch ' pending.log | grep -q '^ touch both files$' |
| 121 | git checkout --quiet -b longsubject origin/main |
| 122 | git commit --quiet --allow-empty -m "$(printf 'x%.0s' $(seq 1 80))" |
| 123 | git push --quiet origin longsubject |
| 124 | git checkout --quiet main |
| 125 | valley pending > pending.log |
| 126 | grep -A1 '^longsubject ' pending.log | grep -qE '^ x{77}…$' |
| 127 | if grep -q $'\x1b' pending.log; then exit 1; fi |
| 128 | |
| 129 | # On a terminal, pending fits the terminal's width and sets each name in |
| 130 | # bold. With NO_COLOR set, it prints no escape code. |
| 131 | script -qec "stty cols 100; valley pending" /dev/null < /dev/null > tty.log 2>&1 |
| 132 | grep -q $'^\x1b\\[1mlongsubject\x1b\\[0m ' tty.log |
| 133 | grep -qE $'^ x{80}\r?$' tty.log |
| 134 | NO_COLOR=1 script -qec "stty cols 100; valley pending" /dev/null < /dev/null > tty.log 2>&1 |
| 135 | grep -q '^longsubject ' tty.log |
| 136 | if grep -q $'\x1b' tty.log; then exit 1; fi |
| 137 | |
| 138 | # ---------------------------------------------------------------------- |
| 139 | # A stack: a branch, then two changes with records, each on the one |
| 140 | # below, in a project whose floor requires nothing, so approving files a |
| 141 | # request with no evidence. Its origin logs every push it receives, which |
| 142 | # is how "publishes nothing" is read. |
| 143 | stack="$TMPDIR/stack.git" |
| 144 | pushlog="$TMPDIR/pushlog" |
| 145 | git init --quiet --bare "$stack" |
| 146 | cat > "$stack/hooks/pre-receive" << EOF |
| 147 | #!/bin/sh |
| 148 | echo '--- push' >> $pushlog |
| 149 | cat >> $pushlog |
| 150 | EOF |
| 151 | chmod +x "$stack/hooks/pre-receive" |
| 152 | git init --quiet "$TMPDIR/stackwork" |
| 153 | cd "$TMPDIR/stackwork" || exit 1 |
| 154 | git remote add origin "$stack" |
| 155 | git config valley.principal operator |
| 156 | mkdir -p policy/instance |
| 157 | cat > policy/instance/floor.cue << 'EOF' |
| 158 | package verification |
| 159 | |
| 160 | floor: { |
| 161 | classes: everything: { |
| 162 | paths: "**": true |
| 163 | requires: {} |
| 164 | } |
| 165 | unclassified: {} |
| 166 | } |
| 167 | EOF |
| 168 | git add -A |
| 169 | git commit --quiet -m seed |
| 170 | git push --quiet -u origin main |
| 171 | from=main |
| 172 | for layer in one two three; do |
| 173 | git checkout --quiet -b "$layer" "$from" |
| 174 | echo "layer $layer" > "$layer.md" |
| 175 | git add -A |
| 176 | git commit --quiet -m "layer $layer" |
| 177 | git push --quiet origin "$layer" |
| 178 | from="$layer" |
| 179 | done |
| 180 | two="$(git rev-parse two)" three="$(git rev-parse three)" |
| 181 | q=qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq p=pppppppppppppppppppppppppppppppp |
| 182 | valley ready --change "$q" two > /dev/null |
| 183 | valley ready --change "$p" three > /dev/null |
| 184 | git checkout --quiet main |
| 185 | requests="refs/the-valley/integration-requests/main" |
| 186 | |
| 187 | # s at the first layer, on a terminal, with a note written in its diff: |
| 188 | # the note is kept under the first layer's branch and printed at the end, |
| 189 | # and nothing is published. |
| 190 | cat > "$TMPDIR/stack-editor" << 'EOF' |
| 191 | #!/bin/sh |
| 192 | f="$1" |
| 193 | case "$1" in +*) f="$2" ;; esac |
| 194 | sed -i '/^+layer one$/a one wants a second line' "$f" |
| 195 | EOF |
| 196 | chmod +x "$TMPDIR/stack-editor" |
| 197 | : > "$pushlog" |
| 198 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 199 | { |
| 200 | printf 'v\nq' |
| 201 | answer_after stack-tty.log 'one, 1 of 3: \[n\]ext layer, .*\[s\]top? ' : 's\n' |
| 202 | wait_for stack-tty.log '1 note(s) on one' |
| 203 | } | EDITOR="$TMPDIR/stack-editor" script -qec "valley review pppp" /dev/null > stack-tty.log 2>&1 |
| 204 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' stack-tty.log > stack-plain.log |
| 205 | grep -q 'pppp is a stack of 3 changes; reviewing from the bottom, each against the one below it:$' stack-plain.log |
| 206 | grep -qxF 'read each layer and go on with [n]; approving pppp at the top lands all 3. [a] on a lower layer lands it and the layers under it, and ends the review.' stack-plain.log |
| 207 | grep -q '| change 1 of 3: one on main$' stack-plain.log |
| 208 | grep -qF 'one, 1 of 3: [n]ext layer, [a]pprove one alone, [v]iew full diff, [s]top? ' stack-plain.log |
| 209 | grep -q 'stopped reviewing pppp at change 1 of 3, one; nothing done' stack-plain.log |
| 210 | if grep -q 'change 2 of 3' stack-plain.log; then exit 1; fi |
| 211 | grep -qx 'one.md:1: one wants a second line' "$XDG_STATE_HOME/valley/notes/one.md" |
| 212 | grep -q '1 note(s) on one, appended to .*/valley/notes/one.md:' stack-plain.log |
| 213 | grep -q '^ one.md:1: one wants a second line$' stack-plain.log |
| 214 | [ ! -e "$XDG_STATE_HOME/valley/notes/two.md" ] |
| 215 | [ ! -s "$pushlog" ] |
| 216 | |
| 217 | # n, n, a: the layers are paged bottom up, each diff holds only its own |
| 218 | # layer's file, and the top's request is filed at the top's head. Each |
| 219 | # prompt names its layer and place, and what approving there lands. |
| 220 | : > "$pushlog" |
| 221 | printf 'n\nn\na\n' | valley review pppp > stack.out 2> stack.err |
| 222 | grep -q '^ 1\. one (branch): layer one$' stack.out |
| 223 | grep -q '^ 2\. qqqq (ready): layer two$' stack.out |
| 224 | grep -q '^ 3\. pppp (ready): layer three$' stack.out |
| 225 | grep -qxF 'read each layer and go on with [n]; approving pppp at the top lands all 3. [a] on a lower layer lands it and the layers under it, and ends the review.' stack.out |
| 226 | grep -qF 'one, 1 of 3: [n]ext layer, [a]pprove one alone, [v]iew full diff, [s]top? ' stack.out |
| 227 | grep -qF 'qqqq, 2 of 3: [n]ext layer, [a]pprove one and qqqq, [v]iew full diff, [s]top? ' stack.out |
| 228 | grep -qF '[a]pprove all 3 [v]iew diff [r]eject pppp [s]top: ' stack.out |
| 229 | # Piped, each page's first line follows the prompt before it. |
| 230 | [ "$(grep -o 'change [0-9] of 3: [a-z]* on [a-z]*$' stack.out)" = "$(printf '%s\n' \ |
| 231 | 'change 1 of 3: one on main' 'change 2 of 3: qqqq on one' 'change 3 of 3: pppp on qqqq')" ] |
| 232 | for n in 1 2 3; do |
| 233 | awk -v n="$n" '/change [0-9] of 3: /{ on = index($0, "change " n " of 3: ") > 0 } on' stack.out > "page$n" |
| 234 | done |
| 235 | [ "$(grep '^diff --git' page1)" = 'diff --git a/one.md b/one.md' ] |
| 236 | [ "$(grep '^diff --git' page2)" = 'diff --git a/two.md b/two.md' ] |
| 237 | [ "$(grep '^diff --git' page3)" = 'diff --git a/three.md b/three.md' ] |
| 238 | [ "$(git -C "$stack" rev-parse "$requests/c-$p")" = "$three" ] |
| 239 | if git -C "$stack" rev-parse --verify --quiet "$requests/c-$q" > /dev/null; then exit 1; fi |
| 240 | git -C "$stack" update-ref -d "$requests/c-$p" |
| 241 | |
| 242 | # a at the second layer files the second layer's request at its head, and |
| 243 | # nothing for the top, whose review never starts: neither its page nor its |
| 244 | # prompt is shown. |
| 245 | : > "$pushlog" |
| 246 | printf 'n\na\n' | valley review pppp > stack-two.out 2> stack-two.err |
| 247 | grep -qF 'qqqq, 2 of 3: [n]ext layer, [a]pprove one and qqqq, [v]iew full diff, [s]top? ' stack-two.out |
| 248 | [ "$(git -C "$stack" rev-parse "$requests/c-$q")" = "$two" ] |
| 249 | if git -C "$stack" rev-parse --verify --quiet "$requests/c-$p" > /dev/null; then exit 1; fi |
| 250 | grep -q "c-$q" "$pushlog" |
| 251 | if grep -q "c-$p" "$pushlog"; then exit 1; fi |
| 252 | if grep -q 'change 3 of 3' stack-two.out; then exit 1; fi |
| 253 | if grep -q '3 of 3: ' stack-two.out; then exit 1; fi |
| 254 | |
| 255 | # A draft in the middle is named in the warning before anything is paged. |
| 256 | # It is readied again after, since review offers no [a]pprove at or above |
| 257 | # a draft, and the stacks below approve above it. |
| 258 | valley unready qqqq > /dev/null 2>&1 |
| 259 | printf 's\n' | valley review pppp > stack-draft.out 2>&1 |
| 260 | grep -q '^warning: qqqq, change 2 of 3, is a draft\. The integrator refuses to land it or anything above it (refused-not-ready)\.$' stack-draft.out |
| 261 | valley ready --change "$q" two > /dev/null |
| 262 | |
| 263 | # A change with no stack under it pages and prompts as it always has. |
| 264 | printf 's\n' | valley review one > stack-one.out 2>&1 |
| 265 | grep -q '^branch one, log against origin/main:$' stack-one.out |
| 266 | grep -q '^\[a\]pprove \[v\]iew diff \[r\]eject \[s\]kip: skipped one; nothing done$' stack-one.out |
| 267 | if grep -q 'stack of\|change 1 of' stack-one.out; then exit 1; fi |
| 268 | |
| 269 | seed="$(git rev-parse main)" onehead="$(git rev-parse one)" |
| 270 | |
| 271 | # [a]pprove at the bottom, on a plain branch under the top, files that |
| 272 | # branch's head under its own request name, and nothing for the top. |
| 273 | : > "$pushlog" |
| 274 | printf 'a\n' | valley review pppp > stack-a-one.out 2>&1 |
| 275 | [ "$(git -C "$stack" rev-parse "$requests/one")" = "$onehead" ] |
| 276 | grep -q "$requests/one" "$pushlog" |
| 277 | if grep -q "c-$p" "$pushlog"; then exit 1; fi |
| 278 | |
| 279 | # Once a page is shown, the head approved is the head shown. When the |
| 280 | # branch moves on origin, and is fetched, after the page is shown and |
| 281 | # before the answer, approving refuses, names both heads, and publishes |
| 282 | # nothing: for a plain branch under the top, for a plain branch at the top |
| 283 | # of a stack, and for a plain branch alone. The request each would file is |
| 284 | # absent first, so a filing would push. |
| 285 | git -C "$stack" update-ref -d "$requests/one" |
| 286 | : > "$pushlog" |
| 287 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 288 | answer_after moved-one.out 'one, 1 of 3: \[n\]ext' "git -C '$stack' update-ref refs/heads/one $seed; git fetch -q origin" 'a\ns\n' \ |
| 289 | | valley review pppp > moved-one.out 2>&1 |
| 290 | grep -q "not approved · origin/one moved from ${onehead:0:7}[0-9a-f]*, the head shown, to ${seed:0:7}" moved-one.out |
| 291 | [ ! -s "$pushlog" ] |
| 292 | if git -C "$stack" rev-parse --verify --quiet "$requests/one" > /dev/null; then exit 1; fi |
| 293 | git -C "$stack" update-ref refs/heads/one "$onehead" |
| 294 | git fetch -q origin |
| 295 | |
| 296 | git checkout --quiet -b four three |
| 297 | echo "layer four" > four.md |
| 298 | git add four.md |
| 299 | git commit --quiet -m "layer four" |
| 300 | git push --quiet origin four |
| 301 | fourhead="$(git rev-parse four)" |
| 302 | git checkout --quiet -b solo main |
| 303 | echo "solo" > solo.md |
| 304 | git add solo.md |
| 305 | git commit --quiet -m "solo" |
| 306 | git push --quiet origin solo |
| 307 | solohead="$(git rev-parse solo)" |
| 308 | git checkout --quiet main |
| 309 | |
| 310 | : > "$pushlog" |
| 311 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 312 | { |
| 313 | printf 'n\nn\nn\n' |
| 314 | answer_after moved-four.out '\[a\]pprove all 4 \[v\]iew diff \[r\]eject four \[s\]top:' "git -C '$stack' update-ref refs/heads/four $seed; git fetch -q origin" 'a\ns\n' |
| 315 | } | valley review four > moved-four.out 2>&1 |
| 316 | grep -q '^four is a stack of 4 changes' moved-four.out |
| 317 | # From the third layer up, a lower layer's prompt counts what approving |
| 318 | # there lands. The top's prompt names the top, and says approving it |
| 319 | # lands all 4. |
| 320 | grep -qF 'pppp, 3 of 4: [n]ext layer, [a]pprove the 3 up to pppp, [v]iew full diff, [s]top? ' moved-four.out |
| 321 | grep -qF '[a]pprove all 4 [v]iew diff [r]eject four [s]top: ' moved-four.out |
| 322 | grep -q "not approved · origin/four moved from ${fourhead:0:7}[0-9a-f]*, the head shown, to ${seed:0:7}" moved-four.out |
| 323 | grep -q 'stopped reviewing four at change 4 of 4; nothing done' moved-four.out |
| 324 | [ ! -s "$pushlog" ] |
| 325 | if git -C "$stack" rev-parse --verify --quiet "$requests/four" > /dev/null; then exit 1; fi |
| 326 | |
| 327 | : > "$pushlog" |
| 328 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 329 | answer_after moved-solo.out '^\[a\]pprove \[v\]iew diff' "git -C '$stack' update-ref refs/heads/solo $seed; git fetch -q origin" 'a\ns\n' \ |
| 330 | | valley review solo > moved-solo.out 2>&1 |
| 331 | grep -q '^branch solo, log against origin/main:$' moved-solo.out |
| 332 | grep -q "not approved · origin/solo moved from ${solohead:0:7}[0-9a-f]*, the head shown, to ${seed:0:7}" moved-solo.out |
| 333 | [ ! -s "$pushlog" ] |
| 334 | if git -C "$stack" rev-parse --verify --quiet "$requests/solo" > /dev/null; then exit 1; fi |
| 335 | |
| 336 | # ---------------------------------------------------------------------- |
| 337 | # A stack whose bottom does not fast-forward from main. The top gains a |
| 338 | # second version, and main moves on under the stack. |
| 339 | git checkout --quiet three |
| 340 | echo "layer three, again" >> three.md |
| 341 | git commit --quiet -am "layer three again" |
| 342 | git push --quiet origin three |
| 343 | threeagain="$(git rev-parse three)" |
| 344 | valley ready --change "$p" three > /dev/null |
| 345 | git checkout --quiet main |
| 346 | echo "main moves on" > moved.md |
| 347 | git add moved.md |
| 348 | git commit --quiet -m "main moves on" |
| 349 | git push --quiet origin main |
| 350 | |
| 351 | # Approving the top is refused before any check runs, at its active head |
| 352 | # and at an earlier version's head, and the refusal names the rebase that |
| 353 | # fixes it. Nothing is published. |
| 354 | : > "$pushlog" |
| 355 | for head in "$threeagain" "$three"; do |
| 356 | if valley approve --head "$head" pppp > stale-approve.out 2>&1; then exit 1; fi |
| 357 | grep -qF 'not approved · stack is behind main (includes qqqq)' stale-approve.out |
| 358 | grep -qx ' run: valley rebase pppp' stale-approve.out |
| 359 | if grep -q 'requires no check' stale-approve.out; then exit 1; fi |
| 360 | done |
| 361 | [ ! -s "$pushlog" ] |
| 362 | # The bottom layer has no change under it, so it is approved as it is. |
| 363 | valley approve one > stale-bottom.out 2>&1 |
| 364 | grep -qx '✓ one approved · no checks required · landing on main' stale-bottom.out |
| 365 | [ "$(git -C "$stack" rev-parse "$requests/one")" = "$onehead" ] |
| 366 | git -C "$stack" update-ref -d "$requests/one" |
| 367 | |
| 368 | # review asks, before any layer is paged, whether to rebase the stack. |
| 369 | # [s]top ends it there, and nothing is done. |
| 370 | : > "$pushlog" |
| 371 | printf 's\n' | valley review pppp > stale-stop.out 2>&1 |
| 372 | grep -qxF 'pppp · stack of 3 · behind main' stale-stop.out |
| 373 | grep -qF '[b]ase onto main [v]iew diff [s]kip: stopped reviewing pppp before its first layer; nothing done' stale-stop.out |
| 374 | if grep -q 'change 1 of 3' stale-stop.out; then exit 1; fi |
| 375 | [ ! -s "$pushlog" ] |
| 376 | |
| 377 | # [b]ase rebases the whole stack. The review then lists the stack again |
| 378 | # and pages the rebased layers, and [a]pprove at the top files the |
| 379 | # request at the top's rebased head. |
| 380 | printf 'b\nn\nn\na\n' | valley review pppp > stale-review.out 2>&1 |
| 381 | grep -qF '[b]ase onto main [v]iew diff [s]kip: ' stale-review.out |
| 382 | grep -qF 'the stack under pppp, bottom first:' stale-review.out |
| 383 | git fetch --quiet origin |
| 384 | newone="$(git rev-parse origin/one)" newthree="$(git rev-parse origin/three)" |
| 385 | [ "$newone" != "$onehead" ] |
| 386 | git merge-base --is-ancestor origin/main "$newone" |
| 387 | awk '/change 1 of 3: /{ on = 1 } /change 2 of 3: /{ on = 0 } on' stale-review.out > stale-page1 |
| 388 | grep -q "^$(git rev-parse --short "$newone") layer one$" stale-page1 |
| 389 | if grep -q "$(git rev-parse --short "$onehead")" stale-page1; then exit 1; fi |
| 390 | grep -qF '[a]pprove all 3 [v]iew diff [r]eject pppp [s]top: ' stale-review.out |
| 391 | [ "$(git -C "$stack" rev-parse "$requests/c-$p")" = "$newthree" ] |
| 392 | # qqqq's v1 was approved earlier, and the rebase gave it v2 with the same |
| 393 | # file delta, so its layer is printed as a clean restack of v1, and not |
| 394 | # paged. pppp has no approved version, so its layer is paged in full. |
| 395 | grep -qx "qqqq v2 at [0-9a-f]*: clean restack of approved v1 at $(git rev-parse --short "$two")\." stale-review.out |
| 396 | awk '/change 2 of 3: /{ on = 1 } /change 3 of 3: /{ on = 0 } on' stale-review.out > stale-page2 |
| 397 | if grep -q '^diff --git' stale-page2; then exit 1; fi |
| 398 | awk '/change 3 of 3: /{ on = 1 } on' stale-review.out > stale-page3 |
| 399 | [ "$(grep '^diff --git' stale-page3)" = 'diff --git a/three.md b/three.md' ] |
| 400 | |
| 401 | # ---------------------------------------------------------------------- |
| 402 | # A note taken on a changed comparison. v1 of a change is approved, and |
| 403 | # v2 edits line 9 of its file, so review pages v2 as changed since v1. |
| 404 | # range-diff's hunks carry no line numbers, so the page ends with v2's |
| 405 | # own diff of the file, and the note written beside the edited line there |
| 406 | # keeps its file and line. |
| 407 | git checkout --quiet -b edited main |
| 408 | seq 1 12 | sed 's/^/line /' > lines.md |
| 409 | git add lines.md |
| 410 | git commit --quiet -m "add the lines" |
| 411 | git push --quiet origin edited |
| 412 | m=mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm |
| 413 | valley ready --change "$m" edited > /dev/null |
| 414 | git -C "$stack" update-ref "$requests/c-$m" "$(git rev-parse edited)" |
| 415 | sed -i 's/^line 9$/line 9 edited/' lines.md |
| 416 | git commit --quiet -am "edit line 9" |
| 417 | git push --quiet origin edited |
| 418 | valley ready --change "$m" edited > /dev/null |
| 419 | git checkout --quiet main |
| 420 | cat > "$TMPDIR/changed-editor" << 'EOF' |
| 421 | #!/bin/sh |
| 422 | f="$1" |
| 423 | case "$1" in +*) f="$2" ;; esac |
| 424 | sed -i '/^+line 9 edited$/a why edit line 9?' "$f" |
| 425 | EOF |
| 426 | chmod +x "$TMPDIR/changed-editor" |
| 427 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 428 | { |
| 429 | printf 'v\nq' |
| 430 | answer_after changed-tty.log '\]kip: ' : 's\n' |
| 431 | wait_for changed-tty.log '1 note(s) on edited' |
| 432 | } | EDITOR="$TMPDIR/changed-editor" script -qec "valley review mmmm" /dev/null > changed-tty.log 2>&1 |
| 433 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' changed-tty.log > changed-plain.log |
| 434 | grep -q "| mmmm v2 at [0-9a-f]*: changed since approved v1 at " changed-plain.log |
| 435 | grep -qx 'lines.md:9: why edit line 9?' "$XDG_STATE_HOME/valley/notes/edited.md" |
| 436 | grep -q '^ lines.md:9: why edit line 9?$' changed-plain.log |
| 437 | |
| 438 | touch "$out" |