#!/usr/bin/env atf-sh atf_init_test_cases() { atf_add_test_case no_args atf_add_test_case unknown_command atf_add_test_case init_no_args atf_add_test_case init_too_many_args atf_add_test_case init_clones_default atf_add_test_case init_single_branch atf_add_test_case init_removes_origin atf_add_test_case init_dst_exists atf_add_test_case new_no_args atf_add_test_case new_too_many_args atf_add_test_case new_no_cells_dir atf_add_test_case new_missing_bare atf_add_test_case new_creates_cell atf_add_test_case new_runs_from_subdir atf_add_test_case new_sets_origin_remote atf_add_test_case new_checks_out_bare_content atf_add_test_case new_duplicate_fails atf_add_test_case new_branch_exists atf_add_test_case resume_no_args atf_add_test_case resume_too_many_args atf_add_test_case resume_no_cells_dir atf_add_test_case resume_missing_bare atf_add_test_case resume_no_branch atf_add_test_case resume_dest_exists atf_add_test_case resume_checks_out_branch atf_add_test_case resume_tracks_branch atf_add_test_case workflow } setup() { cat > jjconfig.toml <<-EOF [user] name = "Test" email = "test@example.com" EOF export JJ_CONFIG="${PWD}/jjconfig.toml" CELL="$(atf_get_srcdir)/cell" } # Create a plain git repo at ${PWD}/src with one commit on branch main, # to stand in for the repo a cell is seeded from via its .git. mk_src() { git init -q -b main src echo "hello" > src/file.txt git -C src add file.txt git -C src -c user.name=t -c user.email=t@t commit -qm init } # Create a .cell directory at ${PWD}/.cell holding a default.git # bare repo with one commit on branch main. mk_cells() { mkdir .cell git init -q --bare -b main .cell/default.git git clone -q .cell/default.git seed 2>/dev/null echo "hello" > seed/file.txt git -C seed add file.txt git -C seed -c user.name=t -c user.email=t@t commit -qm init git -C seed push -q origin main rm -rf seed } # Push a branch to .cell/default.git carrying an extra file # work.txt, standing in for a cell that pushed work and was removed. mk_branch() { local name="${1}" git clone -q .cell/default.git seed 2>/dev/null git -C seed checkout -q -b "${name}" echo "resumed" > seed/work.txt git -C seed add work.txt git -C seed -c user.name=t -c user.email=t@t commit -qm work git -C seed push -q origin "${name}" rm -rf seed } atf_test_case no_args no_args_head() { atf_set "descr" "cell with no arguments prints usage and exits 64" } no_args_body() { setup atf_check -s exit:64 -e match:"usage" "${CELL}" } atf_test_case unknown_command unknown_command_head() { atf_set "descr" "cell with an unknown subcommand prints usage and exits 64" } unknown_command_body() { setup atf_check -s exit:64 -e match:"usage" "${CELL}" bogus } atf_test_case init_no_args init_no_args_head() { atf_set "descr" "cell init with no source prints usage and exits 64" } init_no_args_body() { setup atf_check -s exit:64 -e match:"usage" "${CELL}" init } atf_test_case init_too_many_args init_too_many_args_head() { atf_set "descr" "cell init with extra arguments prints usage and exits 64" } init_too_many_args_body() { setup atf_check -s exit:64 -e match:"usage" "${CELL}" init a b } atf_test_case init_clones_default init_clones_default_head() { atf_set "descr" "cell init bare-clones the source into .cell/default.git" } init_clones_default_body() { setup mk_src atf_check -s exit:0 -e ignore "${CELL}" init src/.git atf_check test -d .cell/default.git atf_check -o inline:"true\n" \ git -C .cell/default.git rev-parse --is-bare-repository } atf_test_case init_single_branch init_single_branch_head() { atf_set "descr" "cell init clones only the source default branch" } init_single_branch_body() { setup mk_src git -C src branch feature-a git -C src branch feature-b atf_check -s exit:0 -e ignore "${CELL}" init src/.git atf_check -o inline:"main\n" \ git -C .cell/default.git for-each-ref --format='%(refname:short)' } atf_test_case init_removes_origin init_removes_origin_head() { atf_set "descr" "cell init leaves the clone with no origin remote" } init_removes_origin_body() { setup mk_src atf_check -s exit:0 -e ignore "${CELL}" init src/.git atf_check -o empty git -C .cell/default.git remote } atf_test_case init_dst_exists init_dst_exists_head() { atf_set "descr" "cell init fails when the destination already exists" } init_dst_exists_body() { setup mk_src mkdir -p .cell/default.git atf_check -s exit:1 -e match:"already exists" "${CELL}" init src/.git } atf_test_case new_no_args new_no_args_head() { atf_set "descr" "cell new with no name prints usage and exits 64" } new_no_args_body() { setup atf_check -s exit:64 -e match:"usage" "${CELL}" new } atf_test_case new_too_many_args new_too_many_args_head() { atf_set "descr" "cell new with extra arguments prints usage and exits 64" } new_too_many_args_body() { setup atf_check -s exit:64 -e match:"usage" "${CELL}" new a b } atf_test_case new_no_cells_dir new_no_cells_dir_head() { atf_set "descr" "cell new fails when no .cell directory is found" } new_no_cells_dir_body() { setup atf_check -s exit:1 -e match:".cell directory" "${CELL}" new q1 } atf_test_case new_missing_bare new_missing_bare_head() { atf_set "descr" "cell new fails when .cell holds no default.git" } new_missing_bare_body() { setup mkdir .cell atf_check -s exit:1 -e match:"default.git" "${CELL}" new q1 } atf_test_case new_creates_cell new_creates_cell_head() { atf_set "descr" "cell new clones default.git into a colocated jj repo" } new_creates_cell_body() { setup mk_cells atf_check -s exit:0 -e ignore "${CELL}" new q1 atf_check test -d .cell/q1.jj/.jj atf_check test -d .cell/q1.jj/.git } atf_test_case new_runs_from_subdir new_runs_from_subdir_head() { atf_set "descr" "cell new finds .cell from a nested subdirectory" } new_runs_from_subdir_body() { setup mk_cells mkdir -p default.jj/src atf_check -s exit:0 -e ignore \ sh -c 'cd default.jj/src && "$1" new q1' _ "${CELL}" atf_check test -d .cell/q1.jj/.jj } atf_test_case new_sets_origin_remote new_sets_origin_remote_head() { atf_set "descr" "the cell origin points at the .cell default.git" } new_sets_origin_remote_body() { setup mk_cells atf_check -s exit:0 -e ignore "${CELL}" new q1 atf_check -o match:"^origin ${PWD}/.cell/default.git" -e ignore \ jj -R .cell/q1.jj git remote list } atf_test_case new_checks_out_bare_content new_checks_out_bare_content_head() { atf_set "descr" "the cell working copy holds the bare repo content" } new_checks_out_bare_content_body() { setup mk_cells atf_check -s exit:0 -e ignore "${CELL}" new q1 atf_check -o inline:"hello\n" cat .cell/q1.jj/file.txt } atf_test_case new_duplicate_fails new_duplicate_fails_head() { atf_set "descr" "cell new fails when the cell already exists" } new_duplicate_fails_body() { setup mk_cells atf_check -s exit:0 -e ignore "${CELL}" new q1 atf_check -s exit:1 -e match:"already exists" "${CELL}" new q1 } atf_test_case new_branch_exists new_branch_exists_head() { atf_set "descr" "cell new fails when default.git already has the branch" } new_branch_exists_body() { setup mk_cells # A pushed cell q1 would leave a q1 branch behind. git -C .cell/default.git branch q1 main atf_check -s exit:1 \ -e match:'branch "q1" already exists' \ -e match:'cell resume q1' \ "${CELL}" new q1 } atf_test_case resume_no_args resume_no_args_head() { atf_set "descr" "cell resume with no name prints usage and exits 64" } resume_no_args_body() { setup atf_check -s exit:64 -e match:"usage" "${CELL}" resume } atf_test_case resume_too_many_args resume_too_many_args_head() { atf_set "descr" "cell resume with extra arguments prints usage and exits 64" } resume_too_many_args_body() { setup atf_check -s exit:64 -e match:"usage" "${CELL}" resume a b } atf_test_case resume_no_cells_dir resume_no_cells_dir_head() { atf_set "descr" "cell resume fails when no .cell directory is found" } resume_no_cells_dir_body() { setup atf_check -s exit:1 -e match:".cell directory" "${CELL}" resume q1 } atf_test_case resume_missing_bare resume_missing_bare_head() { atf_set "descr" "cell resume fails when .cell holds no default.git" } resume_missing_bare_body() { setup mkdir .cell atf_check -s exit:1 -e match:"default.git" "${CELL}" resume q1 } atf_test_case resume_no_branch resume_no_branch_head() { atf_set "descr" "cell resume fails when default.git has no matching branch" } resume_no_branch_body() { setup mk_cells atf_check -s exit:1 -e match:'no branch "q1"' "${CELL}" resume q1 } atf_test_case resume_dest_exists resume_dest_exists_head() { atf_set "descr" "cell resume fails when the cell checkout already exists" } resume_dest_exists_body() { setup mk_cells mk_branch q1 mkdir -p .cell/q1.jj atf_check -s exit:1 -e match:"already exists" "${CELL}" resume q1 } atf_test_case resume_checks_out_branch resume_checks_out_branch_head() { atf_set "descr" "cell resume checks out the pushed branch content" } resume_checks_out_branch_body() { setup mk_cells mk_branch q1 atf_check -s exit:0 -e ignore "${CELL}" resume q1 atf_check -o inline:"resumed\n" cat .cell/q1.jj/work.txt } atf_test_case resume_tracks_branch resume_tracks_branch_head() { atf_set "descr" "cell resume leaves a local bookmark on the branch" } resume_tracks_branch_body() { setup mk_cells mk_branch q1 atf_check -s exit:0 -e ignore "${CELL}" resume q1 atf_check -o match:"^q1:" -e ignore \ jj -R .cell/q1.jj bookmark list q1 } atf_test_case workflow workflow_head() { atf_set "descr" "init then new yields a cell holding the source content" } workflow_body() { setup mk_src atf_check -s exit:0 -e ignore "${CELL}" init src/.git atf_check -s exit:0 -e ignore "${CELL}" new foo atf_check -o inline:"hello\n" cat .cell/foo.jj/file.txt }