| 1 | package Taskwarrior::Kusarigama::Plugin::GitCommit; | ||
| 2 | our $AUTHORITY = 'cpan:YANICK'; | ||
| 3 | # ABSTRACT: turns the task repo into a git repository | ||
| 4 | $Taskwarrior::Kusarigama::Plugin::GitCommit::VERSION = '0.11.0'; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | |||
| 9 | use Module::Runtime qw/ use_module /; | ||
| 10 | # TODO use Git::Wrapper instead | ||
| 11 | use Git::Repository; | ||
| 12 | |||
| 13 | use Moo; | ||
| 14 | |||
| 15 | extends 'Taskwarrior::Kusarigama::Plugin'; | ||
| 16 | |||
| 17 | with 'Taskwarrior::Kusarigama::Hook::OnExit'; | ||
| 18 | |||
| 19 | sub on_exit { | ||
| 20 | my $self = shift; | ||
| 21 | |||
| 22 | my $dir = $self->data_dir; | ||
| 23 | |||
| 24 | my $lock = use_module( 'File::Flock::Tiny' )->trylock( "$dir/git.lock" ) | ||
| 25 | or return "git lock found"; | ||
| 26 | |||
| 27 | unless( $dir->child('.git')->exists ) { | ||
| 28 | Git::Repository->command( init => $dir ); | ||
| 29 | $self .= "initiated git repo for '$dir'"; | ||
| 30 | } | ||
| 31 | |||
| 32 | my $git = Git::Repository->new( work_tree => $dir ); | ||
| 33 | |||
| 34 | # no changes? Fine | ||
| 35 | return unless $git->run( 'status', '--short' ); | ||
| 36 | |||
| 37 | $git->run( 'add', '.' ); | ||
| 38 | $git->run( 'commit', '--message', $self->args ); | ||
| 39 | |||
| 40 | $lock->release; | ||
| 41 | }; | ||
| 42 | |||
| 43 | 1; | ||
| 44 | |||
| 45 | __END__ | ||
| 46 | |||
| 47 | =pod | ||
| 48 | |||
| 49 | =encoding UTF-8 | ||
| 50 | |||
| 51 | =head1 NAME | ||
| 52 | |||
| 53 | Taskwarrior::Kusarigama::Plugin::GitCommit - turns the task repo into a git repository | ||
| 54 | |||
| 55 | =head1 VERSION | ||
| 56 | |||
| 57 | version 0.11.0 | ||
| 58 | |||
| 59 | =head1 DESCRIPTION | ||
| 60 | |||
| 61 | Turns the F<~/.task> directory into a git repository, and | ||
| 62 | commits the state after every command. | ||
| 63 | |||
| 64 | Fair warning: the git repo tends to grow quite a bit over time, | ||
| 65 | so keep an eye on it. | ||
| 66 | |||
| 67 | =head1 AUTHOR | ||
| 68 | |||
| 69 | Yanick Champoux <yanick@cpan.org> | ||
| 70 | |||
| 71 | =head1 COPYRIGHT AND LICENSE | ||
| 72 | |||
| 73 | This software is copyright (c) 2018, 2017 by Yanick Champoux. | ||
| 74 | |||
| 75 | This is free software; you can redistribute it and/or modify it under | ||
| 76 | the same terms as the Perl 5 programming language system itself. | ||
| 77 | |||
| 78 | =cut |