1

Problem description

I have a SVN repository for my scripts. Recently, I've noticed that most of my scripts have a lot of common fragments of code (i.a. parsing options) so I decided to create a simple script that will be used as a template. Then, I will be able to use svn copy to create new scripts from it. It will allow me to make improvements only to the template file and apply changes to all scripts via command svn merge.

Now, I would like to link already existing script to the template so I can svn merge on them too. I tried the command svn merge -r 0:HEAD ^/template ./old-script. It seemed to work. It recorded a correct-looking mergeinfo. Unfortunately, SVN still doesn't understand that these file are supposed to be related. When I try to execute svn merge ^/template ./old-script to transfer some new changes, SVN shows error: svn: E195016: 'svn://localhost/test/template@42' must be ancestrally related to 'svn://localhost/test/old-script@41'.

How can I tell SVN to treat the old-script as if it was svn copy from the template?

Steps to reproduce

I've prepared a POSIX scripts that reproduces this situation in a new repository:

#!/bin/sh

printf 'Creating unrelated files...\n'
printf 'aaa\n' >./aaa
printf 'bbb\n' >./bbb
svn add ./aaa ./bbb
svn commit --message 'Created unrelated files.'

printf '\nMaking change in aaa so it can be merged to bbb...\n'
printf 'aaa\n' >>./aaa
svn commit --message 'Changed aaa.'

printf '\nMerging aaa to bbb...\n'
svn merge ^/aaa ./bbb --revision 0:HEAD --accept=postpone
printf 'aaa\nbbb\n' >./bbb
svn resolve --accept=working ./bbb
svn commit --message 'Merged aaa to bbb. Files should be related now.'

printf '\nMaking another change in aaa...\n'
printf 'aaaaaa\n' >>./aaa
svn commit --message 'Changed aaa again.'

printf '\nPrinting mergeinfo of bbb...\n'
svn propget svn:mergeinfo ./bbb

printf '\nTrying to merge aaa to bbb again...\n'
svn merge ^/aaa ./bbb  # Why is it not working?

Running this script gives the following result:

Creating unrelated files...
A         aaa
A         bbb
Adding         aaa
Adding         bbb
Transmitting file data ..done
Committing transaction...
Committed revision 1.

Making change in aaa so it can be merged to bbb...
Sending        aaa
Transmitting file data .done
Committing transaction...
Committed revision 2.

Merging aaa to bbb...
--- Merging r2 into 'bbb':
C    bbb
--- Recording mergeinfo for merge of r2 into 'bbb':
 U   bbb
Summary of conflicts:
  Text conflicts: 1
Resolved conflicted state of 'bbb'
Sending        bbb
Transmitting file data .done
Committing transaction...
Committed revision 3.

Making another change in aaa...
Sending        aaa
Transmitting file data .done
Committing transaction...
Committed revision 4.

Printing mergeinfo of bbb...
/aaa:2

Trying to merge aaa to bbb again...
svn: E195016: 'svn://localhost/test/aaa@4' must be ancestrally related to 'svn://localhost/test/bbb@3'

I've found this information in the svnbook:

If Merge Tracking is active, then Subversion will internally track metadata (i.e. the svn:mergeinfo property) about merge operations when the two merge sources are ancestrally related—if the first source is an ancestor of the second or vice versa—this is guaranteed to be the case when using the first two forms. Subversion will also take preexisting merge metadata on the working copy target into account when determining what revisions to merge and in an effort to avoid repeat merges and needless conflicts it may only merge a subset of the requested ranges.

It seems to confirm that mergeinfo property indicates files being ancestrally related.

Piotr Siupa
  • 3,929
  • 2
  • 29
  • 65

0 Answers0