SVK

 view release on metacpan or  search on metacpan

lib/SVK/Command/Branch.pm  view on Meta::CPAN

    my $src_path = $self->{fromtag} ?
	$proj->tag_path($self->{fromtag}) :
	$proj->branch_path($self->{from} ? $self->{from} : 'trunk');
    my $newbranch_path = $self->dst_path($proj, $branch_name);

    my $src = $self->arg_uri_maybe($src_path, 'New mirror site not allowed here');
    die loc("Path %1 does not exist.\n",$src->depotpath) if
	$SVN::Node::none == $src->root->check_path($src->path);
    my $dst = $self->arg_uri_maybe($newbranch_path, 'New mirror site not allowed here');
    $SVN::Node::none == $dst->root->check_path($dst->path)
	or die loc("Project branch already exists: %1 %2\n",
	    $branch_name, $self->{local} ? '(in local)' : '');
    if ($self->{local} and $SVN::Node::none != $dst->root->check_path($proj->local_root)) {
	my $trunk = SVK::Path->real_new(
	    {   depot    => $proj->depot,
		revision => $src->root->revision_root_revision,
		path     => $proj->trunk
	    }
	);
        my $lb = $trunk->mclone( path => $target->_to_pclass($proj->local_root,'Unix') );
	die loc("The local project root %1 is a branch itself.\n".
	     "Please rename the directory and try again\n", $proj->local_root) if $lb->related_to($trunk);
    }

    $self->{parent} = 1;
    $self->{message} ||= join(" ", "- Create", ($self->{tag} ? "tag" : "branch"), $branch_name);
    my $ret = $self->SUPER::run($src, $dst);

    if (!$ret) {
	$logger->info( loc("Project %1 created: %2%3%4\n",
        $self->{tag} ? "tag" : "branch",
	    $branch_name,
	    $self->{local} ? ' (in local)' : '',
	    $self->{fromtag} ? " (from tag $self->{fromtag})" :
		$self->{from} ? " (from branch $self->{from})" : '',
	  )
	);
	# call SVK::Command::Switch here if --switch-to
        if ($self->{switch} and !$self->{check_only}) {
            $dst = $self->arg_uri_maybe($newbranch_path);
            if ($target->related_to($dst)) {
                $self->SVK::Command::Switch::run(
                    $dst, $target
                );
            } else {
                $logger->info(
                    loc("Can't switch to the branch because current dir is not a working copy.")
                );
            }
        }
    }
    return;
}

package SVK::Command::Branch::move;
use base qw( SVK::Command::Move SVK::Command::Smerge SVK::Command::Delete SVK::Command::Branch::create );
use SVK::I18N;
use SVK::Logger;
use Path::Class;

sub lock { $_[0]->lock_coroot ($_[1]); };

sub parse_arg {
    my ($self, @arg) = @_;
    return if $#arg < 0;

    die loc ("Copy destination or source can't be URI.\n")
	if $self->ensure_non_uri (@arg);
    my $dst = pop(@arg);

    push @arg, '' unless @arg;

    return ($self->arg_co_maybe ('', 'New mirror site not allowed here'), $dst, @arg);
}

sub run {
    my ($self, $target, $dst_path, @src_paths) = @_;

    my $proj = $self->load_project($target);

    my $depot_root = '/'.$proj->depot->depotname;
    my $branch_path = $depot_root.$proj->branch_location;
    # Normalize name and path
    my $dst_name = $self->dst_name($proj, $dst_path);
    my $dst_branch_path = $self->dst_path($proj, $dst_name);
    my $dst = $self->arg_depotpath($dst_branch_path);
    $SVN::Node::none == $dst->root->check_path($dst->path)
	or $SVN::Node::dir == $dst->root->check_path($dst->path)
	or die loc("Project branch already exists: %1%2\n",
	    $branch_path, $self->{local} ? ' (in local)' : '');
    die loc("Project branch already exists: %1%2\n",
	$dst_name, $self->{local} ? ' (in local)' : '')
        if grep {$_->[0] =~ m/$dst_name/} @{$proj->branches};

    $self->{parent} = 1;
    for my $src_path (@src_paths) {
	$src_path = $target->path unless $src_path;
	$src_path = $target->_to_pclass("$src_path",'Unix');
	if ($target->_to_pclass("/local")->subsumes($src_path)) {
	    $self->{local}++;
	} else {
	    $self->{local} = 0;
	}
	my $src_name = $self->dst_name($proj,$src_path);
	my $src_branch_path = $self->dst_path($proj, $src_name);
	my $src = $self->arg_co_maybe($src_branch_path, 'New mirror site not allowed here');

	if ( !$dst->same_source($src) ) {
	    # branch first, then sm -I
	    my ($which_depotpath, $which_rev_we_branch) =
		(($src->copy_ancestors)[0]->[0], ($src->copy_ancestors)[0]->[1]);
	    $self->{rev} = $which_rev_we_branch;
	    $src = $self->arg_uri_maybe($depot_root.'/'.$which_depotpath);
	    $self->{message} = "- Create branch $src_branch_path to $dst_branch_path";
	    if ($self->{check_only}) {
		$logger->info(
		    loc ("We will copy branch %1 to %2", $src_branch_path, $dst_branch_path)
		);
		$logger->info(
		    loc ("Then do a smerge on %1", $dst_branch_path)
		);



( run in 0.971 second using v1.01-cache-2.11-cpan-ceb78f64989 )