#!/bin/bash
set -euo pipefail
. "$(dirname "$0")"/helpers.sh

new_tmp_dir
{
    jj git clone https://github.com/octocat/Hello-World
    cd Hello-World
    jj abandon --ignore-immutable test@origin
    jj bookmark forget test
    jj abandon --ignore-immutable octocat-patch-1@origin
    jj bookmark forget octocat-patch-1
}> /dev/null 2>&1

comment "We are in the octocat/Hello-World repo.
We have an empty working copy on top of master:"
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 "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"

comment "Add a bookmark so we can easily refer to this
commit:"
run_command "jj bookmark create goodbye"
run_command "jj log"

comment "Start working on a new change off of master:"
run_command "jj new master"
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:"
# 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"
