]> git.vpit.fr Git - perl/modules/rgit.git/blobdiff - bin/rgit
Allow user-defined policies. Enable interactive failure handling when Term::ReadKey...
[perl/modules/rgit.git] / bin / rgit
index 6a56df7c8b0e5051ffa20dd777e58525cf399e83..e6bc9100cbb01edd930de2373521b6b353d5547c 100755 (executable)
--- a/bin/rgit
+++ b/bin/rgit
@@ -8,10 +8,44 @@ use Cwd qw/cwd/;
 use File::Spec::Functions qw/catfile path/;
 use List::Util qw/first/;
 
+use App::Rgit::Utils qw/:codes/;
 use App::Rgit;
 
 our $VERSION = '0.03';
 
+BEGIN {
+ if (-t && eval { use Term::ReadKey; 1 }) {
+  *policy = sub {
+   my ($cmd, $conf, $repo, $status) = @_;
+   return NEXT unless $status;
+   print STDERR "git returned $status\n";
+   print STDERR "[a]bort, [i]gnore, [I]gnore all, [r]etry, open [s]hell ?";
+   ReadMode 4;
+   my $key = ReadKey 0;
+   ReadMode 1;
+   print STDERR "\n";
+   my %codes = (
+    'a' => LAST,
+    'i' => NEXT,
+    'I' => NEXT | SAVE,
+    'r' => REDO,
+    's' => LAST,
+   );
+   $key = 'a' unless defined $key;
+   my $code = $codes{$key};
+   $code = $codes{a} unless defined $code;
+   return $code;
+  };
+ } else {
+  *policy = sub {
+   my ($cmd, $conf, $repo, $status) = @_;
+   return NEXT unless $status;
+   print STDERR "git returned $status, aborting\n";
+   return LAST;
+  };
+ }
+}
+
 my $cmd = first { !/^-/ } @ARGV;
 $cmd = ' ' unless defined $cmd;
 
@@ -31,10 +65,11 @@ my $root = $ENV{GIT_DIR};
 $root = cwd unless defined $root;
 
 exit App::Rgit->new(
- git  => $git,
- root => $root,
- cmd  => $cmd,
- args => \@ARGV
+ git    => $git,
+ root   => $root,
+ cmd    => $cmd,
+ args   => \@ARGV,
+ policy => \&policy,
 )->run;
 
 __END__