13

Sorry if this is a duplicate, I didn’t find the right answer still..

How do you lock a svn directory from command line? I need to lock a branch from checkins

Edit:
All of these answers I've found require the person to access the svn server. Thats not an option for me. I work in a company where the source control machine is literally locked in a vault. Gainning access to change auth rules is a process I can't work out ATM.

Quintin Par
  • 15,862
  • 27
  • 93
  • 146

3 Answers3

7

You can't lock a directory. You can create authorization rules that will prohibit write access to directories. This is typically how this type of thing is done. You could also use a pre-commit hook but I think Subversion's authz is best. Here is a link:

http://svnbook.red-bean.com/nightly/en/svn.serverconfig.pathbasedauthz.html

Jeremy Whitlock
  • 3,808
  • 26
  • 16
  • Is there a way to set this up via script and without having to edit the authz file? I need to BLOCK a directory temporarily to avoid accidental deletion (for instance when doing a svn rm operation). – runlevel0 Sep 05 '14 at 11:19
2

I recently solved this by a solution inspired by http://www.noah.org/engineering/olden/svn_directory_lock.html

The particular python script in that post is overkill, but I put the following in the pre-commit hook for my repsoitory:

#!/bin/sh

err() { echo ${1+"$@"} 1>&2; } # stderr is sent to user

REPOS="$1"
TXN="$2"

SVNLOOK=/usr/bin/svnlook

# Make sure there is a log message.
#
$SVNLOOK log -t "$TXN" "$REPOS" | grep -q "[a-zA-Z0-9]" 
if [ $? -eq 1 ]
then
  err "ERROR: Must enter a log message for this commit!"
  exit 1
fi

# Usage: locked_dir dir [transaction_id]
locked_dir()
{
  if [ -z "$2" ]; then _tid=""; else _tid="-t $2"; fi
  $SVNLOOK propget $_tid "$REPOS" lock "$1" >/dev/null 2>&1
  if [ $? -eq 0 ]; then echo true; else echo false; fi
}

for d in $($SVNLOOK dirs-changed -t "$TXN" "$REPOS")
do
  locked_before=$(locked_dir $d)
  locked_tx=$(locked_dir $d "$TXN")

  if [ $locked_before = $locked_tx -a $locked_tx = true  ]
  then
    err "ERROR: Directory $d is locked. Delete lock before you commit."
    exit 1
  fi
done

# All checks passed, so allow the commit.
exit 0

So now, you can simply use the "svn propset" and commit to create a "lock" property for a directory that you want to lock.

Kayvan Sylvan
  • 466
  • 4
  • 4
0

Here is an approach to lock a folder using a batch script.

  1. SVN check out the directory you want to lock using the command

svn checkout DIRECTORY_TO_LOCK_SVN_URL LOCAL_DIRECTORY

  1. Iterate over all files in the LOCAL_DIRECTORY and run the SVN lock command on each file.

Batch: iterate all files in a directory using a 'for' loop.

svn lock -m LOCK_MESSAGE FILE_PATH

  1. Clean up and delete LOCAL_DIRECTORY.
datchung
  • 3,778
  • 1
  • 28
  • 29