Skip to content

Commit

Permalink
demos: allow broken pipe when doing jj | head
Browse files Browse the repository at this point in the history
`jj | head` exits with non-zero code since `head` breaks the pipe.

Previosly, this caused the script to stop since it's run with
`set -o pipefail`.
  • Loading branch information
ilyagr committed Sep 10, 2023
1 parent 288e295 commit 9be8e4e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion demos/demo_operation_log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ comment "The repo now looks like this:"
run_command "jj log"
comment "The most recent portion of the operation log
is:"
run_command "jj op log | head"
run_command_allow_broken_pipe "jj op log | head"

comment "Let's undo that rebase operation:"
rebase_op=$(jj debug operation --display id --at-op @-- | head --bytes 8)
Expand Down
15 changes: 15 additions & 0 deletions demos/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ run_command() {
eval "$@"
}

run_command_allow_broken_pipe() {
run_command "$@" || {
EXITCODE="$?"
case $EXITCODE in
3)
# `jj` exits with error coded 3 on broken pipe,
# which can happen simply because of running
# `jj|head`.
return 0;;
*)
return $EXITCODE;;
esac
}
}

blank() {
echo ""
}
Expand Down

0 comments on commit 9be8e4e

Please sign in to comment.