Something went wrong. Try again.
my code lab
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369#!/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 <name> 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_argsno_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_commandunknown_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_argsinit_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_argsinit_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_defaultinit_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_branchinit_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_origininit_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_existsinit_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_argsnew_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_argsnew_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_dirnew_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_barenew_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_cellnew_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_subdirnew_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_remotenew_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_contentnew_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_failsnew_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_existsnew_branch_exists_head() { atf_set "descr" "cell new fails when default.git already has the <name> 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_argsresume_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_argsresume_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_dirresume_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_bareresume_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_branchresume_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_existsresume_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_branchresume_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_branchresume_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 workflowworkflow_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}