views:

916

answers:

7

Hi,

I'm looking for a way to make an exclusive checkout from SVN.

  1. Is there a way to automatically lock a file when it's being checked out ?

  2. If one user makes an exclusive checkout, and then another user makes a checkout to the same file, how do I generate some sort of notification or an instant message to the 2nd user that the file is locked?

thank you, Oded.

+1  A: 

One of the biggest reasons with version control is that many people can work on the same file at the same time... Why do you want to have an exclusive lock instead of letting other people merge with your changes upon commit?

PatrikAkerstrand
+4  A: 

You can use svn lock to prevent other users checking changes back in (note that you can use --force to take a lock from another user). This will generate messages on the command line telling people who's locked that file.

It's not common to do this. People work with SVN by checking out copies (non-exclusively) and writing back changes which are merged with other changes (this occurs for mergeable formats like text - you can't do this for binaries and a checkin will be rejected if another checkin has occurred in the meantime).

I would not expect this to be used regularly, and I normally rely on a) svn's merging capability b) communication with other team members to ensure I'm not treading on other people's toes.

Brian Agnew
I agree that communication is the better first choice, but just one note: if you are the administrator of the repo, you can make locks stronger by using the `pre-unlock` repository hook. I'm not really recommending it for normal use, but I can imagine cases where it might be useful or necessary.
Telemachus
+3  A: 

If I understand your follow-up posts, what I think you really want is to make sure that people know about locks. I'm imagining a case where users A and B have already checked out a jpeg. User A now locks it, and you want to make sure that user B knows, so that he or she doesn't begin editing the jpeg and wasting time and effort.

If that's correct, I recommend two things: first and foremost, communication (not very technical, but very powerful when used consistently); second, you might take a look at the post-lock repository hook for svn. You can use that to have emails sent when someone puts a lock on a file.

From the subversion book:

The post-lock hook runs after one or more paths have been locked. It is typically used to send email notification of the lock event.

Telemachus
If you follow that logic and process (e.g. an image file must always be locked before editing), you will not get into the problem! When you try to lock the file it will warn you that a lock (and reason for the lock) is already in place. If you use the svn:needs-lock property it enforces a lock policy on that file or type of file
Alex
In your example, if User B tries to edit the jpeg without placing a lock then he/she is not following process
Alex
+1  A: 

You are all correct.

But the problem I'm facing, for example, JPEG file (merging is not possible). If user A checks it out and edits the file. and a minute later user B checks it out, I don't want him to start editing because he can't commit it back. (because the fuile is not "mergible").

Oded
Fair enough: so for such a case, put a lock on the file. But have a talk with other people working on the project about respecting locks on binary files and communicating. That should work fine, assuming everyone is reasonable.
Telemachus
Yeah, this is pretty much _the_ reason exclusive checkouts exist in SVN. When there's some sort of unmergeable binary.
Greg D
+2  A: 

You can add the property or auto-prop svn:needs-lock which makes the file read-only and requires you to place a lock on the file to edit it.

If you are using TortoiseSVN you will see a different icon for locked files, this should be easy for a second user to see and know not to edit the file.

Referenced in TortoiseSVN documentation

Alex
+1 this should be the accepted answer
Wim Coenen
A: 

You are correct, but I can't rely on a user seeing an icon. I want a massage or a warning to be displayed somehow.

and still , a user can start editing and not knowing he can't commit.

Oded
Don't post new answers to respond to people. Make your responses comments on individual answers. Like this :)
Telemachus
A: 

You understood me correctly, and I think your idea might work! I will give it a shot...

thank you.

Oded
Dude: comments, not new posts.
Telemachus
Oh, and you're welcome.
Telemachus
sorry.....thanks :)
Oded