]> Dogcows Code - chaz/git-codeowners/commitdiff
require git 1.8.5 because of the -C flag
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 12 Nov 2019 05:57:51 +0000 (22:57 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 12 Nov 2019 05:57:51 +0000 (22:57 -0700)
bin/git-codeowners
t/app-codeowners-util.t
t/app-codeowners.t

index 231b16bada4ced86b70ca600058f3663fc4e0b2e..7262df4a558f30aa42a41fa7fe11416fc0273dac 100755 (executable)
@@ -169,6 +169,11 @@ C<PERL_TEXT_TABLE> environment variable if desired, like this:
 
 The list of available modules is at L<Text::Table::Any/@BACKENDS>.
 
 
 The list of available modules is at L<Text::Table::Any/@BACKENDS>.
 
+=head1 CAVEATS
+
+=for :list
+* Some commands require F<git> (at least version 1.8.5).
+
 =cut
 
 # FATPACK - Do not remove this line.
 =cut
 
 # FATPACK - Do not remove this line.
index 93fdce4cefce62897e471b098b376b2caf39c667..4366fdacd8e82b1d20b63c6f74f29bd90f535f6d 100644 (file)
@@ -72,7 +72,8 @@ exit;
 
 sub _can_git {
     my ($version) = run_git('--version');
 
 sub _can_git {
     my ($version) = run_git('--version');
-    return $version;
+    note "Found: $version" if $version;
+    return $version && $version ge 'git version 1.8.5';     # for -C flag
 }
 
 sub _setup_git_repo {
 }
 
 sub _setup_git_repo {
index 5d378416919d4064818aef56cc04c6e9c182817e..8be4287d30487e23e29d1cead3ce4734b153104d 100644 (file)
@@ -13,40 +13,40 @@ use Path::Tiny qw(path tempdir);
 use Test::More;
 
 my $can_git = _can_git();
 use Test::More;
 
 my $can_git = _can_git();
-plan skip_all => 'Cannot run git' if !$can_git;
 
 # Set progname so that pod2usage knows how to find the script after we chdir
 $0 = path($Bin)->parent->child('bin/git-codeowners')->absolute;
 
 $ENV{NO_COLOR} = 1;
 
 
 # Set progname so that pod2usage knows how to find the script after we chdir
 $0 = path($Bin)->parent->child('bin/git-codeowners')->absolute;
 
 $ENV{NO_COLOR} = 1;
 
-subtest 'basic options' => sub {
-    my $repodir = _setup_git_repo();
-    my $chdir   = pushd($repodir);
+sub run(&) { ## no critic (Subroutines::ProhibitSubroutinePrototypes)
+    my $code = shift;
+    capture { exit_code { $code->() } };
+}
 
 
-    my ($stdout, $stderr, $exit) = capture { exit_code { App::Codeowners->main('--help') } };
+subtest 'basic options' => sub {
+    my ($stdout, $stderr, $exit) = run { App::Codeowners->main('--help') };
     is($exit, 0, 'exited 0 when --help');
     like($stdout, qr/Usage:/, 'correct --help output') or diag $stdout;
 
     is($exit, 0, 'exited 0 when --help');
     like($stdout, qr/Usage:/, 'correct --help output') or diag $stdout;
 
-    ($stdout, $stderr, $exit) = capture { exit_code { App::Codeowners->main('--version') } };
+    ($stdout, $stderr, $exit) = run { App::Codeowners->main('--version') };
     is($exit, 0, 'exited 0 when --version');
     like($stdout, qr/git-codeowners [\d.]+\n/, 'correct --version output') or diag $stdout;
 };
 
 subtest 'bad options' => sub {
     is($exit, 0, 'exited 0 when --version');
     like($stdout, qr/git-codeowners [\d.]+\n/, 'correct --version output') or diag $stdout;
 };
 
 subtest 'bad options' => sub {
-    my $repodir = _setup_git_repo();
-    my $chdir   = pushd($repodir);
-
-    my ($stdout, $stderr, $exit) = capture { exit_code { App::Codeowners->main(qw{show --not-an-option}) } };
+    my ($stdout, $stderr, $exit) = run { App::Codeowners->main(qw{show --not-an-option}) };
     is($exit, 2, 'exited with error on bad option');
     like($stderr, qr/Unknown option: not-an-option/, 'correct error message') or diag $stderr;
 };
 
 subtest 'show' => sub {
     is($exit, 2, 'exited with error on bad option');
     like($stderr, qr/Unknown option: not-an-option/, 'correct error message') or diag $stderr;
 };
 
 subtest 'show' => sub {
+    plan skip_all => 'Cannot run git' if !$can_git;
+
     my $repodir = _setup_git_repo();
     my $chdir   = pushd($repodir);
 
     my $repodir = _setup_git_repo();
     my $chdir   = pushd($repodir);
 
-    my ($stdout, $stderr, $exit) = capture { exit_code { App::Codeowners->main(qw{-f %F;%O show}) } };
+    my ($stdout, $stderr, $exit) = run { App::Codeowners->main(qw{-f %F;%O show}) };
     is($exit, 0, 'exited without error');
     is($stdout, <<'END', 'correct output');
 CODEOWNERS;
     is($exit, 0, 'exited without error');
     is($stdout, <<'END', 'correct output');
 CODEOWNERS;
@@ -54,7 +54,7 @@ a/b/c/bar.txt;@snickers
 foo.txt;@twix
 END
 
 foo.txt;@twix
 END
 
-    ($stdout, $stderr, $exit) = capture { exit_code { App::Codeowners->main(qw{-f %F;%O;%P show}) } };
+    ($stdout, $stderr, $exit) = run { App::Codeowners->main(qw{-f %F;%O;%P show}) };
     is($exit, 0, 'exited without error');
     is($stdout, <<'END', 'correct output');
 CODEOWNERS;;
     is($exit, 0, 'exited without error');
     is($stdout, <<'END', 'correct output');
 CODEOWNERS;;
@@ -65,7 +65,7 @@ END
     subtest 'format json' => sub {
         plan skip_all => 'No JSON::MaybeXS' if !eval { require JSON::MaybeXS };
 
     subtest 'format json' => sub {
         plan skip_all => 'No JSON::MaybeXS' if !eval { require JSON::MaybeXS };
 
-        ($stdout, $stderr, $exit) = capture { exit_code { App::Codeowners->main(qw{-f json show --no-project}) } };
+        ($stdout, $stderr, $exit) = run { App::Codeowners->main(qw{-f json show --no-project}) };
         is($exit, 0, 'exited without error');
         my $expect = '[{"File":"CODEOWNERS","Owner":null},{"File":"a/b/c/bar.txt","Owner":["@snickers"]},{"File":"foo.txt","Owner":["@twix"]}]';
         is($stdout, $expect, 'correct output with json format');
         is($exit, 0, 'exited without error');
         my $expect = '[{"File":"CODEOWNERS","Owner":null},{"File":"a/b/c/bar.txt","Owner":["@snickers"]},{"File":"foo.txt","Owner":["@twix"]}]';
         is($stdout, $expect, 'correct output with json format');
@@ -77,7 +77,8 @@ exit;
 
 sub _can_git {
     my ($version) = run_git('--version');
 
 sub _can_git {
     my ($version) = run_git('--version');
-    return $version;
+    note "Found: $version" if $version;
+    return $version && $version ge 'git version 1.8.5';     # for -C flag
 }
 
 sub _setup_git_repo {
 }
 
 sub _setup_git_repo {
This page took 0.027217 seconds and 4 git commands to generate.