Heavymind
Gdyby ludzie rozmawiali tylko o tym, co rozumieją, zapadłaby nad światem wielka cisza.

29/08/2007

The nightmare has returned with new name: svn:ignore

Opublikowane jako: Subversion — Tags: , — Kubek Bartosz @ 21:53

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.



Komentarze: 13 »

  1. 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

  2. @Petri Sirkkala: You right, this is also an option that I haven’t mention it.

    Komentarz od Kubek Bartosz — 04/01/2008 @ 20:00

  3. […] Heavymind Share and […]

    Pingback od How to exclude/ignore a directory from SVN? - Techie Corner — 13/08/2008 @ 03:32

  4. To edit the svn prop fiel for the current directory, do this:

    svn propedit svn:ignore .

    your editor will launch thereafter and just add * to the file and save

    Komentarz od Brandon Teo — 16/01/2009 @ 05:39

  5. What do you do when you want to ignore two or three files/dirs and pattern matching doesn’t make sense? Here’s how I found out: So I had these directories MathML/ and mails/ in my current directory which I wanted svn to ignore. This was my first day with svn so although I had read about propedit, I only remembered propset. Some (logical) experimentation:
    $ svn propset svn:ignore ‘MathML mails’ .
    $ svn status
    M .
    ? MathML
    ? mails
    A Epi-Curves.nb
    A n-D-Curves.nb
    No joy. How about (dirs separated by `,”)
    $ svn propset svn:ignore ‘MathML, mails’ .
    $ svn status
    M .
    ? MathML
    ? mails
    A Epi-Curves.nb
    A n-D-Curves.nb
    Nope! referring to the svn book,
    “When found on a versioned directory, the svn:ignore property is expected to contain a list of newline-delimited file patterns that Subversion should use to determine ignorable objects in that same directory.” So the devil in this detail is the “newline-delimited” requirement. Hmm, how do you get a newline on the command line? well, you quote them. will quote the and you will see ^M in it’s place. So here we go:
    $ svn propset svn:ignore ‘MathML^Mmails’ .
    $ svn propget svn:ignore
    MathML
    mails
    and simply to admire our handy work
    svn status
    M .
    A Epi-Curves.nb
    A n-D-Curves.nb
    gone, chole-gache !
    Btw, the quote character in emacs is M-q (or is it C-q ?) find that useful occasionally …

    Komentarz od Ritesh Sood — 23/03/2009 @ 12:46

  6. Never ever use ” as delimiters when publishing on the web, the markup engine will gobble them up. The following line in my above post
    “will quote the and you will see ^M in it’s place.”
    should actually be
    “(Ctrl-V)(Enter) will quote the (Enter) and you will see ^M in it’s place.”
    I had initially typed ” where you now see ‘(’ , ‘)’

    Komentarz od Ritesh Sood — 23/03/2009 @ 12:56

  7. to setup directories recursive use -R:

    svn propset svn:ignore ‘*’ sess/ -R

    Komentarz od Recursive — 23/04/2009 @ 15:47

  8. Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

    Komentarz od sandrar — 11/09/2009 @ 00:34

  9. Brilliant article, the explanation couldn’t be any more clear! Tnx a lot (-:

    Komentarz od Phunkk — 16/10/2009 @ 11:10

  10. Bardzo pomocne, dzieki !

    Komentarz od ArturR — 14/01/2010 @ 20:46

  11. Thanks for the tip!
    Previously I was trying to set in such way: svn propset svn:ignore “*”, but no luck. With dot at the end this works fine. Thanks again!

    Komentarz od Snowcore — 19/08/2010 @ 11:21

  12. […] Me dei conta do meu erro depois der esse link http://www.heavymind.net/2007/08/29/the-nightmare-has-returned-with-new-name-svnignore/ […]

    Pingback od Dicas sobre Subversion « Procedimentos e Funções — 11/02/2011 @ 17:38

  13. Hi,

    Thank you. Your findings has helped me with using Subversion.

    Much Appreciated,
    Ravi.

    Komentarz od Ravi Gehlot — 15/06/2013 @ 19:50

Kanał RSS dla tego wpisu. TrackBack URL

Dodaj komentarz

Oparte na WordPress