Skip to content

Commit b7dc561

Browse files
committed
use code root, not checkout root
When searching for the root of the code, we don't actually want the checkout root. In Docker, there won't actually be a checkout. Instead, we just want the root directory. This can be calculated based on the config module's path.
1 parent 6de1a23 commit b7dc561

File tree

9 files changed

+28
-152
lines changed

9 files changed

+28
-152
lines changed

cpanfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ requires 'File::stat';
5858
requires 'File::Temp';
5959
requires 'FindBin';
6060
requires 'Getopt::Long::Descriptive', '0.103';
61-
requires 'Git::Helpers', '1.000001';
6261
requires 'Gravatar::URL';
6362
requires 'Hash::Merge::Simple';
6463
requires 'HTML::Entities';

cpanfile.snapshot

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,6 @@ DISTRIBUTIONS
229229
requirements:
230230
B 0
231231
ExtUtils::MakeMaker 0
232-
Browser-Open-0.04
233-
pathname: C/CF/CFRANKS/Browser-Open-0.04.tar.gz
234-
provides:
235-
Browser::Open 0.04
236-
requirements:
237-
ExtUtils::MakeMaker 0
238-
Test::More 0.92
239-
parent 0
240232
CGI-Simple-1.281
241233
pathname: M/MA/MANWAR/CGI-Simple-1.281.tar.gz
242234
provides:
@@ -2627,47 +2619,6 @@ DISTRIBUTIONS
26272619
perl 5.012
26282620
strict 0
26292621
warnings 0
2630-
Git-Helpers-1.000001
2631-
pathname: O/OA/OALDERS/Git-Helpers-1.000001.tar.gz
2632-
provides:
2633-
Git::Helpers 1.000001
2634-
Git::Helpers::CPAN 1.000001
2635-
requirements:
2636-
Browser::Open 0
2637-
Capture::Tiny 0
2638-
Carp 0
2639-
ExtUtils::MakeMaker 0
2640-
File::pushd 0
2641-
Getopt::Long 0
2642-
Git::Sub 0
2643-
MetaCPAN::Client 2.029000
2644-
Moo 0
2645-
MooX::Options 0
2646-
Pod::Usage 0
2647-
String::Trim 0
2648-
Sub::Exporter 0
2649-
Term::Choose 1.743
2650-
Try::Tiny 0
2651-
Types::Standard 0
2652-
URI 0
2653-
URI::Heuristic 0
2654-
URI::git 0
2655-
perl v5.12.0
2656-
strict 0
2657-
warnings 0
2658-
Git-Sub-0.163320
2659-
pathname: D/DO/DOLMEN/Git-Sub-0.163320.tar.gz
2660-
provides:
2661-
Git::Sub 0.163320
2662-
requirements:
2663-
Carp 0
2664-
ExtUtils::MakeMaker 0
2665-
File::Which 0
2666-
System::Sub 0.162800
2667-
perl 5.006
2668-
strict 0
2669-
subs 0
2670-
warnings 0
26712622
Gravatar-URL-1.07
26722623
pathname: M/MS/MSCHWERN/Gravatar-URL-1.07.tar.gz
26732624
provides:
@@ -6676,18 +6627,6 @@ DISTRIBUTIONS
66766627
perl 5.012
66776628
strict 0
66786629
warnings 0
6679-
String-Trim-0.005
6680-
pathname: D/DO/DOHERTY/String-Trim-0.005.tar.gz
6681-
provides:
6682-
String::Trim 0.005
6683-
requirements:
6684-
Data::Dumper 0
6685-
Exporter 5.57
6686-
ExtUtils::MakeMaker 6.31
6687-
File::Find 0
6688-
File::Temp 0
6689-
Test::Builder 0.94
6690-
Test::More 0.94
66916630
Sub-Exporter-0.991
66926631
pathname: R/RJ/RJBS/Sub-Exporter-0.991.tar.gz
66936632
provides:
@@ -6811,23 +6750,6 @@ DISTRIBUTIONS
68116750
requirements:
68126751
Call::Context 0
68136752
ExtUtils::MakeMaker 0
6814-
System-Sub-0.162800
6815-
pathname: D/DO/DOLMEN/System-Sub-0.162800.tar.gz
6816-
provides:
6817-
System::Sub 0.162800
6818-
System::Sub::AutoLoad 0.162800
6819-
requirements:
6820-
Carp 0
6821-
ExtUtils::MakeMaker 0
6822-
File::Which 0
6823-
IPC::Run 0
6824-
Scalar::Util 1.11
6825-
Sub::Name 0
6826-
Symbol 0
6827-
constant 0
6828-
perl 5.006
6829-
strict 0
6830-
warnings 0
68316753
TOML-Tiny-0.18
68326754
pathname: O/OA/OALDERS/TOML-Tiny-0.18.tar.gz
68336755
provides:
@@ -6856,34 +6778,6 @@ DISTRIBUTIONS
68566778
Scalar::Util 1.14
68576779
perl 5.006
68586780
strict 0
6859-
Term-Choose-1.765
6860-
pathname: K/KU/KUERBIS/Term-Choose-1.765.tar.gz
6861-
provides:
6862-
Term::Choose 1.765
6863-
Term::Choose::Constants 1.765
6864-
Term::Choose::LineFold 1.765
6865-
Term::Choose::LineFold::CharWidthAmbiguousWide 1.765
6866-
Term::Choose::LineFold::CharWidthDefault 1.765
6867-
Term::Choose::Linux 1.765
6868-
Term::Choose::Opt::Mouse 1.765
6869-
Term::Choose::Opt::Search 1.765
6870-
Term::Choose::Opt::SkipItems 1.765
6871-
Term::Choose::Screen 1.765
6872-
Term::Choose::ValidateOptions 1.765
6873-
Term::Choose::Win32 1.765
6874-
requirements:
6875-
Carp 0
6876-
Exporter 0
6877-
ExtUtils::MakeMaker 0
6878-
File::Spec::Functions 0
6879-
FindBin 0
6880-
Test::Fatal 0
6881-
Test::More 0
6882-
constant 0
6883-
lib 0
6884-
perl 5.010000
6885-
strict 0
6886-
warnings 0
68876781
Term-Size-Any-0.002
68886782
pathname: F/FE/FERREIRA/Term-Size-Any-0.002.tar.gz
68896783
provides:
@@ -7962,15 +7856,6 @@ DISTRIBUTIONS
79627856
URI 1.40
79637857
URI::Nested 0.10
79647858
perl 5.008001
7965-
URI-git-0.02
7966-
pathname: M/MI/MIYAGAWA/URI-git-0.02.tar.gz
7967-
provides:
7968-
URI::git 0.02
7969-
requirements:
7970-
ExtUtils::MakeMaker 6.42
7971-
Filter::Util::Call 0
7972-
Test::More 0
7973-
URI 0
79747859
URI-ws-0.03
79757860
pathname: P/PL/PLICEASE/URI-ws-0.03.tar.gz
79767861
provides:

