]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
import: fix handling of init.defaultBranch
authorEric Wong <e@80x24.org>
Sun, 10 Mar 2024 21:41:30 +0000 (21:41 +0000)
committerEric Wong <e@80x24.org>
Sun, 10 Mar 2024 21:36:15 +0000 (21:36 +0000)
We must chomp the newline in the branch name if it's set.

Reported-by: Rob Herring <robh@kernel.org>
Link: https://public-inbox.org/meta/CAL_JsqK7P4gjLPyvzxNEcYmxT4j6Ah5f3Pz1RqDHxmysTg3aEg@mail.gmail.com/
Fixes: 73830410e4336b77 (treewide: use run_qx where appropriate, 2023-10-27)
lib/PublicInbox/Import.pm
t/clone-coderepo.t

index a951874b339c18f2509a298b1a2956e2ed95796b..ed34d548e6fcb4241f8559a216ec1519cf230bda 100644 (file)
@@ -26,6 +26,7 @@ sub default_branch () {
        state $default_branch = do {
                my $h = run_qx([qw(git config --global init.defaultBranch)],
                                 { GIT_CONFIG => undef });
+               chomp $h;
                $h eq '' ? 'refs/heads/master' : "refs/heads/$h";
        }
 }
index c0951941d4c8c56866049ee513901c2d7b62d6e3..c6180fc431c05922049a317de43fdf59e98e88b9 100644 (file)
@@ -7,6 +7,7 @@ use PublicInbox::Import;
 use File::Temp;
 use File::Path qw(remove_tree);
 use PublicInbox::SHA qw(sha1_hex);
+use PublicInbox::IO;
 require_mods(qw(json Plack::Builder HTTP::Date HTTP::Status));
 require_git_http_backend;
 require_git '1.8.5';
@@ -38,9 +39,10 @@ my $t0 = time - 1;
 my $m; # manifest hashref
 
 {
-       my $rdr = {};
-       my $fi_data = './t/git.fast-import-data';
-       open $rdr->{0}, '<', $fi_data or xbail "open($fi_data): $!";
+       my $fi_data = PublicInbox::IO::try_cat './t/git.fast-import-data';
+       my $db = PublicInbox::Import::default_branch;
+       $fi_data =~ s!\brefs/heads/master\b!$db!gs;
+       my $rdr = { 0 => \$fi_data };
        my @git = ('git', "--git-dir=$pa");
        xsys_e([@git, qw(fast-import --quiet)], undef, $rdr);
        xsys_e([qw(/bin/cp -Rp a.git b.git)], undef, { -C => "$tmpdir/src" });