The nightmare has returned with new name: svn:ignore
During a time of last week I’ve tried to properly set up of subversion project repository that I’m responsible of. The most important thing I had to do was to exclude all content from repository, that is not a static part of the project. What I mean is a directories and files that contains miscellaneous logs, cache or sessions data. Unfortunately it was another nightmare, cause I’ve found this task very complicated. So as once before, I’d like to share with You about my experiments, to prevent You of wasting time as I did. I’m writing it especially that You will not easily “google” a question : “how to ignore directories in SVN” and get satisfy result.
I’d like to mention, that I’m using most up to date SVN client in shell command line (debian linux). So let me introduce You to the structure. Lets assume that we have an SVN repository with a complete directories and files structure of our project. I will talk about a small part of the repository. A part that looks this way:
/logs/ /logs/sess/ /logs/sess/14/ /logs/sess/14/data.dat /logs/sess/17/ /logs/sess/17/data.dat /logs/logins/ /logs/registers/
This part of project directories structure exists in repository, as well as in my local copy of this repository (for example in: /home/my_proj/logs/…. but the absolute path have nothing to do with us). So my point is to exclude from repository all directories, that are created dynamically in logs/sess/ directory, such as “14/” and “17/”. This can be simple made by:
/logs/$ svn delete sess/* D sess\14\format D sess\14\format_as D sess\14 D sess\17\format D sess\17\format_as D sess\17 /logs/$ svn ci -m "*deleted remotely" Deleting logs\sess\14 Deleting logs\sess\17
Ok, so now we have dropped not needed directories with all depending files from SVN repository. After this we’ve send our changes to svn server.
But this is only a temporary solution, cause if the ‘dynamic content’ will be created again, for example (lest create them manually):
/logs/sess/22/ /logs/sess/25/
…than again we will see them as new items on our project files list:
/logs/$ svn status ? /sess/22 ? /sess/25
The question mark sign ‘?’ means that there are new items in oru project structure, that need to be added to the repository, or deleted - as we wish.
At this moment, I’d like to remind, that our point is to create a configuration, when any new directory or file in sess/ directory will be ignored by svn, so the ’svn status’ will not inform us about files, that we don’t wont to carry about.
In this case I’ll use ’svn propset’ command with proper parameters to instruct repository, that everything that is inside /logs/sess/ directory should be ignored with svn. First of all I’ll enter sess/ directory, where i want to set this property.
/logs/$ cd sess/ /logs/sess/$ svn propset svn:ignore '*' .
This syntax above is a product of many many hours I spent with learning svn theory and experiencing. What it exactly means is: “add ignore property to any (’*') content inside current (’.') directory”. Looks easy and intuitive, but it’s not in a fact.
Now, first of all please notice, that an asterisk sign (*) is typed inside of quotes: ‘*’. This is very important, cause without quotes, this could be not interpreted as “ignore every file or directory”, but as “apply ignore rule to every directory in current folder”. This is because an asterisk sign has also shell meaning. So instead of assigning svn:ignore property to “sess/” directory, this command would add it to all sub directories: “22/” and “25/” in case of not using quote marks. Tricky, isn’t it?
At second, there was an optional way to set the property. Not by changing directory to sess/ directory before set it, but by applying the property from logs/ directory with directing the property on the sess/ directory :
/logs/$ svn propset svn:ignore '*' sess/
This example will work exactly the same way.
And at least, third of all, it is important to remember, that excluding by ignoring will work properly only for content that is not currently under version controll - in repository. This is also critical requirement. So here comes out why our first move was to ’svn delete’ all content in repository that we where going to exclude for permanent. If this content would be still part of our branch, we simply couldn’t ignore it. It goes without saying.
I’m hopefully that some of You could find my example useful. I need to send an acknowledgments to Steffen, who made me spare with this. Thank You my friend.
Hi,
I would like to add that svn propset svn:ignore sess logs would also work. In that case even the sess directory won’t be in the repository.
Also it might be easyer to use svn propedit, which will use an editor. There no quotes are needed when using wildcard glob characters.
-Pete
Komentarz od Petri Sirkkala — 04/01/2008 @ 19:37
@Petri Sirkkala: You right, this is also an option that I haven’t mention it.
Komentarz od Kubek Bartosz — 04/01/2008 @ 20:00
[…] Heavymind Share and […]
Pingback od How to exclude/ignore a directory from SVN? - Techie Corner — 13/08/2008 @ 03:32