Setting file permissions in subversion
Ever since I started using github for hosting I have started to dislike SVN. Don’t get me wrong, its still very useful and easy to understand but as a developer I don’t want something that is easy to understand (infact I won’t be able to use such a tool) but I want something that works well. Today I found a little gem of a tip hidden on SO related to SVN.
One of our new builds was setup yesterday and it just refused to run giving an error saying that the shell script it was trying to execute did not correct permissions. Hmm, odd, this works on windows. (Ofcourse it does, you don’t execute .sh scripts on windows! Duh!) It was obvious that the scripts permissions needed to be changed with `chmod +x script.sh`.
I did that and ran a `svn diff`. No changes. Hmm, that’s odd, I just changed a file, shouldn’t it see this as a change and show me a diff… Apparently not. Subversion does not store file permissions so then how can I make it checkout the correct permissions for scripts that need them?
I thought about this for a few minutes and was about to give up and just run chmod via ant builder in a groovy script when I thought to look this up on SO. The same question has been asked before. And it has just the answer I was looking for, though buried under a few other no-so-useful answers.
For the lazy ones, you need to set a property “svn:executable” on the file where you want to set files to be executable. Subversion then maintains this bit and passes this onto the operating system. Not as flexible as just maintaining the original permissions but it works. Here is the explanation of the property from the svnbook:
svn:executable
The svn:executable property is used to control a versioned file’s filesystem-level execute permission bit in a semi-automated way. This property has no defined values—its mere presence indicates a desire that the execute permission bit be kept enabled by Subversion. Removing this property will restore full control of the execute bit back to the operating system.
On many operating systems, the ability to execute a file as a command is governed by the presence of an execute permission bit. This bit usually defaults to being disabled, and must be explicitly enabled by the user for each file that needs it. In a working copy, new files are being created all the time as new versions of existing files are received during an update. This means that you might enable the execute bit on a file, then update your working copy, and if that file was changed as part of the update, its execute bit might get disabled. So, Subversion provides the svn:executable property as a way to keep the execute bit enabled.
This property has no effect on filesystems that have no concept of an executable permission bit, such as FAT32 and NTFS. [28] Also, although it has no defined values, Subversion will force its value to * when setting this property. Finally, this property is valid only on files, not on directories.
No related posts.

