From d7841cb4430c9f7b3529b156fe1c2d599071cfa5 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Wed, 13 Nov 2019 10:10:39 -0700 Subject: [PATCH] fix broken "create" and "update" commands --- lib/App/Codeowners.pm | 9 ++++----- t/app-codeowners.t | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/App/Codeowners.pm b/lib/App/Codeowners.pm index 1dc97cc..8a83a68 100644 --- a/lib/App/Codeowners.pm +++ b/lib/App/Codeowners.pm @@ -201,11 +201,10 @@ END if ($repopath) { # if there is a repo we can try to update the list of unowned files - my $git_files = git_ls_files($repopath); - if (@$git_files) { - $codeowners->clear_unowned; - $codeowners->add_unowned(grep { !$codeowners->match($_) } @$git_files); - } + my ($proc, @filepaths) = git_ls_files($repopath); + $proc->wait and exit 1; + $codeowners->clear_unowned; + $codeowners->add_unowned(grep { !$codeowners->match($_) } @filepaths); } $codeowners->write_to_filepath($path); diff --git a/t/app-codeowners.t b/t/app-codeowners.t index 28309d3..5ec78cb 100644 --- a/t/app-codeowners.t +++ b/t/app-codeowners.t @@ -72,6 +72,25 @@ END }; }; +subtest 'create' => sub { + plan skip_all => 'Cannot run git' if !$can_git; + + my $repodir = _setup_git_repo(); + my $chdir = pushd($repodir); + + my $codeowners_filepath = path('CODEOWNERS'); + $codeowners_filepath->remove; + + my ($stdout, $stderr, $exit) = run { App::Codeowners->main(qw{create}) }; + is($exit, 0, 'exited without error'); + is($stderr, "Wrote CODEOWNERS\n", 'reportedly wrote a CODEOWNERS file'); + + ok($codeowners_filepath->is_file, 'did write CODEOWNERS file'); + + my $contents = $codeowners_filepath->slurp_utf8; + like($contents, qr/^# This file shows mappings/, 'correct contents of file') or diag $contents; +}; + done_testing; exit; -- 2.43.0