Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demos: automate running demos and update them #2231

Merged
merged 9 commits into from
Oct 4, 2023
44 changes: 44 additions & 0 deletions demos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Screenshots with demos and scripts to generate them

The `demo_*.sh` scripts in this directory demo
various features of `jj`.

The `run_scripts.sh` script can be used to:

- Run them inside a standardized environment instead of the user's local
environment.
- Generate SVG and PNG images for the scripts.

The PNG images in the repo may be slightly older, as they take up more space in
the repo.

The SVG images have human-readable diffs, but may look different on different
computers with different fonts installed.

## Running `run_scripts.sh`

This requires ImageMagick and `term-transcript-cli` to be installed. See
`run_scripts.sh`'s error messages for some more details. On Debian Linux, it
also seems helpful to `sudo apt install inkscape`; ImageMagick seems to use
either Inkscape itself or some dependency of it.

One way to make all the images and check the output is:

```shell
cd demos
./run_scripts.sh demo_*.sh |less
```

### A note on fonts

The exact PNG output depends on the fonts you have installed on your system.

The screenshots are usually generated on a Debian Linux system and use the "Fira
Code" font. It can be installed with `sudo apt install fonts-firacode`. It seems
to include all relevant Unicode symbols and be a little bolder and thus more
readable than the "Liberation Mono" font, which is used if Fira Code is not
installed. That font also works OK. See the CSS font specification in
`run_scripts.sh` for other fonts tried (especially when viewing SVGs on the
web). If none apply, the default `monospace` font will be used.

`convert -list Fonts` will list the fonts ImageMagick is aware of.
3 changes: 2 additions & 1 deletion demos/demo_git_compat.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -euo pipefail
. "$(dirname "$0")"/demo_helpers.sh
. "$(dirname "$0")"/helpers.sh

new_tmp_dir

Expand All @@ -10,6 +10,7 @@ run_command "cd Hello-World"

comment "Inspect it:"
run_command "jj log -r 'all()'"
blank
run_command "jj diff -r b1"

comment "The repo is backed by the actual Git repo:"
Expand Down
26 changes: 0 additions & 26 deletions demos/demo_helpers.sh

This file was deleted.

34 changes: 17 additions & 17 deletions demos/demo_juggle_conflicts.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#!/bin/bash
set -euo pipefail
. "$(dirname "$0")"/demo_helpers.sh
. "$(dirname "$0")"/helpers.sh

new_tmp_dir
jj init --config-toml ui.allow-init-native=true
echo "first" > file
jj branch create first
jj commit -m 'first'
echo "second" > file
jj branch create second
jj commit -m 'second'
echo "third" > file
jj branch create third
jj commit -m 'third'
(
jj init --config-toml ui.allow-init-native=true
echo "first" > file
jj branch create first
jj commit -m 'first'
echo "second" > file
jj branch create second
jj commit -m 'second'
echo "third" > file
jj branch create third
jj commit -m 'third'
) >/dev/null

comment "We are in a repo with three commits, all
editing the same line:"
Expand All @@ -26,13 +28,11 @@ comment "Let's reorder the second and third commits:"
run_command "jj rebase -s third -d first"
run_command "jj rebase -s second -d third"
run_command "jj log"
comment "The commit labeled \"third\" has a conflict,
as expected. What's more interesting is
that the top commit has no conflict! That's
because it has the changes from all three
commits applied to it."
comment "The commit labeled \"third\" has a conflict, as expected. What's more
interesting is that the top commit has no conflict! That's because it
has the changes from all three commits applied to it.

comment "Let's verify that by looking at its contents:"
Let's verify that by looking at its contents:"
run_command "jj co second"
run_command "cat file"

Expand Down
14 changes: 9 additions & 5 deletions demos/demo_operation_log.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash
set -euo pipefail
. "$(dirname "$0")"/demo_helpers.sh
. "$(dirname "$0")"/helpers.sh

new_tmp_dir
jj git clone https://github.com/octocat/Hello-World
cd Hello-World
{
jj git clone https://github.com/octocat/Hello-World
cd Hello-World
jj abandon octocat-patch-1
jj branch forget octocat-patch-1
} > /dev/null

comment "We are in the octocat/Hello-World repo.
The \"operation log\" shows the operations
Expand All @@ -27,10 +31,10 @@ 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 --color=always | head"
run_command_allow_broken_pipe "jj op log --limit 4"

