1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use File::Temp qw(tempdir);
8 require './t/common.perl';
11 my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
12 URI::Escape Plack::Builder);
13 foreach my $mod (@mods) {
15 plan skip_all => "$mod missing for $0" if $@;
17 chomp(my $git_dir = `git rev-parse --git-dir 2>/dev/null`);
18 plan skip_all => "$0 must be run from a git working tree" if $?;
20 # needed for alternates, and --absolute-git-dir is only in git 2.13+
21 $git_dir = abs_path($git_dir);
23 use_ok "PublicInbox::$_" for (qw(Inbox V2Writable MIME Git SolverGit));
25 my $mainrepo = tempdir('pi-solver-XXXXXX', TMPDIR => 1, CLEANUP => 1);
27 mainrepo => $mainrepo,
28 name => 'test-v2writable',
30 -primary_address => 'test@example.com',
32 my $ibx = PublicInbox::Inbox->new($opts);
33 my $im = PublicInbox::V2Writable->new($ibx, 1);
36 sub deliver_patch ($) {
37 open my $fh, '<', $_[0] or die "open: $!";
38 my $mime = PublicInbox::MIME->new(do { local $/; <$fh> });
43 deliver_patch('t/solve/0001-simple-mod.patch');
45 my $git = PublicInbox::Git->new($git_dir);
46 is('public-inbox 1.0.0',
47 $git->commit_title('cb7c42b1e15577ed2215356a2bf925aef59cdd8d'),
48 'commit_title works on 1.0.0');
50 is(undef, $git->commit_title('impossible'), 'undef on impossible object');
52 $ibx->{-repo_objs} = [ $git ];
54 my $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
55 open my $log, '+>>', "$mainrepo/solve.log" or die "open: $!";
56 my $psgi_env = { 'psgi.errors' => *STDERR };
57 $solver->solve($psgi_env, $log, '69df7d5', {});
58 ok($res, 'solved a blob!');
59 my $wt_git = $res->[0];
60 is(ref($wt_git), 'PublicInbox::Git', 'got a git object for the blob');
61 my $expect = '69df7d565d49fbaaeb0a067910f03dc22cd52bd0';
62 is($res->[1], $expect, 'resolved blob to unabbreviated identifier');
63 is($res->[2], 'blob', 'type specified');
64 is($res->[3], 4405, 'size returned');
66 is(ref($wt_git->cat_file($res->[1])), 'SCALAR', 'wt cat-file works');
67 is_deeply([$expect, 'blob', 4405],
68 [$wt_git->check($res->[1])], 'wt check works');
70 if (0) { # TODO: check this?
72 my $z = do { local $/; <$log> };
79 my $s = PublicInbox::SolverGit->new($ibx, sub { $more = $_[0] });
80 $s->solve($psgi_env, $log, $oid, {});
81 is($more->[1], $expect, 'resolved blob to long OID '.$i);
87 my $wt_git_dir = $wt_git->{git_dir};
89 ok(!-d $wt_git_dir, 'no references to WT held');
91 $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
92 $solver->solve($psgi_env, $log, '0'x40, {});
93 is($res, undef, 'no error on z40');
95 my $git_v2_20_1_tag = '7a95a1cd084cb665c5c2586a415e42df0213af74';
96 $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
97 $solver->solve($psgi_env, $log, $git_v2_20_1_tag, {});
98 is($res, undef, 'no error on a tag not in our repo');
100 deliver_patch('t/solve/0002-rename-with-modifications.patch');
101 $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
102 $solver->solve($psgi_env, $log, '0a92431', {});
103 ok($res, 'resolved without hints');
108 path_b => 'CONTRIBUTING'
110 $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
111 $solver->solve($psgi_env, $log, '0a92431', $hints);
113 # don't compare ::Git objects:
114 shift @$res; shift @$hinted;
115 is_deeply($res, $hinted, 'hints work (or did not hurt :P');