-my @x = (qw/git config/, "--file=$filename");
-$git_dir = abs_path($git_dir);
-x(qw(git init -q --bare), $git_dir);
+my @x = (qw/git config/, "--file=$pi_config_tmp");
+
+$inboxdir = abs_path($inboxdir);
+if (-f "$inboxdir/inbox.lock") {
+ if (!defined $version) {
+ $version = 2;
+ } elsif ($version != 2) {
+ die "$inboxdir is a -V2 repo, -V$version specified\n"
+ }
+} elsif (-d "$inboxdir/objects") {
+ if (!defined $version) {
+ $version = 1;
+ } elsif ($version != 1) {
+ die "$inboxdir is a -V1 repo, -V$version specified\n"
+ }
+}
+
+$version = 1 unless defined $version;
+
+if ($version == 1 && defined $skip_epoch) {
+ die "--skip-epoch is only supported for -V2 repos\n";
+}
+
+my $ibx = PublicInbox::Inbox->new({
+ inboxdir => $inboxdir,
+ name => $name,
+ version => $version,
+ -primary_address => $address[0],
+ indexlevel => $indexlevel,
+});
+
+my $creat_opt = {};
+PublicInbox::InboxWritable->new($ibx, $creat_opt)->init_inbox(0, $skip_epoch);
+
+# needed for git prior to v2.1.0
+umask(0077) if defined $perm;
+