lib/MetaCPAN/Role/HasConfig.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use Moose::Role;
44

55
use MetaCPAN::Server::Config ();
66
use MetaCPAN::Types::TypeTiny qw( HashRef );
7-
use MetaCPAN::Util qw( checkout_root );
87

98
# Done like this so can be required by a role
109
sub config {

lib/MetaCPAN/Role/Script.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use IO::Prompt::Tiny qw( prompt );
99
use Log::Contextual qw( :log :dlog );
1010
use MetaCPAN::Model ();
1111
use MetaCPAN::Types::TypeTiny qw( Bool HashRef Int Path Str );
12-
use MetaCPAN::Util qw( checkout_root );
12+
use MetaCPAN::Util qw( root_dir );
1313
use Mojo::Server ();
1414
use Term::ANSIColor qw( colored );
1515

@@ -123,7 +123,7 @@ has home => (
123123
isa => Path,
124124
lazy => 1,
125125
coerce => 1,
126-
default => sub { checkout_root() },
126+
default => sub { root_dir() },
127127
);
128128

129129
has quarantine => (

lib/MetaCPAN/Server/Config.pm

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@ package MetaCPAN::Server::Config;
33
use warnings;
44
use strict;
55

6-
use Config::ZOMG ();
7-
use FindBin ();
8-
use Module::Runtime qw( require_module );
6+
use Config::ZOMG ();
7+
use MetaCPAN::Util qw(root_dir);
98

109
sub config {
11-
my $config = _zomg("$FindBin::RealBin/..");
12-
return $config if $config;
13-
14-
require_module('Git::Helpers');
15-
$config = _zomg( Git::Helpers::checkout_root() );
10+
my $root = root_dir();
11+
my $config = _zomg($root);
1612

1713
if ( !$config ) {
18-
die "Couldn't find config file in $FindBin::RealBin/.. or "
19-
. Git::Helpers::checkout_root();
14+
die "Couldn't find config file in $root";
2015
}
2116

2217
return $config;

lib/MetaCPAN/Util.pm

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ use strict;
66
use warnings;
77
use version;
88

9-
use Digest::SHA qw( sha1_base64 sha1_hex );
10-
use Encode qw( decode_utf8 );
11-
use IPC::Run3 ();
12-
use Ref::Util qw(
9+
use Cwd ();
10+
use Digest::SHA qw( sha1_base64 sha1_hex );
11+
use Encode qw( decode_utf8 );
12+
use File::Basename ();
13+
use File::Spec ();
14+
use Ref::Util qw(
1315
is_arrayref
1416
is_hashref
1517
is_plain_arrayref
@@ -19,7 +21,7 @@ use Ref::Util qw(
1921
use Cpanel::JSON::XS ();
2022
use Sub::Exporter -setup => {
2123
exports => [ qw(
22-
checkout_root
24+
root_dir
2325
author_dir
2426
diff_struct
2527
digest
@@ -41,17 +43,13 @@ use Sub::Exporter -setup => {
4143
*false = \&Cpanel::JSON::XS::false;
4244
*is_bool = \&Cpanel::JSON::XS::is_bool;
4345

44-
sub checkout_root {
45-
IPC::Run3::run3( [qw(git rev-parse --show-toplevel)],
46-
\undef, \my $stdout, \my $stderr );
47-
if ($?) {
48-
die $stderr;
49-
}
50-
chomp $stdout;
51-
if ( !-d $stdout ) {
52-
die "Failed to find git dir: '$stdout'";
53-
}
54-
return $stdout;
46+
sub root_dir {
47+
Cwd::abs_path(
48+
File::Spec->catdir(
49+
File::Basename::dirname(__FILE__),
50+
( File::Spec->updir ) x 2
51+
)
52+
);
5553
}
5654

5755
sub digest {

t/lib/MetaCPAN/TestHelpers.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use Cpanel::JSON::XS qw( decode_json encode_json );
1010
use File::Copy qw( copy );
1111
use File::pushd qw( pushd );
1212
use MetaCPAN::Server::Config ();
13-
use MetaCPAN::Util qw( checkout_root );
13+
use MetaCPAN::Util qw( root_dir );
1414
use Path::Tiny qw( path );
1515
use Test::More;
1616
use Test::Routine::Util qw( run_tests );
@@ -103,7 +103,7 @@ sub get_config {
103103
}
104104

105105
sub tmp_dir {
106-
my $dir = path( checkout_root(), 'var', 't', 'tmp' );
106+
my $dir = path( root_dir(), 'var', 't', 'tmp' );
107107
$dir->mkpath;
108108
return $dir;
109109
}
@@ -116,7 +116,7 @@ sub fakecpan_dir {
116116
}
117117

118118
sub fakecpan_configs_dir {
119-
my $source = path( checkout_root(), 'test-data', 'fakecpan' );
119+
my $source = path( root_dir(), 'test-data', 'fakecpan' );
120120
$source->mkpath;
121121
return $source;
122122
}

t/script/cover.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use lib 't/lib';
55

66
use MetaCPAN::Script::Cover ();
77
use MetaCPAN::Server::Config ();
8-
use MetaCPAN::Util qw( checkout_root );
8+
use MetaCPAN::Util qw( root_dir );
99
use Test::More;
1010
use URI ();
1111

12-
my $root = checkout_root();
12+
my $root = root_dir();
1313
my $file = URI->new('t/var/cover.json')->abs("file://$root/");
1414

1515
my $config = MetaCPAN::Server::Config::config();

t/script/river.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use lib 't/lib';
55
use MetaCPAN::Script::River ();
66
use MetaCPAN::Server::Test qw( app GET );
77
use MetaCPAN::TestHelpers qw( decode_json_ok );
8-
use MetaCPAN::Util qw( checkout_root );
8+
use MetaCPAN::Util qw( root_dir );
99
use Plack::Test ();
1010
use Test::More;
1111
use URI ();
1212

1313
my $config = MetaCPAN::Server::Config::config();
1414

1515
# local json file with structure from https://github.com/metacpan/metacpan-api/issues/460
16-
my $root = checkout_root();
16+
my $root = root_dir();
1717
my $file = URI->new('t/var/river.json')->abs("file://$root/");
1818
$config->{'river_url'} = "$file";
1919

0 commit comments

Comments
 (0)