All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
5 mr - a Multiple Repository management tool
9 B<mr> [options] checkout
11 B<mr> [options] update
13 B<mr> [options] status
15 B<mr> [options] commit [-m "message"]
21 B<mr> [options] register repository
23 B<mr> [options] config section [parameter=[value] ...]
25 B<mr> [options] action [params ...]
29 B<mr> is a Multiple Repository management tool. It allows you to register a
30 set of repositories in a .mrconfig file, and then checkout, update, or
31 perform other actions on the repositories as if they were one big
34 Any mix of revision control systems can be used with B<mr>, and you can
35 define arbitrary actions for commands like "update", "checkout", or "commit".
37 B<mr> cds into and operates on all registered repsitories at or below your
38 working directory. Or, if you are in a subdirectory of a repository that
39 contains no other registered repositories, it will stay in that directory,
40 and work on only that repository,
42 The predefined commands should be fairly familiar to users of any revision
47 =item checkout (or co)
49 Checks out any repositories that are not already checked out.
53 Updates each repository from its configured remote repository.
55 If a repository isn't checked out yet, it will first check it out.
59 Displays a status report for each repository, showing what
60 uncommitted changes are present in the repository.
64 Commits changes to each repository. (By default, changes are pushed to the
65 remote repository too, when using distributed systems like git.)
67 The optional -m parameter allows specifying a commit message.
71 Show a diff of uncommitted changes.
79 List the repositories that mr will act on.
83 The next parameter is the directory of an existing repository. The
84 repository will be registered in the mrconfig file.
88 Modifies the mrconfig file. The next parameter is the name of the section
89 to add or modify, and it is followed by one or more instances of
90 "parameter=value". Use "parameter=" to remove a parameter.
92 For example, to register a new svn repository in src/foo:
94 mr config src/foo checkout="svn co svn://example.com/foo/trunk"
102 Actions can be abbreviated to any unambiguous subsctring, so
103 "mr st" is equivilant to "mr status", and "mr up" is equivilant to "mr
106 Additional parameters can be passed to other commands than "commit", they
107 will be passed on unchanged to the underlying revision control system.
108 This is mostly useful if the repositories mr will act on all use the same
109 revision control system.
117 Specifies the topmost directory that B<mr> should work in. The default is
118 the current working directory.
122 Use the specified mrconfig file, instead of looking for one in your home
133 B<mr> is configured by .mrconfig files. It starts by reading the .mrconfig
134 file in your home directory, and this can in turn chain load .mrconfig files
137 Here is an example .mrconfig file:
140 checkout = svn co svn://svn.example.com/src/trunk src
144 checkout = git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
146 The .mrconfig file uses a variant of the INI file format. Lines starting with
147 "#" are comments. Lines ending with "\" are continued on to the next line.
149 The "DEFAULT" section allows setting default values for the sections that
152 The "ALIAS" section allows adding aliases for actions. Each parameter
153 is an alias, and its value is the action to use.
155 All other sections add repositories. The section header specifies the
156 directory where the repository is located. This is relative to the directory
157 that contains the mrconfig file, but you can also choose to use absolute
160 Within a section, each parameter defines a shell command to run to handle a
161 given action. mr contains default handlers for the "update", "status", and
162 "commit" actions, so normally you only need to specify what to do for
165 Note that these shell commands are run in a "set -e" shell
166 environment, where any additional parameters you pass are available in
167 "$@". The "checkout" command is run in the parent of the repository
168 directory, since the repository isn't checked out yet. All other commands
169 are run inside the repository, though not necessarily at the top of it.
170 The "MR_REPO" environment variable is set to the path to the top of the
173 A few parameters have special meanings:
179 If the "skip" parameter is set and its command returns nonzero, then B<mr>
180 will skip acting on that repository.
184 If the "chain" parameter is set and its command returns nonzero, then B<mr>
185 will try to load a .mrconfig file from the root of the repository. (You
186 should avoid chaining from repositories with untrusted committers.)
190 If the "deleted" parameter is set and its command returns nonzero, then
191 B<mr> will treat the repository as deleted. It won't ever actually delete
192 the repository, but it will warn if it sees the repsoitory's directory.
193 This is useful when one mrconfig file is shared amoung multiple machines,
194 to keep track of and remember to delete old repositories.
198 The "lib" parameter can specify some shell code that will be run before each
199 command, this can be a useful way to define shell functions for other commands
206 Copyright 2007 Joey Hess <joey@kitenet.net>
208 Licensed under the GNU GPL version 2 or higher.
210 http://kitenet.net/~joey/code/mr/
217 use Cwd qw(getcwd abs_path);
219 my $directory=getcwd();
220 my $config="$ENV{HOME}/.mrconfig";
226 Getopt::Long::Configure("no_permute");
227 my $result=GetOptions(
228 "d|directory=s" => sub { $directory=abs_path($_[1]) },
229 "c|config=s" => \$config,
230 "verbose" => \$verbose,
232 if (! $result || @ARGV < 1) {
233 die("Usage: mr [-d directory] action [params ...]\n".
234 "(Use mr help for man page.)\n");
241 #print Dumper(\%config);
244 use FindBin qw($Bin $Script);
245 $ENV{MR_PATH}=$Bin."/".$Script;
248 # alias expansion and command stemming
249 my $action=shift @ARGV;
250 if (exists $alias{$action}) {
251 $action=$alias{$action};
253 if (! exists $knownactions{$action}) {
254 my @matches = grep { /^\Q$action\E/ }
255 keys %knownactions, keys %alias;
259 elsif (@matches == 0) {
260 die "mr: unknown action \"$action\" (known actions: ".
261 join(", ", sort keys %knownactions).")\n";
264 die "mr: ambiguous action \"$action\" (matches: ".
265 join(", ", @matches).")\n";
269 if ($action eq 'help') {
270 exec($config{''}{DEFAULT}{$action}) || die "exec: $!";
272 elsif ($action eq 'config') {
274 die "mr config: not enough parameters\n";
277 if ($section=~/^\//) {
278 # try to convert to a path relative to $config's dir
279 my ($dir)=$config=~/^(.*\/)[^\/]+$/;
280 if ($section=~/^\Q$dir\E(.*)/) {
286 if (/^([^=]+)=(.*)$/) {
290 die "mr config: expected parameter=value, not \"$_\"\n";
293 modifyconfig($config, $section, %fields);
296 elsif ($action eq 'register') {
297 my $command="set -e; ".$config{''}{DEFAULT}{lib}."\n".
298 "my_action(){ $config{''}{DEFAULT}{$action}\n }; my_action ".
299 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
300 print STDERR "mr $action: running >>$command<<\n" if $verbose;
301 exec($command) || die "exec: $!";
304 # work out what repos to act on
307 foreach my $topdir (sort keys %config) {
308 foreach my $subdir (sort keys %{$config{$topdir}}) {
309 next if $subdir eq 'DEFAULT';
310 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
312 $dir.="/" unless $dir=~/\/$/;
313 $d.="/" unless $d=~/\/$/;
314 next if $dir ne $directory && $dir !~ /^\Q$directory\E/;
315 push @repos, [$dir, $topdir, $subdir];
319 # fallback to find a leaf repo
320 LEAF: foreach my $topdir (reverse sort keys %config) {
321 foreach my $subdir (reverse sort keys %{$config{$topdir}}) {
322 next if $subdir eq 'DEFAULT';
323 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
325 $dir.="/" unless $dir=~/\/$/;
326 $d.="/" unless $d=~/\/$/;
327 if ($d=~/^\Q$dir\E/) {
328 push @repos, [$dir, $topdir, $subdir];
336 my (@failed, @successful, @skipped);
337 foreach my $repo (@repos) {
338 action($action, @$repo);
342 my ($action, $dir, $topdir, $subdir) = @_;
344 my $lib= exists $config{$topdir}{$subdir}{lib} ?
345 $config{$topdir}{$subdir}{lib}."\n" : "";
347 if (exists $config{$topdir}{$subdir}{deleted}) {
352 my $test="set -e;".$lib.$config{$topdir}{$subdir}{deleted};
353 print "mr $action: running deleted test >>$test<<\n" if $verbose;
354 my $ret=system($test);
355 if ($ret >> 8 == 0) {
356 print STDERR "mr error: $dir should be deleted yet still exists\n\n";
363 if ($action eq 'checkout') {
365 print "mr $action: $dir already exists, skipping checkout\n" if $verbose;
369 $dir=~s/^(.*)\/[^\/]+\/?$/$1/;
371 elsif ($action eq 'update') {
373 return action("checkout", $dir, $topdir, $subdir);
379 if (exists $config{$topdir}{$subdir}{skip}) {
380 my $test="set -e;".$lib.$config{$topdir}{$subdir}{skip};
381 print "mr $action: running skip test >>$test<<\n" if $verbose;
382 my $ret=system($test);
383 if ($ret >> 8 == 0) {
384 print "mr $action: $dir skipped per config file\n" if $verbose;
390 if (! $nochdir && ! chdir($dir)) {
391 print STDERR "mr $action: failed to chdir to $dir: $!\n";
394 elsif (! exists $config{$topdir}{$subdir}{$action}) {
395 print STDERR "mr $action: no defined $action command for $topdir$subdir, skipping\n";
400 print "mr $action: $topdir$subdir\n";
403 print "mr $action: $topdir$subdir (in subdir $directory)\n";
405 my $command="set -e; ".$lib.
406 "my_action(){ $config{$topdir}{$subdir}{$action}\n }; my_action ".
407 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
408 print STDERR "mr $action: running >>$command<<\n" if $verbose;
409 my $ret=system($command);
411 print STDERR "mr $action: failed ($ret)\n" if $verbose;
413 if ($ret >> 8 != 0) {
414 print STDERR "mr $action: command failed\n";
417 print STDERR "mr $action: command died ($ret)\n";
421 push @successful, $dir;
433 return "$count ".($count > 1 ? $plural : $singular);
437 if (! @successful && ! @failed && ! @skipped) {
438 die "mr $action: no repositories found to work on\n";
440 print "mr $action: finished (".join("; ",
441 showstat($#successful+1, "successful", "successful"),
442 showstat($#failed+1, "failed", "failed"),
443 showstat($#skipped+1, "skipped", "skipped"),
448 elsif (! @successful && @skipped) {
461 if (ref $f eq 'GLOB') {
466 my $absf=abs_path($f);
467 if ($loaded{$absf}) {
472 print "mr: loading config $f\n" if $verbose;
473 open($in, "<", $f) || die "mr: open $f: $!\n";
474 ($dir)=$f=~/^(.*\/)[^\/]+$/;
475 if (! defined $dir) {
478 $dir=abs_path($dir)."/";
480 # copy in defaults from first parent
482 while ($parent=~s/^(.*)\/[^\/]+\/?$/$1/) {
483 if (exists $config{$parent} &&
484 exists $config{$parent}{DEFAULT}) {
485 $config{$dir}{DEFAULT}={ %{$config{$parent}{DEFAULT}} };
494 next if /^\s*\#/ || /^\s*$/;
495 if (/^\s*\[([^\]]*)\]\s*$/) {
498 elsif (/^\s*(\w+)\s*=\s*(.*)/) {
503 while ($value=~/(.*)\\$/s) {
504 $value=$1."\n".<$in>;
508 if (! defined $section) {
509 die "$f line $.: parameter ($parameter) not in section\n";
511 if ($section ne 'ALIAS' &&
512 ! exists $config{$dir}{$section} &&
513 exists $config{$dir}{DEFAULT}) {
515 $config{$dir}{$section}={ %{$config{$dir}{DEFAULT}} };
517 if ($section eq 'ALIAS') {
518 $alias{$parameter}=$value;
520 elsif ($parameter eq 'lib') {
521 $config{$dir}{$section}{lib}.=$value."\n";
524 $config{$dir}{$section}{$parameter}=$value;
525 $knownactions{$parameter}=1;
526 if ($parameter eq 'chain' &&
527 length $dir && $section ne "DEFAULT" &&
528 -e $dir.$section."/.mrconfig" &&
529 system($value) >> 8 == 0) {
530 push @toload, $dir.$section."/.mrconfig";
535 die "$f line $.: parse error\n";
547 # the section to modify or add
548 my $targetsection=shift;
549 # fields to change in the section
550 # To remove a field, set its value to "".
555 open(my $in, "<", $f) || die "mr: open $f: $!\n";
565 if (/^\s*\#/ || /^\s*$/) {
568 elsif (/^\s*\[([^\]]*)\]\s*$/) {
569 if (defined $section &&
570 $section eq $targetsection) {
572 while ($out[$#out] =~ /^\s*$/) {
573 unshift @blanks, pop @out;
575 foreach my $field (sort keys %changefields) {
576 if (length $changefields{$field}) {
577 push @out, "$field = $changefields{$field}\n";
587 elsif (/^\s*(\w+)\s*=\s(.*)/) {
592 while ($value=~/(.*\\)$/s) {
593 $value=$1."\n".shift(@lines);
597 if ($section eq $targetsection) {
598 if (exists $changefields{$parameter}) {
599 if (length $changefields{$parameter}) {
600 $value=$changefields{$parameter};
602 delete $changefields{$parameter};
606 push @out, "$parameter = $value\n";
611 push @out, "\n[$targetsection]\n";
612 foreach my $field (sort keys %changefields) {
613 if (length $changefields{$field}) {
614 push @out, "$field = $changefields{$field}\n";
619 open(my $out, ">", $f) || die "mr: write $f: $!\n";
624 # Finally, some useful actions that mr knows about by default.
625 # These can be overridden in ~/.mrconfig.
640 if [ -d "$MR_REPO"/.svn ]; then \
642 elif [ -d "$MR_REPO"/.git ]; then \
643 git pull origin master "$@" \
644 elif [ -d "$MR_REPO"/.bzr ]; then \
646 elif [ -d "$MR_REPO"/CVS ]; then \
649 error "unknown repo type" \
652 if [ -d "$MR_REPO"/.svn ]; then \
654 elif [ -d "$MR_REPO"/.git ]; then \
655 git status "$@" || true \
656 elif [ -d "$MR_REPO"/.bzr ]; then \
658 elif [ -d "$MR_REPO"/CVS ]; then \
661 error "unknown repo type" \
664 if [ -d "$MR_REPO"/.svn ]; then \
666 elif [ -d "$MR_REPO"/.git ]; then \
667 git commit -a "$@" && git push --all \
668 elif [ -d "$MR_REPO"/.bzr ]; then \
669 bzr commit "$@" && bzr push \
670 elif [ -d "$MR_REPO"/CVS ]; then \
673 error "unknown repo type" \
676 if [ -d "$MR_REPO"/.svn ]; then \
678 elif [ -d "$MR_REPO"/.git ]; then \
680 elif [ -d "$MR_REPO"/.bzr ]; then \
682 elif [ -d "$MR_REPO"/CVS ]; then \
685 error "unknown repo type" \
688 if [ -d "$MR_REPO"/.svn ]; then \
690 elif [ -d "$MR_REPO"/.git ]; then \
692 elif [ -d "$MR_REPO"/.bzr ]; then \
694 elif [ -d "$MR_REPO"/CVS ]; then \
697 error "unknown repo type" \
700 if [ -z "$1" ]; then \
701 error "repository directory not specified" \
704 basedir="$(basename $(pwd))" \
705 if [ -d .svn ]; then \
707 grep -i ^URL: | cut -d ' ' -f 2) \
708 if [ -z "$url" ]; then \
709 error "cannot determine svn url" \
711 echo "Found svn url: $url" \
712 mr config "$(pwd)" checkout="svn co $url $basedir" \
713 elif [ -d .git ]; then \
714 url=$(git-config --get remote.origin.url) \
715 if [ -z "$url" ]; then \
716 error "cannot determine git url" \
718 echo "Found git url: $url" \
719 mr config "$(pwd)" checkout="git clone $url $basedir" \
721 error "unable to register this repo type" \
726 if [ ! -e "$MR_PATH" ]; then \
727 error "cannot find program path" \
729 (pod2man -c mr "$MR_PATH" | man -l -) || \
730 error "pod2man or man failed"
732 ed = echo "A horse is a horse, of course, of course.."
733 T = echo "I pity the fool."