Showing 4 changed files with 37 additions and 11 deletions
+1
lib/Gitprep.pm
... ...
@@ -11,6 +11,7 @@ use Scalar::Util 'weaken';
11 11
 use Validator::Custom;
12 12
 use Mojolicious::Plugin::AutoRoute::Util 'template';
13 13
 
14
+
14 15
 # Digest::SHA loading to Mojo::Util if not loaded
15 16
 {
16 17
   package Mojo::Util;
+3 -2
lib/Gitprep/Git.pm
... ...
@@ -10,6 +10,7 @@ use File::Copy 'move';
10 10
 use File::Find 'find';
11 11
 use File::Path qw/mkpath rmtree/;
12 12
 use POSIX 'floor';
13
+use Gitprep::Util;
13 14
 
14 15
 # Attributes
15 16
 has 'bin';
... ...
@@ -531,7 +532,7 @@ sub delete_branch {
531 532
   
532 533
   if ($exists) {
533 534
     my @cmd = $self->cmd($user, $project, 'branch', '-D', $branch);
534
-    system(@cmd) == 0
535
+    Gitprep::Util::run_command(@cmd)
535 536
       or croak "Branch deleting failed. Can't delete branch $branch";
536 537
   }
537 538
   else {
... ...
@@ -1450,7 +1451,7 @@ sub import_branch {
1450 1451
     ($force ? '+' : '') . "refs/heads/$remote_branch:refs/heads/$branch"
1451 1452
   );
1452 1453
   
1453
-  system(@cmd) == 0
1454
+  Gitprep::Util::run_command(@cmd)
1454 1455
     or croak 'Open git fetch for import_branch failed';
1455 1456
 }
1456 1457
 
+10 -9
lib/Gitprep/Manager.pm
... ...
@@ -9,6 +9,8 @@ use File::Temp ();
9 9
 use Fcntl ':flock';
10 10
 use Carp 'croak';
11 11
 use File::Copy qw/copy move/;
12
+use File::Spec;
13
+use Gitprep::Util;
12 14
 
13 15
 has 'app';
14 16
 has 'authorized_keys_file';
... ...
@@ -608,12 +610,12 @@ sub _create_rep {
608 610
   my $rep = $git->rep($user, $project);
609 611
   mkdir $rep
610 612
     or croak "Can't create directory $rep: $!";
611
-
613
+  
612 614
   eval {
613 615
     # Git init
614 616
     {
615 617
       my @git_init_cmd = $git->cmd_rep($rep, 'init', '--bare');
616
-      system(@git_init_cmd) == 0
618
+      Gitprep::Util::run_command(@git_init_cmd)
617 619
         or croak  "Can't execute git init --bare:@git_init_cmd";
618 620
     }
619 621
     
... ...
@@ -630,7 +632,7 @@ sub _create_rep {
630 632
       '--bare',
631 633
       'update-server-info'
632 634
     );
633
-    system(@git_update_server_info_cmd) == 0
635
+    Gitprep::Util::run_command(@git_update_server_info_cmd)
634 636
       or croak "Can't execute git --bare update-server-info";
635 637
     move("$rep/hooks/post-update.sample", "$rep/hooks/post-update")
636 638
       or croak "Can't move post-update";
... ...
@@ -657,7 +659,7 @@ sub _create_rep {
657 659
 
658 660
       # Git init
659 661
       my @git_init_cmd = $git->cmd_rep($temp_work, 'init', '-q');
660
-      system(@git_init_cmd) == 0
662
+      Gitprep::Util::run_command(@git_init_cmd)
661 663
         or croak "Can't execute git init: @git_init_cmd";
662 664
       
663 665
       # Add README
... ...
@@ -674,7 +676,7 @@ sub _create_rep {
674 676
         'add',
675 677
         'README.md'
676 678
       );
677
-      system(@git_add_cmd) == 0
679
+      Gitprep::Util::run_command(@git_add_cmd)
678 680
         or croak "Can't execute git add: @git_add_cmd";
679 681
       
680 682
       # Commit
... ...
@@ -688,7 +690,7 @@ sub _create_rep {
688 690
         '-m',
689 691
         'first commit'
690 692
       );
691
-      system(@git_commit_cmd) == 0
693
+      Gitprep::Util::run_command(@git_commit_cmd)
692 694
         or croak "Can't execute git commit: @git_commit_cmd";
693 695
       
694 696
       # Push
... ...
@@ -702,8 +704,7 @@ sub _create_rep {
702 704
           'master'
703 705
         );
704 706
         # (This is bad, but --quiet option can't supress in old git)
705
-        my $git_push_cmd = join(' ', @git_push_cmd);
706
-        system("$git_push_cmd 2> /dev/null") == 0
707
+        Gitprep::Util::run_command(@git_push_cmd)
707 708
           or croak "Can't execute git push: @git_push_cmd";
708 709
       }
709 710
     }
... ...
@@ -812,7 +813,7 @@ sub _fork_rep {
812 813
     $rep,
813 814
     $to_rep
814 815
   );
815
-  system(@cmd) == 0
816
+  Gitprep::Util::run_command(@cmd)
816 817
     or croak "Can't fork repository(_fork_rep): @cmd";
817 818
   
818 819
   # Copy description
+23
lib/Gitprep/Util.pm
... ...
@@ -0,0 +1,23 @@
1
+package Gitprep::Util;
2
+
3
+use strict;
4
+use warnings;
5
+use IPC::Open3 ();
6
+use File::Spec;
7
+
8
+sub run_command {
9
+  my @cmd = @_;
10
+  
11
+  # Run command(Suppress STDOUT and STDERR)
12
+  my($wfh, $rfh, $efh);
13
+  my $pid = IPC::Open3::open3($wfh, $rfh, $efh, @cmd);
14
+  close $wfh;
15
+  () = <$rfh>;
16
+  waitpid($pid, 0);
17
+  
18
+  my $child_exit_status = $? >> 8;
19
+  
20
+  return $child_exit_status == 0 ? 1 : 0;
21
+}
22
+
23
+1;