fixed attributions, copyright and license pod
[scpubgit/File-Tree-Snapshot.git] / lib / File / Tree / Snapshot.pm
index 9b883f7..bdcf39a 100644 (file)
@@ -1,3 +1,5 @@
+# most of this was sponsored by socialflow.com
+
 package File::Tree::Snapshot;
 use Moo;
 use File::Path;
@@ -55,13 +57,20 @@ sub create {
     my $path = $self->storage_path;
     $self->_mkpath($path);
     $self->_git_exec('init');
+    CORE::open my $fh, '>', "$path/.gitignore"
+      or die "Unable to write .gitignore in '$path': $!\n";
+    $self->_git_exec('add', '.gitignore');
+    $self->_git_exec('commit', '-m', '"Initial commit"');
     return 1;
 }
 
 sub _has_changes {
     my ($self) = @_;
     my $path = $self->storage_path;
-    my @changes = `cd $path && git diff --name-only --cached`;
+    my $cmd = qq{cd $path && git status --porcelain};
+    CORE::open my $handle, '-|', $cmd
+      or die "Unable to find changes in ($cmd): $!\n";
+    my @changes = <$handle>;
     return scalar @changes;
 }
 
@@ -83,6 +92,8 @@ sub commit {
 sub reset {
     my ($self) = @_;
     $self->_git_exec('add .');
+    return 1
+        unless $self->_has_changes;
     $self->_git_exec('checkout -f');
     return 1;
 }
@@ -201,4 +212,26 @@ Will commit the changes made to the tree to the Git repository.
 
 Rolls back the changes since the last snapshot.
 
+=head1 AUTHOR
+
+ phaylon - Robert Sedlacek (cpan:PHAYLON) <r.sedlacek@shadowcat.co.uk>
+
+=head1 CONTRIBUTORS
+
+ mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
+
+=head1 SPONSORS
+
+The development of this module was sponsored by L<http://socialflow.com/>.
+
+=head1 COPYRIGHT
+
+Copyright (c) 2012 the File::Tree::Snapshot L</AUTHOR>, L</CONTRIBUTORS>
+and L</SPONSORS> as listed above.
+
+=head1 LICENSE
+
+This library is free software and may be distributed under the same terms
+as perl itself.
+
 =cut