#!perl
use strict;
use warnings;

=head1 NAME

rami - Automates merging/committing a single change to
an arbitrary number of branches

=head1 SYNOPSIS

Try it from the command line, using this real demonstration repository.
Merge revision 7 from the trunk to all the branches, as follows:

  $ rami --load-repo-config-from-svn-url=https://github.com/DanTheDancer/demo-rami/trunk/rami-config
  ...
  Checked out revision 8.
  
  $ rami -c 7
  ...
  Password for 'you': ***********
  Committed revision 9

Of course, it won't work as well if you don't have permission to commit to that repository,
which you probably don't. But let's look at what the commands do.

  $ rami --load-repo-config-from-svn-url=https://github.com/DanTheDancer/demo-rami/trunk/rami-config

Configures Rami using the files at that URL. There is only one such file, named C<urls.csv>,
which tells it the branches to which it should merge changes to the trunk.

  $ rami -c 7

Tells Rami to merge revision 7. Rami figures out that revision 7 was made to the trunk, and that
according to C<urls.csv>, changes to the trunk should go to three branches. So it commits the
change to all three branches.

Note: if it encounters a merge conflict, Rami will exit with an error message.

=head1 FILES

Both configuration and repository working directories can be found in the C<~/.rami> directory.

=head1 BUGS

When run from Cygwin, rami uses the Cygwin user's home directory,
which is different from the Windows user's home directory.
This means that rami on Cygwin and rami on Windows do not share the same configuration.

Rami keeps a local copy of all the branches, even when it is not running.
(In other words, if you run Rami, you will have all the branches sitting
on your hard drive at once.)
This makes Rami run faster, but uses a lot of disk space.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc SVN::Rami


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker (report bugs here)

L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=SVN-Rami>

=item * CPAN Ratings

L<https://cpanratings.perl.org/d/SVN-Rami>

=item * Search CPAN

L<https://metacpan.org/release/SVN-Rami>

=back

=head1 SEE ALSO

SVK::Merge

=head1 LICENSE AND COPYRIGHT

This software is copyright (c) 2023 by Dan Richter.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.


=cut

package rami;



# PODNAME: rami
# ABSTRACT: automate merging to an arbitrary number of branches

# To invoke this script from the dev environment, use:
#   perl -Ilib bin\rami
# For example:
#   perl -Ilib bin\rami -c 84987 

use SVN::Rami;

my $load_config_from_SVN_arg = '--load-repo-config-from-svn-url';
# my $help_command = '--help';

my $command = shift || '';   # If there is no command-line arg, it is ''.

if ($command eq '-c') {
	# The usual case.
	my $source_revision = shift;
	SVN::Rami::rami_main($source_revision);
} elsif ($command =~ /^$load_config_from_SVN_arg=(.*)$/) {
	SVN::Rami::load_config_from_SVN_url($1);
} elsif ($command eq '--version') {
	print "rami version ${SVN::Rami::VERSION}\n";
} else {
	print "Usage: $0 -c <revision_number>\n";
	print "or: $0 $load_config_from_SVN_arg=<SVN-URL>\n";
	exit 1;
}
