8
votes

Tags are implemented as branches in Subversion. Thus my question: after creating a Subversion tag - how do I close this branch such that no one adds changesets to that tag-branch by accident?

For example consider following directory layout:

calc+-trunk
    |-branches
    |-tags

At some point trunk is ready for release and is tagged:

$ svn cp svn://example.net/calc/trunk svn://example.net/calc/tags/v1.0

Now following accident might happen:

$ svn co svn://example.net/calc/tags/v1.0
$ cd v1.0
$ # change files
$ svn ci

(perhaps the above URL was copy'n'pasted and instead a branch was meant)

How can I close the branch calc/tags/v1.0 such that the last svn ci would fail?

I call it closing - alternatively you could call that operation switching a branch to read-only mode - or something like that.

2
Regarding the feature branches we have a rule in my company that we rename the branch to {old name}_closed. So we still know that we created a feature branch ( with a useful name) and closed it later after merging back.Bjoern

2 Answers

7
votes

You can control commits through a pre-commit hook. This one will allow you to create, but not edit tags. You can control the access to branches (preventing changes on them or keeping who can make a change to a select group of people).

I created the original copy when I realized that users could accidentally edit a tag without meaning to. I wanted a way where users could create tags, but couldn't modify a tag once it was created.

You control the hook through a control file (and that control file can even reside in the repository for easy access). The first line prevents anyone from writing to the /tags directory (or any sub directories). The second one allows users to copy a branch to a new tag, but they can't modify anything in that tag.

[FILE You cannot edit a tag once it's been created]
file = /tags/**
access = read-only
users = @ALL

[FILE You cannot edit a tag once it's been created]
file = /tags/*
access = add-only
users = @ALL

You can do the same thing in a branch. Here, the 2.2 branch is completely locked and only Bob and Carol can make changes to the 2.3 branch as it's getting ready for release:

[FILE No one is allowed to touch the 2.2 branch. It is dead]
file = /branches/2.2
access = read-only
users = @all

[FILE Only Bob and Carol can make changes to the 2.3 branch]
file = /branches/2.3/**
access = read-only
users = @ALL

[FILE Only Bob and Carol can make changes to the 2.3 branch]
file = /branches/2.3/**
access = read-write
users bob, carol
1
votes

You have three options, from easiest/fastest to most complex.

  1. Delete the branch (it's not really deleted, you can always retrieve it).
  2. Create a rule in your path-based authorization configuration file (assuming you use one) to deny writes to that path.
  3. Install (or modify, if one already exists) a pre-commit hook script to reject any commits to that path.