40

I finally got my group to switch from SourceSafe to Subversion. Unfortunately, my manager still wants to use exclusive locks on every single file. So I set the svn:needs-lock property on every file and created a pre-commit hook to make sure the property stays set.

We are running Subversion on a Linux server. Most of us use Windows machines and a few use Macs. We are using various SVN clients (TortoiseSVN, SmartSVN, Subclipse, etc.).

What we now need is a good/easy method to see all the files that are currently locked in the entire repository (and who has them locked). I have poked around a little in Tortoise and Subclipse, but haven't found what I am looking for. Our projects have many subdirectories that are multiple levels deep, so it would be too time consuming to look at each individual directory.

What I would like is a single report I can run that lists everything that is currently locked and who has it locked. What is the best way to get this type of information?

peterh
  • 11,875
  • 18
  • 85
  • 108
Shane
  • 2,629
  • 6
  • 32
  • 39
  • 5
    I know you know this, but these locks are going to be a productivity killer in shared areas of the code. Merging tools are pretty good now and merging changes together is easier than your boss seems to think. – Tom Leys Nov 12 '08 at 19:07
  • 1
    @TomLeys You may have right in case of source code, or in any good mergeable file type. But it is not always so, for example sometimes SVN is used for managing data files or office documents, none of them has easily reachable, widely used merge tools. – peterh Apr 26 '16 at 14:56
  • How about merging Informatica files (stored as xml) on SVN? I guess the only way out is svn lock...isn't it? – Tarmit Jan 04 '17 at 13:57

4 Answers4

34

What you're looking for is the svnadmin lslocks command.

I have this set up at work because we keep some Word documents in our Subversion repository (with svn:needs-lock). I have a cron job set up that every day, checks the list of locks and emails a report of all locks older than 7 days to the whole team. That way we can tell who has been slacking and sitting on a locked copy of a document for a long time.

bahrep
  • 29,961
  • 12
  • 103
  • 150
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 1
    Office 2003 has built in merging of word documents now. I don't know when this feature was introduced, but it might mean you no longer need to lock your word documents. – Tom Leys Nov 12 '08 at 19:06
  • Thanks Greg. As a follow-up, can you tell me how you make the list show only locks older than x days? – Shane Nov 13 '08 at 16:39
  • I just wrote a script that parses the output of "svnadmin lslocks", looks at the Created date for each lock, and calculates the number of days from that. My actual script is at work and I don't have access to it at the moment, but it should be easy enough to figure out. – Greg Hewgill Nov 13 '08 at 19:03
22

To see what locks you and others hold, you can use TortoiseSVN → Check for Modifications.... Locally held lock tokens show up immediately. To check for locks held by others (and to see if any of your locks are broken or stolen) you need to click on Check Repository.

22

This might not be the answer you're looking for, but you should try to convince the manager that locks are actually not the best development practice. There's lots out there that's been written on this subject, so I won't repeat it all here.

When you go from a locking environment to one with no enforced checkout locks, at first you think it will lead to chaos, but it really doesn't. SVN is good at merging changes when two people are working on the same file, and even if you end up with conflicts, it's not so bad to fix them.

Much better than waiting around for the guy who went to lunch with a critical file checked out, or worse yet, went on vacation.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
Eric Z Beard
  • 37,669
  • 27
  • 100
  • 145
  • 3
    I'm trying to take it one step at a time. Just getting the group off of SourceSafe was a battle. Once they are comfortable with SVN, then I plan to tackle dropping the exclusive locking. – Shane Nov 13 '08 at 16:48
  • 3
    Locks are invaluable when working on binary files that cannot trivially be merged or diffed, like Microsoft Office documents. – DanB Sep 30 '14 at 00:30
22

You can discover locks from a local checkout using svn status --show-updates which will put an O before all files which are locked on the server.

e.g.

$ svn status --show-updates
     O      279532   LockedFile
?                    UncommittedFile
M           279532   ModifiedFile

see the svnbook for more details

ashirley
  • 1,148
  • 1
  • 12
  • 19