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 Register an existing repository in the mrconfig file. By default, the
84 epository in the current directory is registered, or you can specify a
85 directory to register.
89 Adds, modifies, removed, or prints a value from the mrconfig file. The next
90 parameter is the name of the section the value is in. To add or modify a
91 value, follow it by one or more instances of "parameter=value". Use
92 "parameter=" to remove a parameter. Use just "parameter" to get the value
95 For example, to add (or edit) a repository in src/foo:
97 mr config src/foo checkout="svn co svn://example.com/foo/trunk foo"
105 Actions can be abbreviated to any unambiguous subsctring, so
106 "mr st" is equivilant to "mr status", and "mr up" is equivilant to "mr
109 Additional parameters can be passed to most commands, and are passed on
110 unchanged to the underlying revision control system. This is mostly useful
111 if the repositories mr will act on all use the same revision control
120 Specifies the topmost directory that B<mr> should work in. The default is
121 the current working directory.
125 Use the specified mrconfig file, instead of looking for one in your home
136 B<mr> is configured by .mrconfig files. It starts by reading the .mrconfig
137 file in your home directory, and this can in turn chain load .mrconfig files
140 Here is an example .mrconfig file:
143 checkout = svn co svn://svn.example.com/src/trunk src
147 checkout = git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
149 The .mrconfig file uses a variant of the INI file format. Lines starting with
150 "#" are comments. Lines ending with "\" are continued on to the next line.
152 The "DEFAULT" section allows setting default values for the sections that
155 The "ALIAS" section allows adding aliases for actions. Each parameter
156 is an alias, and its value is the action to use.
158 All other sections add repositories. The section header specifies the
159 directory where the repository is located. This is relative to the directory
160 that contains the mrconfig file, but you can also choose to use absolute
163 Within a section, each parameter defines a shell command to run to handle a
164 given action. mr contains default handlers for the "update", "status", and
165 "commit" actions, so normally you only need to specify what to do for
168 Note that these shell commands are run in a "set -e" shell
169 environment, where any additional parameters you pass are available in
170 "$@". The "checkout" command is run in the parent of the repository
171 directory, since the repository isn't checked out yet. All other commands
172 are run inside the repository, though not necessarily at the top of it.
173 The "MR_REPO" environment variable is set to the path to the top of the
176 A few parameters have special meanings:
182 If the "skip" parameter is set and its command returns nonzero, then B<mr>
183 will skip acting on that repository.
187 If the "chain" parameter is set and its command returns nonzero, then B<mr>
188 will try to load a .mrconfig file from the root of the repository. (You
189 should avoid chaining from repositories with untrusted committers.)
193 If the "deleted" parameter is set and its command returns nonzero, then
194 B<mr> will treat the repository as deleted. It won't ever actually delete
195 the repository, but it will warn if it sees the repsoitory's directory.
196 This is useful when one mrconfig file is shared amoung multiple machines,
197 to keep track of and remember to delete old repositories.
201 The "lib" parameter can specify some shell code that will be run before each
202 command, this can be a useful way to define shell functions for other commands
209 Copyright 2007 Joey Hess <joey@kitenet.net>
211 Licensed under the GNU GPL version 2 or higher.
213 http://kitenet.net/~joey/code/mr/
220 use Cwd qw(getcwd abs_path);
222 my $directory=getcwd();
223 my $config="$ENV{HOME}/.mrconfig";
229 Getopt::Long::Configure("no_permute");
230 my $result=GetOptions(
231 "d|directory=s" => sub { $directory=abs_path($_[1]) },
232 "c|config=s" => \$config,
233 "verbose" => \$verbose,
235 if (! $result || @ARGV < 1) {
236 die("Usage: mr [-d directory] action [params ...]\n".
237 "(Use mr help for man page.)\n");
244 #print Dumper(\%config);
247 use FindBin qw($Bin $Script);
248 $ENV{MR_PATH}=$Bin."/".$Script;
251 # alias expansion and command stemming
252 my $action=shift @ARGV;
253 if (exists $alias{$action}) {
254 $action=$alias{$action};
256 if (! exists $knownactions{$action}) {
257 my @matches = grep { /^\Q$action\E/ }
258 keys %knownactions, keys %alias;
262 elsif (@matches == 0) {
263 die "mr: unknown action \"$action\" (known actions: ".
264 join(", ", sort keys %knownactions).")\n";
267 die "mr: ambiguous action \"$action\" (matches: ".
268 join(", ", @matches).")\n";
272 if ($action eq 'help') {
273 exec($config{''}{DEFAULT}{$action}) || die "exec: $!";
275 elsif ($action eq 'config') {
277 die "mr config: not enough parameters\n";
280 if ($section=~/^\//) {
281 # try to convert to a path relative to $config's dir
282 my ($dir)=$config=~/^(.*\/)[^\/]+$/;
283 if ($section=~/^\Q$dir\E(.*)/) {
289 if (/^([^=]+)=(.*)$/) {
290 $changefields{$1}=$2;
293 foreach my $topdir (sort keys %config) {
294 if (exists $config{$topdir}{$section} &&
295 exists $config{$topdir}{$section}{$_}) {
296 print $config{$topdir}{$section}{$_}."\n";
301 modifyconfig($config, $section, %changefields) if %changefields;
304 elsif ($action eq 'register') {
305 my $command="set -e; ".$config{''}{DEFAULT}{lib}."\n".
306 "my_action(){ $config{''}{DEFAULT}{$action}\n }; my_action ".
307 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
308 print STDERR "mr $action: running >>$command<<\n" if $verbose;
309 exec($command) || die "exec: $!";
312 # work out what repos to act on
315 foreach my $topdir (sort keys %config) {
316 foreach my $subdir (sort keys %{$config{$topdir}}) {
317 next if $subdir eq 'DEFAULT';
318 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
320 $dir.="/" unless $dir=~/\/$/;
321 $d.="/" unless $d=~/\/$/;
322 next if $dir ne $directory && $dir !~ /^\Q$directory\E/;
323 push @repos, [$dir, $topdir, $subdir];
327 # fallback to find a leaf repo
328 LEAF: foreach my $topdir (reverse sort keys %config) {
329 foreach my $subdir (reverse sort keys %{$config{$topdir}}) {
330 next if $subdir eq 'DEFAULT';
331 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
333 $dir.="/" unless $dir=~/\/$/;
334 $d.="/" unless $d=~/\/$/;
335 if ($d=~/^\Q$dir\E/) {
336 push @repos, [$dir, $topdir, $subdir];
344 my (@failed, @successful, @skipped);
345 foreach my $repo (@repos) {
346 action($action, @$repo);
350 my ($action, $dir, $topdir, $subdir) = @_;
352 my $lib= exists $config{$topdir}{$subdir}{lib} ?
353 $config{$topdir}{$subdir}{lib}."\n" : "";
355 if (exists $config{$topdir}{$subdir}{deleted}) {
360 my $test="set -e;".$lib.$config{$topdir}{$subdir}{deleted};
361 print "mr $action: running deleted test >>$test<<\n" if $verbose;
362 my $ret=system($test);
363 if ($ret >> 8 == 0) {
364 print STDERR "mr error: $dir should be deleted yet still exists\n\n";
371 if ($action eq 'checkout') {
373 print "mr $action: $dir already exists, skipping checkout\n" if $verbose;
377 $dir=~s/^(.*)\/[^\/]+\/?$/$1/;
379 elsif ($action eq 'update') {
381 return action("checkout", $dir, $topdir, $subdir);
387 if (exists $config{$topdir}{$subdir}{skip}) {
388 my $test="set -e;".$lib.$config{$topdir}{$subdir}{skip};
389 print "mr $action: running skip test >>$test<<\n" if $verbose;
390 my $ret=system($test);
391 if ($ret >> 8 == 0) {
392 print "mr $action: $dir skipped per config file\n" if $verbose;
398 if (! $nochdir && ! chdir($dir)) {
399 print STDERR "mr $action: failed to chdir to $dir: $!\n";
402 elsif (! exists $config{$topdir}{$subdir}{$action}) {
403 print STDERR "mr $action: no defined $action command for $topdir$subdir, skipping\n";
408 print "mr $action: $topdir$subdir\n";
411 print "mr $action: $topdir$subdir (in subdir $directory)\n";
413 my $command="set -e; ".$lib.
414 "my_action(){ $config{$topdir}{$subdir}{$action}\n }; my_action ".
415 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
416 print STDERR "mr $action: running >>$command<<\n" if $verbose;
417 my $ret=system($command);
419 print STDERR "mr $action: failed ($ret)\n" if $verbose;
421 if ($ret >> 8 != 0) {
422 print STDERR "mr $action: command failed\n";
425 print STDERR "mr $action: command died ($ret)\n";
429 push @successful, $dir;
441 return "$count ".($count > 1 ? $plural : $singular);
445 if (! @successful && ! @failed && ! @skipped) {
446 die "mr $action: no repositories found to work on\n";
448 print "mr $action: finished (".join("; ",
449 showstat($#successful+1, "successful", "successful"),
450 showstat($#failed+1, "failed", "failed"),
451 showstat($#skipped+1, "skipped", "skipped"),
456 elsif (! @successful && @skipped) {
469 if (ref $f eq 'GLOB') {
478 my $absf=abs_path($f);
479 if ($loaded{$absf}) {
484 print "mr: loading config $f\n" if $verbose;
485 open($in, "<", $f) || die "mr: open $f: $!\n";
486 ($dir)=$f=~/^(.*\/)[^\/]+$/;
487 if (! defined $dir) {
490 $dir=abs_path($dir)."/";
492 # copy in defaults from first parent
494 while ($parent=~s/^(.*)\/[^\/]+\/?$/$1/) {
495 if (exists $config{$parent} &&
496 exists $config{$parent}{DEFAULT}) {
497 $config{$dir}{DEFAULT}={ %{$config{$parent}{DEFAULT}} };
506 next if /^\s*\#/ || /^\s*$/;
507 if (/^\s*\[([^\]]*)\]\s*$/) {
510 elsif (/^\s*(\w+)\s*=\s*(.*)/) {
515 while ($value=~/(.*)\\$/s) {
516 $value=$1."\n".<$in>;
520 if (! defined $section) {
521 die "$f line $.: parameter ($parameter) not in section\n";
523 if ($section ne 'ALIAS' &&
524 ! exists $config{$dir}{$section} &&
525 exists $config{$dir}{DEFAULT}) {
527 $config{$dir}{$section}={ %{$config{$dir}{DEFAULT}} };
529 if ($section eq 'ALIAS') {
530 $alias{$parameter}=$value;
532 elsif ($parameter eq 'lib') {
533 $config{$dir}{$section}{lib}.=$value."\n";
536 $config{$dir}{$section}{$parameter}=$value;
537 $knownactions{$parameter}=1;
538 if ($parameter eq 'chain' &&
539 length $dir && $section ne "DEFAULT" &&
540 -e $dir.$section."/.mrconfig" &&
541 system($value) >> 8 == 0) {
542 push @toload, $dir.$section."/.mrconfig";
547 die "$f line $.: parse error\n";
559 # the section to modify or add
560 my $targetsection=shift;
561 # fields to change in the section
562 # To remove a field, set its value to "".
569 open(my $in, "<", $f) || die "mr: open $f: $!\n";
576 while ($out[$#out] =~ /^\s*$/) {
577 unshift @blanks, pop @out;
579 foreach my $field (sort keys %changefields) {
580 if (length $changefields{$field}) {
581 push @out, "$field = $changefields{$field}\n";
591 if (/^\s*\#/ || /^\s*$/) {
594 elsif (/^\s*\[([^\]]*)\]\s*$/) {
595 if (defined $section &&
596 $section eq $targetsection) {
604 elsif (/^\s*(\w+)\s*=\s(.*)/) {
609 while ($value=~/(.*\\)$/s) {
610 $value=$1."\n".shift(@lines);
614 if ($section eq $targetsection) {
615 if (exists $changefields{$parameter}) {
616 if (length $changefields{$parameter}) {
617 $value=$changefields{$parameter};
619 delete $changefields{$parameter};
623 push @out, "$parameter = $value\n";
627 if (defined $section &&
628 $section eq $targetsection) {
631 elsif (%changefields) {
632 push @out, "\n[$targetsection]\n";
633 foreach my $field (sort keys %changefields) {
634 if (length $changefields{$field}) {
635 push @out, "$field = $changefields{$field}\n";
640 open(my $out, ">", $f) || die "mr: write $f: $!\n";
645 # Finally, some useful actions that mr knows about by default.
646 # These can be overridden in ~/.mrconfig.
661 if [ -d "$MR_REPO"/.svn ]; then \
663 elif [ -d "$MR_REPO"/.git ]; then \
664 git pull origin master "$@" \
665 elif [ -d "$MR_REPO"/.bzr ]; then \
667 elif [ -d "$MR_REPO"/CVS ]; then \
670 error "unknown repo type" \
673 if [ -d "$MR_REPO"/.svn ]; then \
675 elif [ -d "$MR_REPO"/.git ]; then \
676 git status "$@" || true \
677 elif [ -d "$MR_REPO"/.bzr ]; then \
679 elif [ -d "$MR_REPO"/CVS ]; then \
682 error "unknown repo type" \
685 if [ -d "$MR_REPO"/.svn ]; then \
687 elif [ -d "$MR_REPO"/.git ]; then \
688 git commit -a "$@" && git push --all \
689 elif [ -d "$MR_REPO"/.bzr ]; then \
690 bzr commit "$@" && bzr push \
691 elif [ -d "$MR_REPO"/CVS ]; then \
694 error "unknown repo type" \
697 if [ -d "$MR_REPO"/.svn ]; then \
699 elif [ -d "$MR_REPO"/.git ]; then \
701 elif [ -d "$MR_REPO"/.bzr ]; then \
703 elif [ -d "$MR_REPO"/CVS ]; then \
706 error "unknown repo type" \
709 if [ -d "$MR_REPO"/.svn ]; then \
711 elif [ -d "$MR_REPO"/.git ]; then \
713 elif [ -d "$MR_REPO"/.bzr ]; then \
715 elif [ -d "$MR_REPO"/CVS ]; then \
718 error "unknown repo type" \
721 if [ -n "$1" ]; then \
724 basedir="$(basename $(pwd))" \
725 if [ -d .svn ]; then \
726 url=$(LANG=C svn info . | \
727 grep -i ^URL: | cut -d ' ' -f 2) \
728 if [ -z "$url" ]; then \
729 error "cannot determine svn url" \
731 echo "Registering svn url: $url" \
732 mr config "$(pwd)" checkout="svn co $url $basedir" \
733 elif [ -d .git ]; then \
734 url=$(LANG=C git-config --get remote.origin.url) \
735 if [ -z "$url" ]; then \
736 error "cannot determine git url" \
738 echo "Registering git url: $url" \
739 mr config "$(pwd)" checkout="git clone $url $basedir" \
740 elif [ -d .bzr ]; then \
741 url=$(cat .bzr/branch/parent) \
742 if [ -z "$url" ]; then \
743 error "cannot determine bzr url" \
745 echo "Registering bzr url: $url" \
746 mr config "$(pwd)" checkout="bzr clone $url $basedir" \
748 error "unable to register this repo type" \
753 if [ ! -e "$MR_PATH" ]; then \
754 error "cannot find program path" \
756 (pod2man -c mr "$MR_PATH" | man -l -) || \
757 error "pod2man or man failed"
759 ed = echo "A horse is a horse, of course, of course.."
760 T = echo "I pity the fool."