comment "Let's undo that rebase operation:"
rebase_op=$(jj --color=never op log | grep '^◉ ' | sed '2q;d' | cut -b4-15)
rebase_op=$(jj --color=never op log --no-graph -T 'id.short(5)' --limit 1 --at-op @--)
run_command "jj undo $rebase_op"

comment "Note that only the rebase was undone, and the
Expand Down
27 changes: 17 additions & 10 deletions demos/demo_resolve_conflict.sh → demos/demo_resolve_conflicts.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
#!/bin/bash
set -euo pipefail
. "$(dirname "$0")"/demo_helpers.sh
. "$(dirname "$0")"/helpers.sh

new_tmp_dir
jj git clone https://github.com/octocat/Hello-World
cd Hello-World
{
jj git clone https://github.com/octocat/Hello-World
cd Hello-World
jj abandon test
jj branch forget test
} > /dev/null

comment "We are on the master branch of the
octocat/Hello-World repo:"
run_command "jj log -r 'all()'"
run_command "jj log"

comment "Let's make an edit that will conflict
when we rebase it:"
run_command "jj describe -m \"README: say which world\""
run_command "echo \"Hello Earth!\" > README"
run_command "jj diff"

# TODO(ilyagr): Get the real shortest prefix of the b1b commit using `jj log
# --no-graph` and the `.shortest()` template function.
#
# This could also be done in demo_git_compat.sh, but that might not be worth it.
comment "We're going to rebase it onto commit b1.
That commit looks like this:"
run_command "jj diff -r b1"

comment "Now rebase:"
run_command "jj rebase -d b1"

comment "Huh, that seemed to succeed. Let's take a
look at the repo:"
run_command "jj log -r 'all()'"
comment "That seemed to succeed but we are also told there is now a conflict.
Let's take a look at the repo:"
run_command "jj log"
run_command "jj status"

comment "As you can see, the rebased commit has a
conflict. The file in the working copy looks
like this:"
comment "Indeed, the rebased commit has a conflict. The conflicted file
in the working copy looks like this:"
run_command "cat README"

comment "Now we will resolve the conflict:"
Expand Down
34 changes: 21 additions & 13 deletions demos/demo_working_copy.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#!/bin/bash
set -euo pipefail
. "$(dirname "$0")"/demo_helpers.sh
. "$(dirname "$0")"/helpers.sh

new_tmp_dir
jj git clone https://github.com/octocat/Hello-World
cd Hello-World
{
jj git clone https://github.com/octocat/Hello-World
cd Hello-World
jj abandon test
jj branch forget test
jj abandon octocat-patch-1
jj branch forget octocat-patch-1
}> /dev/null

comment "We are in the octocat/Hello-World repo.
We have an empty working copy on top of master:"
run_command "jj status"
run_command "jj log"
run_command "jj status"

comment "Now make some changes in the working copy:"
run_command "echo \"Goodbye World!\" > README"
run_command "echo stuff > new-file"

comment "Our working copy's commit ID changed
because we made changes:"
comment "Because of these changes, our working copy is no longer marked as \"(empty)\".
Also, its commit ID (starting with a blue character) changed:"
run_command "jj status"
run_command "jj log"

comment "Add a branch so we can easily refer to this
commit:"
Expand All @@ -27,24 +32,27 @@ run_command "jj log"

comment "Start working on a new change off of master:"
run_command "jj co master"
run_command "jj log"

comment "Note that the working copy is now clean; the
comment "Note that we were told the working copy is now empty (AKA clean). The
\"goodbye\" change stayed in its own commit:"

run_command "jj log"
comment "Let's do a sanity check: 'jj status' should tell us that
the working copy is clean."
run_command "jj status"

comment "Modify a file in this new change:"
run_command "echo \"Hello everyone!\" > README"
run_command "jj status"

comment "The working copy is not special; we can, for
example, set the description of any commit.
First, set it on the working copy:"
run_command "jj describe -m everyone"
# The output with the description of the working copy slightly messes up the
# parallel between the working copy and another commit, so we redact it.
run_command_output_redacted "jj describe -m everyone"

comment "Now set it on the change we worked on before:"
run_command "jj describe goodbye -m goodbye"

comment "Inspect the result:"
run_command "jj log"

blank
Binary file modified demos/git_compat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions demos/git_compat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading