+our $wa;
+our $local_git_cfg;
+
+sub in_playtree ($;$) {
+ my $sub = pop @_; # in_playtree [$twa, sub { ... };]
+ # default $twa is global $wa (which caller must, in that case, set)
+ # $twa should be relative paths of the form .git/FOO/BAR
+ my ($twa) = @_;
+ $twa //= $wa;
+ changedir $twa or die "$twa $!";
+ my $r = eval { $sub->($twa); };
+ changedir '../../..' or die "$@; $!";
+ die $@ if length $@;
+ return $r;
+}
+
+sub fresh_playtree (;$) {
+ my ($twa) = @_;
+ $twa //= $wa;
+ $local_git_cfg //= git_slurp_config_src 'local';
+ my $parent = dirname $twa;
+ mkdir $parent or $!==EEXIST or fail "failed to mkdir $parent: $!";
+ rmtree $twa;
+ mkdir $twa or die "$twa $!";
+ in_playtree sub { playtree_setup $local_git_cfg; };
+}
+