]> git.vpit.fr Git - perl/modules/rgit.git/blob - bin/rgit
Sort the list of repositories by repository path. Test for git returning non-zero
[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 Cwd qw/cwd/;
8 use File::Spec::Functions qw/catfile path/;
9 use List::Util qw/first/;
10
11 use App::Rgit;
12
13 our $VERSION = '0.02';
14
15 my $cmd = first { !/^-/ } @ARGV;
16 $cmd = ' ' unless defined $cmd;
17
18 my $git = $ENV{GIT_EXEC_PATH};
19 unless (defined $git) {
20  for (path) {
21   my $g = catfile $_, 'git';
22   if (-x $g) {
23    $git = $g;
24    last;
25   }
26  }
27 }
28 croak "Couldn't find any valid git executable" unless defined $git;
29
30 my $root = $ENV{GIT_DIR};
31 $root = cwd unless defined $root;
32
33 exit App::Rgit->new(
34  git  => $git,
35  root => $root,
36  cmd  => $cmd,
37  args => \@ARGV
38 )->run;
39
40 __END__
41
42 =head1 NAME
43
44 rgit - Recursively execute a command on all the git repositories in a directory tree.
45
46 =head1 VERSION
47
48 Version 0.02
49
50 =head1 SYNOPSIS
51
52     rgit [GIT_OPTIONS] COMMAND [COMMAND_ARGS]
53
54 =head1 DESCRIPTION
55
56 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.
57 Moreover, those formats are substuted in the arguments before running the command :
58
59 =over 4
60
61 =item *
62
63 C<^n> with the current repository name.
64
65 =item *
66
67 C<^g> with the relative path to the current repository.
68
69 =item *
70
71 C<^G> with the absolute path to the current repository.
72
73 =item *
74
75 C<^w> with the relative path to the current repository's working directory.
76
77 =item *
78
79 C<^W> with the absolute path to the current repository's working directory.
80
81 =item *
82
83 C<^b> with a "bareified" relative path, i.e. C<^g> if this is a bare repository, and C<^w.git> otherwise.
84
85 =item *
86
87 C<^B> with an absolute version of the "bareified" path.
88
89 =item *
90
91 C<^R> with the absolute path to the current root directory.
92
93 =item *
94
95 C<^^> with a bare C<^>.
96
97 =back
98
99 There are actually a few commands that are only executed once in the current directory : C<version>, C<help>, C<daemon> and C<init>.
100 For any of those, no format substitution is done.
101
102 You can specify which C<git> executable to use with the C<GIT_EXEC_PATH> environment variable.
103
104 =head1 EXAMPLES
105
106 Execute C<git gc> on all the repositories below the current directory :
107
108     rgit gc
109
110 Tag all the repositories with their name :
111
112     rgit tag ^n
113
114 Add a remote to all repositories in "/foo/bar" to their bare counterpart in C<qux> on F<host> :
115
116     GIT_DIR="/foo/bar" rgit remote add host git://host/qux/^b
117
118 =head1 DEPENDENCIES
119
120 The core modules L<Carp>, L<Cwd>, L<Exporter>, L<File::Find>, L<File::Spec::Functions> and L<List::Util>.
121
122 L<Object::Tiny>.
123
124 =head1 AUTHOR
125
126 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
127    
128 You can contact me by mail or on C<irc.perl.org> (vincent).
129
130 =head1 BUGS
131
132 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.
133
134 =head1 SUPPORT
135
136 You can find documentation for this module with the perldoc command.
137
138     perldoc rgit
139
140 Tests code coverage report is available at L<http://www.profvince.com/perl/cover/rgit>.
141
142 =head1 COPYRIGHT & LICENSE
143
144 Copyright 2008 Vincent Pit, all rights reserved.
145
146 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
147
148 =cut