]> Dogcows Code - chaz/git-codeowners/commitdiff
fix broken "create" and "update" commands
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Wed, 13 Nov 2019 17:10:39 +0000 (10:10 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Wed, 13 Nov 2019 17:10:39 +0000 (10:10 -0700)
lib/App/Codeowners.pm
t/app-codeowners.t

index 1dc97cc49dba3ead168ab5e4bd23e2865c0d0424..8a83a68496a7c7281ad28672426970551d6df139 100644 (file)
@@ -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);
index 28309d3861ca0b802cf938133128494302850377..5ec78cb8e9b37295e94b231ea38f4e862cb80b68 100644 (file)
@@ -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;
 
This page took 0.022079 seconds and 4 git commands to generate.