Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting branch reintegration or merge in pre-commit script

Within a pre-commit script, is it possible (and if so, how) to identify commits stemming from an svn merge?

svnlook changed ... shows files that have changed, but does not differentiate between merges and manual edits.

Ideally, I would also like to differentiate between a standard merge and a merge --reintegrate.

Background:

I'm exploring the possibility of using pre-commit hooks to enforce SVN usage policies for our project.

One of the policies state that some directories (such as /trunk) should not be modified directly, and changed only through the reintegration of feature branches. The pre-commit script would therefore reject all changes made to these directories apart from branch reintegrations.

Any ideas?


Update:

I've explored the svnlook command, and the closest I've got is to detect and parse changes to the svn:mergeinfo property of the directory. This approach has some drawback:

  1. svnlook can flag up a change in properties, but not which property was changed. (a diff with the proplist of the previous revision is required)
  2. By inspecting changes in svn:mergeinfo, it is possible to detect that svn merge was run. However, there is no way to determine if the commits are purely a result of the merge. Changes manually made after the merge will go undetected. (related post: Diff transaction tree against another path/revision)
like image 892
Shawn Chin Avatar asked Jan 09 '12 15:01

Shawn Chin


2 Answers

unfortunately subversion does not enforce merge only commits

if i have access to a branch, i can do whatever after merge and before commit

also subversion merge happens on client side

lot of code repository tools will merge on server. i.e. enforce that you are only moving patches from one stream to another

like image 69
Kalpesh Soni Avatar answered Sep 18 '22 18:09

Kalpesh Soni


I've eventually resorted to a non-ideal solution, i.e. detecting changes in the svn:mergeinfo property in the top directory of the changes tree (implemented in SVNTransaction.is_merge_operation()).

We cannot differentiate between merge-only commits and commits that also include additional changes. This means all changes that occur under that tree will go undetected if committed along with a merge. A possible solution might be to diff the transaction tree against the merge source but I have not figured out how to achieve that yet (this will also need to take into account changes as a result of conflict resolutions).

It also cannot differentiate between a merge and a merge --reintegrate.

Other limitations include the reliance on svn:mergeinfo which is user-modifiable and not used in older version of subversion.

The commit scripts in question is meant as a gentle reminder to flag commits that go against project guidelines rather than an access control mechanism, so the limitations listed above is not a show-stopper. However, I'm still on a lookout for improvements. Comments and further suggestions welcome.

like image 34
Shawn Chin Avatar answered Sep 18 '22 18:09

Shawn Chin