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