7 use Config qw/%Config/;
9 use File::Spec::Functions qw/catfile path/;
11 use App::Rgit::Utils qw/:codes :levels/;
25 : ( /^-([DIKV]+)$/ ? do { $opts{$_} = 1 for split //, $1; () }
26 : do { $cmd = $_ unless /^-/; $_ } )
28 $cmd = ' ' unless defined $cmd;
35 if (eval "require Term::ReadKey; 1") {
36 Term::ReadKey->import;
37 *policy = \&policy_interactive;
38 for (grep defined, $ENV{SHELL}, '/bin/sh') {
45 warn "You have to install Term::ReadKey to use the interactive mode.\n";
48 *policy = $opts{K} ? \&policy_keep
50 unless defined *policy{CODE};
53 setpgrp 0, 0 if $Config{d_setpgrp};
55 my $git = $ENV{GIT_EXEC_PATH};
56 unless (defined $git) {
58 my $g = catfile $_, 'git';
65 croak "Couldn't find any valid git executable" unless defined $git;
67 my $root = $ENV{GIT_DIR};
68 $root = cwd unless defined $root;
70 my $ar = App::Rgit->new(
76 debug => $opts{D} ? INFO : WARN,
79 print STDOUT "rgit $VERSION\n" if $opts{V};
84 my ($cmd, $conf, $repo, $status, $signal) = @_;
85 return NEXT unless $status;
89 sub policy_keep { NEXT }
91 sub policy_interactive {
92 my ($cmd, $conf, $repo, $status, $signal) = @_;
93 return NEXT unless $status;
95 'a' => [ LAST, 'aborting' ],
96 'i' => [ NEXT, 'ignoring' ],
97 'I' => [ NEXT | SAVE, 'ignoring all' ],
98 'r' => [ REDO, 'retrying' ],
100 my $int = { GetControlChars() }->{INTERRUPT};
102 $conf->warn("[a]bort, [i]gnore, [I]gnore all, [r]etry, open [s]hell ?");
104 my $key = ReadKey(0);
107 next unless defined $key;
109 $conf->warn("Interrupted, aborting\n");
111 } elsif ($key eq 's') {
112 if (defined $shell) {
113 $conf->info('Opening shell in ', $repo->work, "\n");
116 system { $shell } $shell;
119 $conf->err("Couldn't find any shell\n");
121 } elsif (exists $codes{$key}) {
122 my $code = $codes{$key};
123 $conf->info('Okay, ', $code->[1], "\n");
133 rgit - Recursively execute a command on all the git repositories in a directory tree.
141 rgit [-K|-I|-D|-V] [GIT_OPTIONS] COMMAND [COMMAND_ARGS]
145 This utility recursively searches in a root directory (which may be the current working directory or - if it has been set - the directory given by the C<GIT_DIR> environment variable) for all git repositories, sort this list by the repository path, C<chdir> into each of them, and executes the specified git command.
146 Moreover, those formats are substituted in the arguments before running the command :
152 C<%n> with the current repository name.
156 C<%g> with the relative path (based from the root directory) to the current repository.
160 C<%G> with the absolute path to the current repository.
164 C<%w> with the relative path (based from the root directory) to the current repository's working directory.
168 C<%W> with the absolute path to the current repository's working directory.
172 C<%b> with a "bareified" relative path, i.e. C<%g> if this is a bare repository, and C<%w.git> otherwise.
176 C<%B> with an absolute version of the "bareified" path.
180 C<%R> with the absolute path to the root directory.
184 C<%%> with a bare C<%>.
188 There are actually a few commands that are only executed once in the root directory : C<daemon>, C<gui>, C<help>, C<init> and C<version>.
189 For any of those, no format substitution is done.
191 You can specify which C<git> executable to use with the C<GIT_EXEC_PATH> environment variable.
193 =head1 COMMAND LINE SWITCHES
195 C<rgit> takes its options as the capital switches that comes before the git command.
196 It's possible to bundle them together.
197 They are removed from the argument list before calling C<git>.
205 Keep processing on error.
206 The default policy is to stop whenever an error occured.
212 Enables interactive mode when the standard input is a tty.
213 Requires L<Term::ReadKey> to be installed.
214 This lets you choose interactively what to do when one of the commands returns a non-zero status.
232 Execute C<git gc> on all the repositories below the current directory :
236 Tag all the repositories with their name :
240 Add a remote to all repositories in "/foo/bar" to their bare counterpart in C<qux> on F<host> :
242 GIT_DIR="/foo/bar" rgit remote add host git://host/qux/%b
246 The core modules L<Carp>, L<Config>, L<Cwd>, L<Exporter>, L<File::Find>, L<File::Spec::Functions> and L<POSIX>.
252 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
254 You can contact me by mail or on C<irc.perl.org> (vincent).
258 Please report any bugs or feature requests to C<bug-rgit at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=rgit>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
262 You can find documentation for this module with the perldoc command.
266 Tests code coverage report is available at L<http://www.profvince.com/perl/cover/rgit>.
268 =head1 COPYRIGHT & LICENSE
270 Copyright 2008-2009 Vincent Pit, all rights reserved.
272 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.