Dominic Humphries


Git::Archive - For automated file archiving with Git


  use Git::Archive;
  Git::Archive->commit({ msg => "Committing files", files => [qw/foo bar/] });


When you want to have code maintain a file archive by committing changes to a Git repo, you don't have the luxury of being lazy and simply telling the code to do:

  git pull
  git commit changes
  git push

Many little things can go wrong:

What if files are already staged when your code goes to commit its changes?
What if there are conflicts on pull?
What if the world ends?

This is a module that helps you not have to care about such questions! (Two out of three ain't bad)

The goal is to allow you to simply call the commit method, and know that you'll get a useful error and safe recovery to a working state, whatever goes wrong.



Commit message. This one is mandatory.


List of filenames to commit. Necessary unless you specify all_tracked or all_dirty. Can be either a string of space-separated filenames, or an arrayref of filename strings. If any of the filenames will contain a space, you must use the arrayref option. Otherwise, use whichever you prefer.


Default behaviour for errors is to just dump them to STDERR.

If you want something more exciting (like email!) supply a subref here.

Error sub arguments:


Hashref, mostly the arguments you passed in when calling the commit method


String containing the actual error message


If you want to execute some code upon successful commit supply the function here

Success sub arguments:


Hashref, mostly the arguments you passed in when calling the commit method


If you want to simply commit all tracked files, set this to be true


If you want to commit all changes in the directory, tracked or not, set this to be true


If you want to push to a remote, set this to the name of the remote (You'll typically want this to be 'origin')


If you want to make sure every file supplied in the 'files' arg is staged before committing, set this to be true: It will then throw an error if the file was unchanged/doesn't exist


If you want to use a directory other than the current one as your repo, specify it here

Note: If your git-controlled dir is ./foo and you want to commit the file ./foo/bar/baz then ( git_dir => './foo', files => 'bar/baz' )


If you want to call git as a different user via sudo, specify that user here


Dominic Humphries <>


Copyright 2013 Dominic Humphries


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.