aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Feist <shabble@metavore.org>2011-05-05 03:56:49 +0000
committerTom Feist <shabble@metavore.org>2011-05-05 03:56:49 +0000
commitf67652377e1fff94536dd1c18ce33b43b86e84eb (patch)
tree5bdf042b588b703bdbc83deff67f1fa00bbb7be3
parentadded script to auto-updated "changed" field of %IRSSI hash when called on a ... (diff)
downloadirssi-scripts-f67652377e1fff94536dd1c18ce33b43b86e84eb.tar.gz
irssi-scripts-f67652377e1fff94536dd1c18ce33b43b86e84eb.zip
sorted otu pre-commit hook, I hope
-rwxr-xr-x[-rw-r--r--]changed_update.pl13
-rwxr-xr-xgit-update-changed-param-hook38
2 files changed, 46 insertions, 5 deletions
diff --git a/changed_update.pl b/changed_update.pl
index 2e6b733..15f6667 100644..100755
--- a/changed_update.pl
+++ b/changed_update.pl
@@ -6,8 +6,7 @@ use warnings;
use feature qw/say/;
use DateTime;
-my $infile = $ARGV[0] // 'feature-tests/template.pl.copy';
-
+my $infile = $ARGV[0] // die "No File provided"; #'feature-tests/template.pl.copy';
my $transform = PPI::Transform::UpdateTimestamp->new
(
updated => DateTime->now,
@@ -17,7 +16,10 @@ my $transform = PPI::Transform::UpdateTimestamp->new
my $ret = $transform->file($infile);
-say "Return value: " . defined $ret && $ret ? 'success' : 'failure';
+#say "Return value: " .
+
+exit (defined $ret && $ret ? 0 : 1);
+
package PPI::Transform::UpdateTimestamp;
@@ -28,6 +30,7 @@ use warnings;
use PPI;
use PPI::Dumper;
use DateTime;
+use Carp qw/carp/;
use base 'PPI::Transform';
@@ -43,7 +46,7 @@ sub new {
unless ( exists ($self->{updated}) ) {
#PPI::Exception->throw("Did not provide a valid updated timestamp.");
my $now = DateTime->now();
- carp "No updated value provided, using $now";
+ carp("No updated value provided, using $now");
$self->set_updated($now);
}
@@ -105,7 +108,7 @@ sub examine_struct {
if ($val->content eq $self->updated) {
$ret = 1;
}
-
+
say "Thingie: " . $t->content unless $self->quiet;
say "value set to: " . $val->content unless $self->quiet;
}
diff --git a/git-update-changed-param-hook b/git-update-changed-param-hook
new file mode 100755
index 0000000..0407e29
--- /dev/null
+++ b/git-update-changed-param-hook
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+
+# -*- mode: cperl -*-
+
+
+use strict;
+use warnings;
+use File::Spec;
+use feature qw/say/;
+
+my $file_cmd = "/usr/bin/file";
+my $git_cmd = "/opt/local/bin/git";
+
+my $root_dir = qx/$git_cmd rev-parse --show-toplevel/;
+chomp ($root_dir);
+
+my @changed_files = qx/git status --porcelain -u no/;
+
+foreach my $file (@changed_files) {
+ chomp $file;
+ if (is_irssi_script($file)) {
+ system(File::Spec->catfile($root_dir, 'changed_update.pl'), $file);
+ }
+}
+
+
+sub is_irssi_script {
+ my ($file) = @_;
+ my $full_path = File::Spec->catfile($root_dir, $file);
+ return 0 unless -f $full_path;
+ my $file_result = system("/usr/bin/grep -s -q '\%IRSSI' 1>/dev/null 2>&1");
+ if ($file_result != 0) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
+