]> git.vpit.fr Git - perl/modules/rgit.git/blob - bin/rgit
POD nit in bin/rgit
[perl/modules/rgit.git] / bin / rgit
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Carp qw/croak/;
7 use Config qw/%Config/;
8 use Cwd qw/cwd/;
9 use File::Spec::Functions qw/catfile path/;
10
11 use App::Rgit::Utils qw/:codes/;
12 use App::Rgit;
13
14 our $VERSION;
15 BEGIN {
16  $VERSION = '0.04';
17 }
18
19 my %opts;
20 my $cmd;
21
22 BEGIN {
23  @ARGV = grep {
24   defined $cmd ? $_
25                : ( /^-([IKV]+)$/ ? do { $opts{$_} = 1 for split //, $1; () }
26                                  : do { $cmd = $_ unless /^-/; $_ } )
27  } @ARGV;
28  warn "rgit $VERSION\n" if $opts{V};
29  $cmd = ' ' unless defined $cmd;
30 }
31
32 BEGIN {
33  if (-t && $opts{I}) {
34   if (eval "require Term::ReadKey; 1") {
35    Term::ReadKey->import;
36    *policy = sub {
37     my ($cmd, $conf, $repo, $status, $signal) = @_;
38     return NEXT unless $status;
39     print STDERR 'The command failed for ' . $repo->work . "\n";
40     print STDERR "[a]bort, [i]gnore, [I]gnore all, [r]etry ?";
41     ReadMode(4);
42     my $key = ReadKey(0);
43     ReadMode(1);
44     print STDERR "\n";
45     my %codes = (
46      'a' => LAST,
47      'i' => NEXT,
48      'I' => NEXT | SAVE,
49      'r' => REDO,
50     );
51     $key = 'a' unless defined $key;
52     my $code = $codes{$key};
53     $code = $codes{a} unless defined $code;
54     return $code;
55    };
56   } else {
57    warn "You have to install Term::ReadKey to use the interactive mode.\n";
58   }
59  }
60  *policy = sub { NEXT } if $opts{K} and not defined *policy{CODE};
61  *policy = sub {
62   my ($cmd, $conf, $repo, $status, $signal) = @_;
63   return NEXT unless $status;
64   return LAST;
65  } unless defined *policy{CODE};
66 }
67
68 setpgrp 0, 0 if $Config{d_setpgrp};
69
70 my $git = $ENV{GIT_EXEC_PATH};
71 unless (defined $git) {
72  for (path) {
73   my $g = catfile $_, 'git';
74   if (-x $g) {
75    $git = $g;
76    last;
77   }
78  }
79 }
80 croak "Couldn't find any valid git executable" unless defined $git;
81
82 my $root = $ENV{GIT_DIR};
83 $root = cwd unless defined $root;
84
85 exit App::Rgit->new(
86  git    => $git,
87  root   => $root,
88  cmd    => $cmd,
89  args   => \@ARGV,
90  policy => \&policy,
91 )->run;
92
93 __END__
94
95 =head1 NAME
96
97 rgit - Recursively execute a command on all the git repositories in a directory tree.
98
99 =head1 VERSION
100
101 Version 0.04
102
103 =head1 SYNOPSIS
104
105     rgit [-K|-V|-I] [GIT_OPTIONS] COMMAND [COMMAND_ARGS]
106
107 =head1 DESCRIPTION
108
109 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.
110 Moreover, those formats are substuted in the arguments before running the command :
111
112 =over 4
113
114 =item *
115
116 C<^n> with the current repository name.
117
118 =item *
119
120 C<^g> with the relative path to the current repository.
121
122 =item *
123
124 C<^G> with the absolute path to the current repository.
125
126 =item *
127
128 C<^w> with the relative path to the current repository's working directory.
129
130 =item *
131
132 C<^W> with the absolute path to the current repository's working directory.
133
134 =item *
135
136 C<^b> with a "bareified" relative path, i.e. C<^g> if this is a bare repository, and C<^w.git> otherwise.
137
138 =item *
139
140 C<^B> with an absolute version of the "bareified" path.
141
142 =item *
143
144 C<^R> with the absolute path to the current root directory.
145
146 =item *
147
148 C<^^> with a bare C<^>.
149
150 =back
151
152 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>.
153 For any of those, no format substitution is done.
154
155 You can specify which C<git> executable to use with the C<GIT_EXEC_PATH> environment variable.
156
157 =head1 COMMAND LINE SWITCHES
158
159 C<rgit> takes its options as the capital switches that comes before the git command.
160 It's possible to bundle them together.
161 They are removed from the argument list before calling C<git>.
162
163 =over 4
164
165 =item *
166
167 C<-K>
168
169 Keep processing on error.
170 The default policy is to stop whenever an error occured.
171
172 =item *
173
174 C<-I>
175
176 Enables interactive mode when the standard input is a tty.
177 Requires L<Term::ReadKey> to be installed.
178 This lets you choose interactively what to do when one of the commands returns a non-zero status.
179
180 =item *
181
182 C<-V>
183
184 Outputs the version.
185
186 =back
187
188 =head1 EXAMPLES
189
190 Execute C<git gc> on all the repositories below the current directory :
191
192     rgit gc
193
194 Tag all the repositories with their name :
195
196     rgit tag ^n
197
198 Add a remote to all repositories in "/foo/bar" to their bare counterpart in C<qux> on F<host> :
199
200     GIT_DIR="/foo/bar" rgit remote add host git://host/qux/^b
201
202 =head1 DEPENDENCIES
203
204 The core modules L<Carp>, L<Config>, L<Cwd>, L<Exporter>, L<File::Find>, L<File::Spec::Functions> and L<POSIX>.
205
206 L<Object::Tiny>.
207
208 =head1 AUTHOR
209
210 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
211    
212 You can contact me by mail or on C<irc.perl.org> (vincent).
213
214 =head1 BUGS
215
216 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.
217
218 =head1 SUPPORT
219
220 You can find documentation for this module with the perldoc command.
221
222     perldoc rgit
223
224 Tests code coverage report is available at L<http://www.profvince.com/perl/cover/rgit>.
225
226 =head1 COPYRIGHT & LICENSE
227
228 Copyright 2008 Vincent Pit, all rights reserved.
229
230 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
231
232 =cut