about summary refs log tree commit homepage
path: root/lib/PublicInbox/Import.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-31 13:51:19 +0000
committerEric Wong <e@80x24.org>2021-01-01 05:00:38 +0000
commit7c2f36de2fb49dd756f9a8a1a44dbf7fb4b25f38 (patch)
tree12059aacebe38efd987b7a1707cc3e806302d00f /lib/PublicInbox/Import.pm
parentd49c0789d208e66121bfb68ff0c48d7612a7cd8e (diff)
downloadpublic-inbox-7c2f36de2fb49dd756f9a8a1a44dbf7fb4b25f38.tar.gz
This matches git v2.28.0+ behavior in case users prefer
a different name.
Diffstat (limited to 'lib/PublicInbox/Import.pm')
-rw-r--r--lib/PublicInbox/Import.pm17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 079afc5f..7258e848 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -19,13 +19,21 @@ use PublicInbox::MDA;
 use PublicInbox::Eml;
 use POSIX qw(strftime);
 
+sub default_branch () {
+        state $default_branch = do {
+                my $r = popen_rd([qw(git config --global init.defaultBranch)]);
+                chomp(my $h = <$r> // '');
+                $h eq '' ? 'refs/heads/master' : $h;
+        }
+}
+
 sub new {
         # we can't change arg order, this is documented in POD
         # and external projects may rely on it:
         my ($class, $git, $name, $email, $ibx) = @_;
-        my $ref = 'refs/heads/master';
+        my $ref;
         if ($ibx) {
-                $ref = $ibx->{ref_head} // 'refs/heads/master';
+                $ref = $ibx->{ref_head};
                 $name //= $ibx->{name};
                 $email //= $ibx->{-primary_address};
                 $git //= $ibx->git;
@@ -34,7 +42,7 @@ sub new {
                 git => $git,
                 ident => "$name <$email>",
                 mark => 1,
-                ref => $ref,
+                ref => $ref // default_branch,
                 ibx => $ibx,
                 path_type => '2/38', # or 'v2'
                 lock_path => "$git->{git_dir}/ssoma.lock", # v2 changes this
@@ -441,7 +449,7 @@ sub run_die ($;$$) {
         $? == 0 or die join(' ', @$cmd) . " failed: $?\n";
 }
 
-my @INIT_FILES = ('HEAD' => "ref: refs/heads/master\n",
+my @INIT_FILES = ('HEAD' => undef, # filled in at runtime
                 'description' => <<EOD,
 Unnamed repository; edit this file 'description' to name the repository.
 EOD
@@ -459,6 +467,7 @@ sub init_bare {
         $dir = $dir->{git}->{git_dir} if ref($dir);
         require File::Path;
         File::Path::mkpath([ map { "$dir/$_" } qw(objects/info refs/heads) ]);
+        $INIT_FILES[1] //= 'ref: '.default_branch."\n";
         for (my $i = 0; $i < @INIT_FILES; $i++) {
                 my $f = $dir.'/'.$INIT_FILES[$i++];
                 next if -f $f;