[svk-commit] r2833 - in trunk: t/bm

nobody at bestpractical.com nobody at bestpractical.com
Thu May 8 03:34:39 EDT 2008


Author: clsung
Date: Thu May  8 03:34:39 2008
New Revision: 2833

Modified:
   trunk/lib/SVK/Command/Branch.pm
   trunk/t/bm/online-offline.t

Log:
- implement the --online functionality 
  - ref: http://task.hm/EAKH

Modified: trunk/lib/SVK/Command/Branch.pm
==============================================================================
--- trunk/lib/SVK/Command/Branch.pm	(original)
+++ trunk/lib/SVK/Command/Branch.pm	Thu May  8 03:34:39 2008
@@ -681,7 +681,7 @@
 }
 
 package SVK::Command::Branch::online;
-use base qw( SVK::Command::Branch::move SVK::Command::Switch );
+use base qw( SVK::Command::Branch::move SVK::Command::Smerge SVK::Command::Switch );
 use SVK::I18N;
 use SVK::Logger;
 
@@ -691,28 +691,42 @@
     my ($self, $arg) = @_;
     my $target = $self->arg_co_maybe($arg || '');
     $self->{switch} = 1 if $target->isa('SVK::Path::Checkout');
-    # XXX: if the remote branch of the same name already exists, do a
-    # smerge instead
-    $self->{branch_name} = $target->_to_pclass($target->path)->dir_list(-1);
-
     # XXX: should we verbose the branch_name here?
 #    die loc ("Current branch '%1' already online\n", $self->{branch_name})
     die loc ("Current branch already online\n")
 	if (!$target->_to_pclass("/local")->subsumes($target->path));
 
+    # XXX: if the remote branch of the same name already exists, do a
+    # smerge instead
+    my $proj = $self->load_project($target);
+    $self->{branch_name} = $proj->branch_name($target->path, 1);
+
+    # check existence of remote branch
+    my $dst = $self->arg_depotpath($proj->branch_path($self->{branch_name}));
+    if ($SVN::Node::none != $dst->root->check_path($dst->path)) {
+	$self->{go_smerge} = $dst->depotpath if $target->related_to($dst);
+    }
+
     return ($target, $self->{branch_name}, $target->depotpath);
 }
 
 sub run {
     my ($self, $target, @args) = @_;
-    $self->SUPER::run($target, @args);
-    my $proj = $self->load_project($target);
-
-    my $newtarget = $target->mclone( path => '/'. $proj->branch_location . '/' . $self->{branch_name} )->refresh_revision;
 
-    # XXX: we have a little conflict in private hash argname.
-    $self->{rev} = undef;
-    $self->SVK::Command::Switch::run($newtarget, $target) if $target->isa('SVK::Path::Checkout');
+    if ($self->{go_smerge}) {
+	my $dst = $self->arg_depotpath($self->{go_smerge});
+	
+	$self->{message} = "- Merged from local";
+	$self->SVK::Command::Smerge::run($target->source, $dst);
+
+	$dst->refresh_revision;
+
+	# XXX: we have a little conflict in private hash argname.
+	$self->{rev} = undef;
+	$self->SVK::Command::Switch::run($dst, $target) if $target->isa('SVK::Path::Checkout');
+    } else {
+	$self->SUPER::run($target, @args);
+    }
 }
 
 package SVK::Command::Branch::offline;

Modified: trunk/t/bm/online-offline.t
==============================================================================
--- trunk/t/bm/online-offline.t	(original)
+++ trunk/t/bm/online-offline.t	Thu May  8 03:34:39 2008
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 use strict;
 use SVK::Test;
-plan tests => 9;
+plan tests => 12;
 our $output;
 
 my ($xd, $svk) = build_test('test');
@@ -42,6 +42,10 @@
 is_output_like ($svk, 'info', [],
    qr|Depot Path: //mirror/MyProject/branches/foo|);
 
+# since branch name is not the same, just do move and switch
+is_output ($svk, 'info', ['//local/MyProject/foo'],
+    ["Path //local/MyProject/foo does not exist."]);
+
 is_ancestor($svk, '//mirror/MyProject/branches/foo', '/mirror/MyProject/trunk', 6);
 
 
@@ -69,8 +73,15 @@
 append_file ('B/S/Q/qu', "\nappend CBA on local branch feature/foobar\n");
 $svk->commit ('-m', 'commit message','');
 
-# now should do push first, then sw to the branch 
+# now should do smerge first, then sw to the branch 
 $svk->br('--online');
 
+is_output_like ($svk, 'info', [],
+   qr|Depot Path: //mirror/MyProject/branches/feature/foobar|);
+
+# since there's the same branch name exists, just do smerge and switch
+is_output_like ($svk, 'info', ['//local/MyProject/feature/foobar'],
+   qr|Depot Path: //local/MyProject/feature/foobar|);
+
 # need more message to test
 }


More information about the svk-commit mailing list