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