7 use Config qw/%Config/;
9 use File::Spec::Functions qw/catfile path/;
11 use App::Rgit::Utils qw/:codes/;
25 : ( /^-([IKV]+)$/ ? do { $opts{$_} = 1 for split //, $1; () }
26 : do { $cmd = $_ unless /^-/; $_ } )
28 warn "rgit $VERSION\n" if $opts{V};
29 $cmd = ' ' unless defined $cmd;
36 if (eval "require Term::ReadKey; 1") {
37 Term::ReadKey->import;
38 *policy = \&policy_interactive;
39 for (grep defined, $ENV{SHELL}, '/bin/sh') {
46 warn "You have to install Term::ReadKey to use the interactive mode.\n";
49 *policy = $opts{K} ? \&policy_keep
51 unless defined *policy{CODE};
54 setpgrp 0, 0 if $Config{d_setpgrp};
56 my $git = $ENV{GIT_EXEC_PATH};
57 unless (defined $git) {
59 my $g = catfile $_, 'git';
66 croak "Couldn't find any valid git executable" unless defined $git;
68 my $root = $ENV{GIT_DIR};
69 $root = cwd unless defined $root;
80 my ($cmd, $conf, $repo, $status, $signal) = @_;
81 return NEXT unless $status;
85 sub policy_keep { NEXT }
87 sub policy_interactive {
88 my ($cmd, $conf, $repo, $status, $signal) = @_;
89 return NEXT unless $status;
91 'a' => [ LAST, 'aborting' ],
92 'i' => [ NEXT, 'ignoring' ],
93 'I' => [ NEXT | SAVE, 'ignoring all' ],
94 'r' => [ REDO, 'retrying' ],
96 my $int = { GetControlChars() }->{INTERRUPT};
98 print STDERR "[a]bort, [i]gnore, [I]gnore all, [r]etry, open [s]hell ?";
100 my $key = ReadKey(0);
103 next unless defined $key;
105 print STDERR "Interrupted, aborting\n";
107 } elsif ($key eq 's') {
108 if (defined $shell) {
109 print STDERR 'Opening shell in ', $repo->work, "\n";
112 system { $shell } $shell;
115 print STDERR "Couldn't find any shell\n";
117 } elsif (exists $codes{$key}) {
118 my $code = $codes{$key};
119 print STDERR 'Okay, ', $code->[1], "\n";
129 rgit - Recursively execute a command on all the git repositories in a directory tree.
137 rgit [-K|-V|-I] [GIT_OPTIONS] COMMAND [COMMAND_ARGS]
141 This utility recursively searches in the current directory (or in the directory given by the C<GIT_DIR> environment variable if it's set) for all git repositories, sort this list by the repository path, C<chdir> into each of them, and executes the specified git command.
142 Moreover, those formats are substuted in the arguments before running the command :
148 C<^n> with the current repository name.
152 C<^g> with the relative path to the current repository.
156 C<^G> with the absolute path to the current repository.
160 C<^w> with the relative path to the current repository's working directory.
164 C<^W> with the absolute path to the current repository's working directory.
168 C<^b> with a "bareified" relative path, i.e. C<^g> if this is a bare repository, and C<^w.git> otherwise.
172 C<^B> with an absolute version of the "bareified" path.
176 C<^R> with the absolute path to the current root directory.
180 C<^^> with a bare C<^>.
184 There are actually a few commands that are only executed once in the current directory : C<daemon>, C<gui>, C<help>, C<init> and C<version>.
185 For any of those, no format substitution is done.
187 You can specify which C<git> executable to use with the C<GIT_EXEC_PATH> environment variable.
189 =head1 COMMAND LINE SWITCHES
191 C<rgit> takes its options as the capital switches that comes before the git command.
192 It's possible to bundle them together.
193 They are removed from the argument list before calling C<git>.
201 Keep processing on error.
202 The default policy is to stop whenever an error occured.
208 Enables interactive mode when the standard input is a tty.
209 Requires L<Term::ReadKey> to be installed.
210 This lets you choose interactively what to do when one of the commands returns a non-zero status.
222 Execute C<git gc> on all the repositories below the current directory :
226 Tag all the repositories with their name :
230 Add a remote to all repositories in "/foo/bar" to their bare counterpart in C<qux> on F<host> :
232 GIT_DIR="/foo/bar" rgit remote add host git://host/qux/^b
236 The core modules L<Carp>, L<Config>, L<Cwd>, L<Exporter>, L<File::Find>, L<File::Spec::Functions> and L<POSIX>.
242 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
244 You can contact me by mail or on C<irc.perl.org> (vincent).
248 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.
252 You can find documentation for this module with the perldoc command.
256 Tests code coverage report is available at L<http://www.profvince.com/perl/cover/rgit>.
258 =head1 COPYRIGHT & LICENSE
260 Copyright 2008 Vincent Pit, all rights reserved.
262 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.