]> git.vpit.fr Git - perl/modules/rgit.git/blob - bin/rgit
Set a process group when possible
[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 use List::Util qw/first/;
11
12 use App::Rgit::Utils qw/:codes/;
13 use App::Rgit;
14
15 our $VERSION = '0.03';
16
17 BEGIN {
18  if (-t && eval { use Term::ReadKey; 1 }) {
19   *policy = sub {
20    my ($cmd, $conf, $repo, $status, $signal) = @_;
21    return NEXT unless $status;
22    print STDERR "[a]bort, [i]gnore, [I]gnore all, [r]etry, open [s]hell ?";
23    ReadMode 4;
24    my $key = ReadKey 0;
25    ReadMode 1;
26    print STDERR "\n";
27    my %codes = (
28     'a' => LAST,
29     'i' => NEXT,
30     'I' => NEXT | SAVE,
31     'r' => REDO,
32     's' => LAST,
33    );
34    $key = 'a' unless defined $key;
35    my $code = $codes{$key};
36    $code = $codes{a} unless defined $code;
37    return $code;
38   };
39  } else {
40   *policy = sub {
41    my ($cmd, $conf, $repo, $status, $signal) = @_;
42    return NEXT unless $status;
43    return LAST;
44   };
45  }
46 }
47
48 setpgrp 0, 0 if $Config{d_setpgrp};
49
50 my $cmd = first { !/^-/ } @ARGV;
51 $cmd = ' ' unless defined $cmd;
52
53 my $git = $ENV{GIT_EXEC_PATH};
54 unless (defined $git) {
55  for (path) {
56   my $g = catfile $_, 'git';
57   if (-x $g) {
58    $git = $g;
59    last;
60   }
61  }
62 }
63 croak "Couldn't find any valid git executable" unless defined $git;
64
65 my $root = $ENV{GIT_DIR};
66 $root = cwd unless defined $root;
67
68 exit App::Rgit->new(
69  git    => $git,
70  root   => $root,
71  cmd    => $cmd,
72  args   => \@ARGV,
73  policy => \&policy,
74 )->run;
75
76 __END__
77
78 =head1 NAME
79
80 rgit - Recursively execute a command on all the git repositories in a directory tree.
81
82 =head1 VERSION
83
84 Version 0.03
85
86 =head1 SYNOPSIS
87
88     rgit [GIT_OPTIONS] COMMAND [COMMAND_ARGS]
89
90 =head1 DESCRIPTION
91
92 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.
93 Moreover, those formats are substuted in the arguments before running the command :
94
95 =over 4
96
97 =item *
98
99 C<^n> with the current repository name.
100
101 =item *
102
103 C<^g> with the relative path to the current repository.
104
105 =item *
106
107 C<^G> with the absolute path to the current repository.
108
109 =item *
110
111 C<^w> with the relative path to the current repository's working directory.
112
113 =item *
114
115 C<^W> with the absolute path to the current repository's working directory.
116
117 =item *
118
119 C<^b> with a "bareified" relative path, i.e. C<^g> if this is a bare repository, and C<^w.git> otherwise.
120
121 =item *
122
123 C<^B> with an absolute version of the "bareified" path.
124
125 =item *
126
127 C<^R> with the absolute path to the current root directory.
128
129 =item *
130
131 C<^^> with a bare C<^>.
132
133 =back
134
135 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>.
136 For any of those, no format substitution is done.
137
138 You can specify which C<git> executable to use with the C<GIT_EXEC_PATH> environment variable.
139
140 =head1 EXAMPLES
141
142 Execute C<git gc> on all the repositories below the current directory :
143
144     rgit gc
145
146 Tag all the repositories with their name :
147
148     rgit tag ^n
149
150 Add a remote to all repositories in "/foo/bar" to their bare counterpart in C<qux> on F<host> :
151
152     GIT_DIR="/foo/bar" rgit remote add host git://host/qux/^b
153
154 =head1 DEPENDENCIES
155
156 The core modules L<Carp>, L<Cwd>, L<Exporter>, L<File::Find>, L<File::Spec::Functions>, L<List::Util> and L<POSIX>.
157
158 L<Object::Tiny>.
159
160 =head1 AUTHOR
161
162 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
163    
164 You can contact me by mail or on C<irc.perl.org> (vincent).
165
166 =head1 BUGS
167
168 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.
169
170 =head1 SUPPORT
171
172 You can find documentation for this module with the perldoc command.
173
174     perldoc rgit
175
176 Tests code coverage report is available at L<http://www.profvince.com/perl/cover/rgit>.
177
178 =head1 COPYRIGHT & LICENSE
179
180 Copyright 2008 Vincent Pit, all rights reserved.
181
182 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
183
184 =cut