# implicitly uses $main::us
%EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)],
playground => [qw(record_maindir $maindir $local_git_cfg
+ $maindir_gitdir $maindir_gitcommon
fresh_playground $playground
ensure_a_playground)]);
@EXPORT_OK = ( @{ $EXPORT_TAGS{policyflags} },
# ----- maindir -----
+# these three all go together
our $maindir;
+our $maindir_gitdir;
+our $maindir_gitcommon;
+
our $local_git_cfg;
sub record_maindir () {
- $maindir //= must_getcwd();
+ if (!defined $maindir) {
+ $maindir = must_getcwd();
+ if (!stat "$maindir/.git") {
+ fail "cannot stat $maindir/.git: $!";
+ }
+ if (-d _) {
+ # we fall back to this in case we have a pre-worktree
+ # git, which may not know git rev-parse --git-common-dir
+ $maindir_gitdir = "$maindir/.git";
+ $maindir_gitcommon = "$maindir/.git";
+ } else {
+ $maindir_gitdir = cmdoutput qw(git rev-parse --git-dir);
+ $maindir_gitcommon = cmdoutput qw(git rev-parse --git-common-dir);
+ }
+ }
$local_git_cfg //= git_slurp_config_src 'local';
}
sub ensure_a_playground_parent ($) {
my ($spc) = @_;
record_maindir();
- $spc = ".git/$spc";
+ $spc = "$maindir_gitdir/$spc";
my $parent = dirname $spc;
- mkdir $parent or $!==EEXIST or fail "failed to mkdir $parent: $!";
+ mkdir $parent or $!==EEXIST
+ or fail "failed to mkdir playground parent $parent: $!";
return $spc;
}
$spc = ensure_a_playground_parent $spc;
rmtree $spc;
mkdir $spc or die "$spc $!";
- return $playground = "$maindir/$spc";
+ return $playground = $spc;
}
# ----- playtrees -----