The problem in this is when the svn merge line is executed, the value of $status is always 0 whether there are conflicts or no.
That's not true. svn merge
will return a non-zero status if the merge didn't work at all. For example, you didn't have a clean working directory. svn merge
returns a non-zero value if the merge worked. And the merge works even if there are conflicts.
Do a --dry-run
first and open svn merge
as a file handle:
use strict;
use warnings; # I hope in your program, you're actually using these two pragmas
# No you aren't. :-(
# $dir = 'D:\Transversal Unit\example\ace__project\branches\UAT';
use feature qw(say);
use autodie;
my $dir = 'D:/Traversal Unit/example/ace__project/branches/UAT'; #Use forward slashes
open my $merge, '|-', "svn merge -c39,46 --dry-run $sourceBranchURL";
Now, you can read each line of output from your svn merge
command and see if you have problems:
my $conflict_found;
while ( my $line = <$merge> ) {
chomp $line;
if ( line =~ /^!/ ) {
say "Conflict found: $line";
$conflict_found = 1;
}
}
if ( $conflict_found ) {
die qq(Conflicts were found. Do this by hand...);
}
# No conflicts, rerun `svn merge` without `--dry-run`
...
This way, you can check for conflicts before you actually run the merge command. If there are no conflicts, you can (almost) safely do the merge without problems.
Remember that svn if there aren't conflicts doesn't mean the merge worked correctly. There may be a logical conflict even if the lines don't conflict:
Original file
line #1
line #2
line #3
line #4
print "Foo = " + foo
Change on trunk
line #1
line #2
line #3
foo = "bar"
line #4
print "Foo = " + foo
Change on branch
line #1
foo = "boof"
line #2
line #3
line #4
print "Foo = " + foo
I am assuming that setting foo
to bar
on trunk and boof
on the branch is a conflict. However, the merge will happily happen without conflicts:
line #1
foo = "boof"
line #2
line #3
foo = "bar"
line #4
print "Foo = " + foo