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.
7 mr - a Multiple Repository management tool
11 B<mr> [options] checkout
13 B<mr> [options] update
15 B<mr> [options] status
17 B<mr> [options] commit [-m "message"]
23 B<mr> [options] register [repository]
25 B<mr> [options] config section [parameter=[value] ...]
27 B<mr> [options] action [params ...]
31 B<mr> is a Multiple Repository management tool. It
32 can checkout, update, or perform other actions on
33 a set of repositories as if they were one combined respository. It
34 supports any combination of subversion, git, cvs, and bzr repositories,
35 and support for other revision control systems can easily be added.
37 B<mr> cds into and operates on all registered repositories 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 These 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 These commands are also available:
85 List the repositories that mr will act on.
89 Register an existing repository in the mrconfig file. By default, the
90 repository in the current directory is registered, or you can specify a
91 directory to register.
93 By default it registers it to the ~/.mrconfig file. To make it write to a
94 different file, use the -c option.
98 Adds, modifies, removes, or prints a value from the mrconfig file. The next
99 parameter is the name of the section the value is in. To add or modify
100 values, use one or more instances of "parameter=value". Use "parameter=" to
101 remove a parameter. Use just "parameter" to get the value of a parameter.
103 For example, to add (or edit) a repository in src/foo:
105 mr config src/foo checkout="svn co svn://example.com/foo/trunk foo"
107 To show the command that mr uses to update the repository in src/foo:
109 mr config src/foo update
117 Actions can be abbreviated to any unambiguous subsctring, so
118 "mr st" is equivilant to "mr status", and "mr up" is equivilant to "mr
121 Additional parameters can be passed to most commands, and are passed on
122 unchanged to the underlying revision control system. This is mostly useful
123 if the repositories mr will act on all use the same revision control
132 Specifies the topmost directory that B<mr> should work in. The default is
133 the current working directory.
137 Use the specified mrconfig file, instead of looking for one in your home
146 Expand the statistics line displayed at the end to include information
147 about exactly which repositories failed and were skipped, if any.
153 B<mr> is configured by .mrconfig files. It starts by reading the .mrconfig
154 file in your home directory, and this can in turn chain load .mrconfig files
157 Here is an example .mrconfig file:
160 checkout = svn co svn://svn.example.com/src/trunk src
164 checkout = git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git &&
166 git checkout -b mybranch origin/master
168 The .mrconfig file uses a variant of the INI file format. Lines starting with
169 "#" are comments. Values can be continued to the following line by
170 indenting the line with whitespace.
172 The "DEFAULT" section allows setting default values for the sections that
175 The "ALIAS" section allows adding aliases for actions. Each parameter
176 is an alias, and its value is the action to use.
178 All other sections add repositories. The section header specifies the
179 directory where the repository is located. This is relative to the directory
180 that contains the mrconfig file, but you can also choose to use absolute
183 Within a section, each parameter defines a shell command to run to handle a
184 given action. mr contains default handlers for the "update", "status", and
185 "commit" actions, so normally you only need to specify what to do for
188 Note that these shell commands are run in a "set -e" shell
189 environment, where any additional parameters you pass are available in
190 "$@". The "checkout" command is run in the parent of the repository
191 directory, since the repository isn't checked out yet. All other commands
192 are run inside the repository, though not necessarily at the top of it.
193 The "MR_REPO" environment variable is set to the path to the top of the
194 repository, and "MR_CONFIG" is set to the topmost .mrconfig file used.
196 A few parameters have special meanings:
202 If the "skip" parameter is set and its command returns nonzero, then B<mr>
203 will skip acting on that repository. The command is passed the action
206 Here are two examples. The first skips the repo unless
207 mr is run by joey. The second uses the hours_since function
208 (included in mr's built-in library) to skip updating the repo unless it's
209 been at least 12 hours since the last update.
211 skip = test $(whoami) != joey
212 skip = [ "$1" = update ] && [ $(hours_since "$1") -lt 12 ]
216 If the "chain" parameter is set and its command returns nonzero, then B<mr>
217 will try to load a .mrconfig file from the root of the repository. (You
218 should avoid chaining from repositories with untrusted committers.)
222 If the "deleted" parameter is set and its command returns nonzero, then
223 B<mr> will treat the repository as deleted. It won't ever actually delete
224 the repository, but it will warn if it sees the repository's directory.
225 This is useful when one mrconfig file is shared amoung multiple machines,
226 to keep track of and remember to delete old repositories.
230 The "lib" parameter can specify some shell code that will be run before each
231 command, this can be a useful way to define shell functions for other commands
238 Copyright 2007 Joey Hess <joey@kitenet.net>
240 Licensed under the GNU GPL version 2 or higher.
242 http://kitenet.net/~joey/code/mr/
251 use Cwd qw(getcwd abs_path);
254 print STDERR "mr: interrupted\n";
258 $ENV{MR_CONFIG}="$ENV{HOME}/.mrconfig";
259 my $directory=getcwd();
266 Getopt::Long::Configure("no_permute");
267 my $result=GetOptions(
268 "d|directory=s" => sub { $directory=abs_path($_[1]) },
269 "c|config=s" => sub { $ENV{MR_CONFIG}=abs_path($_[1]) },
270 "v|verbose" => \$verbose,
271 "s|stats" => \$stats,
273 if (! $result || @ARGV < 1) {
274 die("Usage: mr [-d directory] action [params ...]\n".
275 "(Use mr help for man page.)\n");
280 loadconfig($ENV{MR_CONFIG});
282 #print Dumper(\%config);
285 use FindBin qw($Bin $Script);
286 $ENV{MR_PATH}=$Bin."/".$Script;
289 # alias expansion and command stemming
290 my $action=shift @ARGV;
291 if (exists $alias{$action}) {
292 $action=$alias{$action};
294 if (! exists $knownactions{$action}) {
295 my @matches = grep { /^\Q$action\E/ }
296 keys %knownactions, keys %alias;
300 elsif (@matches == 0) {
301 die "mr: unknown action \"$action\" (known actions: ".
302 join(", ", sort keys %knownactions).")\n";
305 die "mr: ambiguous action \"$action\" (matches: ".
306 join(", ", @matches).")\n";
310 if ($action eq 'help') {
311 exec($config{''}{DEFAULT}{$action}) || die "exec: $!";
313 elsif ($action eq 'config') {
315 die "mr config: not enough parameters\n";
318 if ($section=~/^\//) {
319 # try to convert to a path relative to $config's dir
320 my ($dir)=$ENV{MR_CONFIG}=~/^(.*\/)[^\/]+$/;
321 if ($section=~/^\Q$dir\E(.*)/) {
327 if (/^([^=]+)=(.*)$/) {
328 $changefields{$1}=$2;
332 foreach my $topdir (sort keys %config) {
333 if (exists $config{$topdir}{$section} &&
334 exists $config{$topdir}{$section}{$_}) {
335 print $config{$topdir}{$section}{$_}."\n";
340 die "mr $action: $section $_ not set\n";
344 modifyconfig($ENV{MR_CONFIG}, $section, %changefields) if %changefields;
347 elsif ($action eq 'register') {
348 my $command="set -e; ".$config{''}{DEFAULT}{lib}."\n".
349 "my_action(){ $config{''}{DEFAULT}{$action}\n }; my_action ".
350 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
351 print STDERR "mr $action: running >>$command<<\n" if $verbose;
352 exec($command) || die "exec: $!";
355 # work out what repos to act on
358 foreach my $topdir (sort keys %config) {
359 foreach my $subdir (sort keys %{$config{$topdir}}) {
360 next if $subdir eq 'DEFAULT';
361 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
363 $dir.="/" unless $dir=~/\/$/;
364 $d.="/" unless $d=~/\/$/;
365 next if $dir ne $directory && $dir !~ /^\Q$directory\E/;
366 push @repos, [$dir, $topdir, $subdir];
370 # fallback to find a leaf repo
371 LEAF: foreach my $topdir (reverse sort keys %config) {
372 foreach my $subdir (reverse sort keys %{$config{$topdir}}) {
373 next if $subdir eq 'DEFAULT';
374 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
376 $dir.="/" unless $dir=~/\/$/;
377 $d.="/" unless $d=~/\/$/;
378 if ($d=~/^\Q$dir\E/) {
379 push @repos, [$dir, $topdir, $subdir];
387 my (@failed, @ok, @skipped);
388 foreach my $repo (@repos) {
389 action($action, @$repo);
393 my ($action, $dir, $topdir, $subdir) = @_;
395 my $lib= exists $config{$topdir}{$subdir}{lib} ?
396 $config{$topdir}{$subdir}{lib}."\n" : "";
398 if (exists $config{$topdir}{$subdir}{deleted}) {
403 my $test="set -e;".$lib.$config{$topdir}{$subdir}{deleted};
404 print "mr $action: running deleted test >>$test<<\n" if $verbose;
405 my $ret=system($test);
407 if (($? & 127) == 2) {
408 print STDERR "mr $action: interrupted\n";
412 print STDERR "mr $action: deleted test received signal ".($? & 127)."\n";
414 if ($ret >> 8 == 0) {
415 print STDERR "mr error: $dir should be deleted yet still exists\n\n";
423 if ($action eq 'checkout') {
425 print "mr $action: $dir already exists, skipping checkout\n" if $verbose;
429 $dir=~s/^(.*)\/[^\/]+\/?$/$1/;
431 elsif ($action eq 'update') {
433 return action("checkout", $dir, $topdir, $subdir);
439 if (exists $config{$topdir}{$subdir}{skip}) {
440 my $test="set -e;".$lib.
441 "my_action(){ $config{$topdir}{$subdir}{skip}\n }; my_action '$action'";
442 print "mr $action: running skip test >>$test<<\n" if $verbose;
443 my $ret=system($test);
445 if (($? & 127) == 2) {
446 print STDERR "mr $action: interrupted\n";
450 print STDERR "mr $action: skip test received signal ".($? & 127)."\n";
453 if ($ret >> 8 == 0) {
454 print "mr $action: $dir skipped per config file\n" if $verbose;
461 if (! $nochdir && ! chdir($dir)) {
462 print STDERR "mr $action: failed to chdir to $dir: $!\n";
465 elsif (! exists $config{$topdir}{$subdir}{$action}) {
466 print STDERR "mr $action: no defined $action command for $topdir$subdir, skipping\n";
471 print "mr $action: $topdir$subdir\n";
474 print "mr $action: $topdir$subdir (in subdir $directory)\n";
476 my $command="set -e; ".$lib.
477 "my_action(){ $config{$topdir}{$subdir}{$action}\n }; my_action ".
478 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
479 print STDERR "mr $action: running >>$command<<\n" if $verbose;
480 my $ret=system($command);
482 if (($? & 127) == 2) {
483 print STDERR "mr $action: interrupted\n";
487 print STDERR "mr $action: received signal ".($? & 127)."\n";
489 print STDERR "mr $action: failed ($ret)\n" if $verbose;
491 if ($ret >> 8 != 0) {
492 print STDERR "mr $action: command failed\n";
495 print STDERR "mr $action: command died ($ret)\n";
499 if ($action eq 'checkout' && ! -d $dir) {
500 print STDERR "mr $action: $dir missing after checkout\n";;
517 return "$count ".($count > 1 ? $plural : $singular);
521 if (! @ok && ! @failed && ! @skipped) {
522 die "mr $action: no repositories found to work on\n";
524 print "mr $action: finished (".join("; ",
525 showstat($#ok+1, "ok", "ok"),
526 showstat($#failed+1, "failed", "failed"),
527 showstat($#skipped+1, "skipped", "skipped"),
531 print "mr $action: (skipped: ".join(" ", @skipped).")\n";
534 print "mr $action: (failed: ".join(" ", @failed).")\n";
540 elsif (! @ok && @skipped) {
546 sub loadconfig { #{{{
553 if (ref $f eq 'GLOB') {
562 my $absf=abs_path($f);
563 if ($loaded{$absf}) {
568 ($dir)=$f=~/^(.*\/)[^\/]+$/;
569 if (! defined $dir) {
572 $dir=abs_path($dir)."/";
574 # copy in defaults from first parent
576 while ($parent=~s/^(.*\/)[^\/]+\/?$/$1/) {
577 if ($parent eq '/') {
580 if (exists $config{$parent} &&
581 exists $config{$parent}{DEFAULT}) {
582 $config{$dir}{DEFAULT}={ %{$config{$parent}{DEFAULT}} };
587 print "mr: loading config $f\n" if $verbose;
588 open($in, "<", $f) || die "mr: open $f: $!\n";
599 next if /^\s*\#/ || /^\s*$/;
600 if (/^\[([^\]]*)\]\s*$/) {
603 elsif (/^(\w+)\s*=\s*(.*)/) {
608 while (@lines && $lines[0]=~/^\s(.+)/) {
615 if (! defined $section) {
616 die "$f line $.: parameter ($parameter) not in section\n";
618 if ($section ne 'ALIAS' &&
619 ! exists $config{$dir}{$section} &&
620 exists $config{$dir}{DEFAULT}) {
622 $config{$dir}{$section}={ %{$config{$dir}{DEFAULT}} };
624 if ($section eq 'ALIAS') {
625 $alias{$parameter}=$value;
627 elsif ($parameter eq 'lib') {
628 $config{$dir}{$section}{lib}.=$value."\n";
631 $config{$dir}{$section}{$parameter}=$value;
632 $knownactions{$parameter}=1;
633 if ($parameter eq 'chain' &&
634 length $dir && $section ne "DEFAULT" &&
635 -e $dir.$section."/.mrconfig") {
636 my $ret=system($value);
638 if (($? & 127) == 2) {
639 print STDERR "mr $action: chain test interrupted\n";
643 print STDERR "mr $action: chain test received signal ".($? & 127)."\n";
647 push @toload, $dir.$section."/.mrconfig";
653 die "$f line $line: parse error\n";
662 sub modifyconfig { #{{{
664 # the section to modify or add
665 my $targetsection=shift;
666 # fields to change in the section
667 # To remove a field, set its value to "".
674 open(my $in, "<", $f) || die "mr: open $f: $!\n";
679 my $formatfield=sub {
681 my @value=split(/\n/, shift);
683 return "$field = ".shift(@value)."\n".
684 join("", map { "\t$_\n" } @value);
688 while ($out[$#out] =~ /^\s*$/) {
689 unshift @blanks, pop @out;
691 foreach my $field (sort keys %changefields) {
692 if (length $changefields{$field}) {
693 push @out, "$field = $changefields{$field}\n";
694 delete $changefields{$field};
704 if (/^\s*\#/ || /^\s*$/) {
707 elsif (/^\[([^\]]*)\]\s*$/) {
708 if (defined $section &&
709 $section eq $targetsection) {
717 elsif (/^(\w+)\s*=\s(.*)/) {
722 while (@lines && $lines[0]=~/^\s(.+)/) {
728 if ($section eq $targetsection) {
729 if (exists $changefields{$parameter}) {
730 if (length $changefields{$parameter}) {
731 $value=$changefields{$parameter};
733 delete $changefields{$parameter};
737 push @out, $formatfield->($parameter, $value);
741 if (defined $section &&
742 $section eq $targetsection) {
745 elsif (%changefields) {
746 push @out, "\n[$targetsection]\n";
747 foreach my $field (sort keys %changefields) {
748 if (length $changefields{$field}) {
749 push @out, $formatfield->($field, $changefields{$field});
754 open(my $out, ">", $f) || die "mr: write $f: $!\n";
759 # Finally, some useful actions that mr knows about by default.
760 # These can be overridden in ~/.mrconfig.
775 for dir in .git .svn .bzr CVS; do
776 if [ -e "$MR_REPO/$dir" ]; then
777 flagfile="$MR_REPO/$dir/.mr_last$1"
781 if [ -z "$flagfile" ]; then
782 error "cannot determine flag filename"
784 perl -wle 'print -f shift() ? int((-M _) * 24) : 9999' "$flagfile"
789 if [ -d "$MR_REPO"/.svn ]; then
791 elif [ -d "$MR_REPO"/.git ]; then
792 git pull origin master "$@"
793 elif [ -d "$MR_REPO"/.bzr ]; then
795 elif [ -d "$MR_REPO"/CVS ]; then
798 error "unknown repo type"
801 if [ -d "$MR_REPO"/.svn ]; then
803 elif [ -d "$MR_REPO"/.git ]; then
804 git status "$@" || true
805 elif [ -d "$MR_REPO"/.bzr ]; then
807 elif [ -d "$MR_REPO"/CVS ]; then
810 error "unknown repo type"
813 if [ -d "$MR_REPO"/.svn ]; then
815 elif [ -d "$MR_REPO"/.git ]; then
816 git commit -a "$@" && git push --all
817 elif [ -d "$MR_REPO"/.bzr ]; then
818 bzr commit "$@" && bzr push
819 elif [ -d "$MR_REPO"/CVS ]; then
822 error "unknown repo type"
825 if [ -d "$MR_REPO"/.svn ]; then
827 elif [ -d "$MR_REPO"/.git ]; then
829 elif [ -d "$MR_REPO"/.bzr ]; then
831 elif [ -d "$MR_REPO"/CVS ]; then
834 error "unknown repo type"
837 if [ -d "$MR_REPO"/.svn ]; then
839 elif [ -d "$MR_REPO"/.git ]; then
841 elif [ -d "$MR_REPO"/.bzr ]; then
843 elif [ -d "$MR_REPO"/CVS ]; then
846 error "unknown repo type"
852 basedir="$(basename $(pwd))"
854 url=$(LANG=C svn info . | grep -i ^URL: | cut -d ' ' -f 2)
855 if [ -z "$url" ]; then
856 error "cannot determine svn url"
858 echo "Registering svn url: $url"
859 mr -c "$MR_CONFIG" config "$(pwd)" checkout="svn co $url $basedir"
860 elif [ -d .git ]; then
861 url=$(LANG=C git-config --get remote.origin.url)
862 if [ -z "$url" ]; then
863 error "cannot determine git url"
865 echo "Registering git url: $url"
866 mr -c "$MR_CONFIG" config "$(pwd)" checkout="git clone $url $basedir"
867 elif [ -d .bzr ]; then
868 url=$(cat .bzr/branch/parent)
869 if [ -z "$url" ]; then
870 error "cannot determine bzr url"
872 echo "Registering bzr url: $url"
873 mr -c "$MR_CONFIG" config "$(pwd)" checkout="bzr clone $url $basedir"
875 error "unable to register this repo type"
878 if [ ! -e "$MR_PATH" ]; then
879 error "cannot find program path"
881 (pod2man -c mr "$MR_PATH" | man -l -) || error "pod2man or man failed"
885 ed = echo "A horse is a horse, of course, of course.."
886 T = echo "I pity the fool."
887 right = echo "Not found."