demos: add automated demo of cloning Git repo

The automation is mostly copied from
https://github.com/arxanas/git-branchless/tree/master/demos, so big
thanks to @arxanas for writing that!
This commit is contained in:
Martin von Zweigbergk 2021-10-22 09:24:02 -07:00
parent f35f2f0c97
commit 234cb15ff8
4 changed files with 136 additions and 1 deletions

View File

@ -23,11 +23,18 @@ well-known).
Features:
* **Compatible with Git**
Jujutsu has two backends. One of them is a Git backend (the other is a
native one). This lets you use Jujutsu as an alternative interface to Git.
The commits you create will look like regular Git commits. You can always
switch back to Git.
<details>
<summary>Demo</summary>
<a href="https://asciinema.org/a/3LEDzGEmEGnf0sTsvyHm41Jgu" target="_blank">
<img src="https://asciinema.org/a/3LEDzGEmEGnf0sTsvyHm41Jgu.svg" />
</a>
</details>
* **The working copy is automatically committed**

25
demos/demo_git_compat.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
set -euo pipefail
. "$(dirname "$0")"/demo_helpers.sh
parse_args "$@"
new_tmp_dir
run_demo '
expect_prompt
run_command "# Clone a Git repo:"
expect_prompt
run_command "jj git clone https://github.com/octocat/Hello-World"
expect_prompt
run_command "cd Hello-World"
expect_prompt
run_command "# Inspect it:"
expect_prompt
run_command "jj log"
expect_prompt
run_command "jj diff -r b1"
expect_prompt
run_command "# The repo is backed by the actual Git repo:"
expect_prompt
run_command "git --git-dir=.jj/store/git log --graph --all --decorate --oneline"
'

77
demos/demo_helpers.sh Normal file
View File

@ -0,0 +1,77 @@
#!/bin/bash
set -euo pipefail
BASE_DIR=$(realpath "$(dirname "$0")")
UPLOAD=false
PREVIEW=false
DEBUG=false
parse_args() {
for arg in "$@"; do
case "$arg" in
-h|--help)
echo 'Run a given demo.
Arguments:
--preview: Preview the asciicast.
--upload: Upload to asciinema (after previewing, if necessary).
--debug: Show the asciicast as it is being recorded. Note that what you see
will not be exactly the same as what is recorded.
'
exit
;;
--upload)
UPLOAD=true
;;
--preview)
PREVIEW=true
;;
--debug)
DEBUG=true
;;
*)
echo "Unrecognized argument: $arg"
exit 1
;;
esac
done
}
new_tmp_dir() {
local dirname
dirname=$(mktemp -d)
mkdir -p "$dirname"
cd "$dirname"
trap "rm -rf '$dirname'" EXIT
}
run_demo() {
local expect_script="$1"
expect_script=$(printf "source $BASE_DIR/demo_helpers.tcl
spawn asciinema rec -c \"PS1='$ ' bash --norc\"
expect_prompt
%s
quit_and_dump_asciicast_path
" "$expect_script")
if [[ "$DEBUG" == true ]]; then
echo "$expect_script" | /usr/bin/env expect
return
fi
echo "Recording demo (terminal size is $(tput cols)x$(tput lines))..."
if [[ "$PREVIEW" == 'false' ]]; then
echo '(Pass --preview to play the demo automatically once done)'
fi
local asciicast_path
asciicast_path=$(echo "$expect_script" | /usr/bin/env expect | tail -1)
echo "$asciicast_path"
if [[ "$PREVIEW" == 'true' ]]; then
asciinema play "$asciicast_path"
fi
if [[ "$UPLOAD" == 'true' ]]; then
if [[ "$PREVIEW" == 'true' ]] && ! confirm "Upload?"; then
return
fi
: asciinema upload "$asciicast_path"
fi
}

26
demos/demo_helpers.tcl Normal file
View File

@ -0,0 +1,26 @@
set send_human {0.1 0.3 1 0.05 1}
set timeout 2
proc expect_prompt {} {
expect "$ "
}
proc run_command {cmd} {
send -h "$cmd"
send "\r"
expect -timeout 1
}
proc quit_and_dump_asciicast_path {} {
set CTRLC \003
set CTRLD \004
set ESC \033
send $CTRLD
expect "asciinema: recording finished"
sleep 1
send $CTRLC
expect -re "asciicast saved to (.+)$ESC.*\r" {
send_user "$expect_out(1,string)\n"
}
}