03.26.08

Adding Files to Subversion without Ignoring svn:ignore

Posted by ryan in linux


While writing a script today to automatically add files to a local repository, I ran across a curious behavior of Subversion. Specifically, while using svn:ignore on certain files, those files were then still added via the command svn add *. In other words, the 'ignored' files were being added as if there weren't 'ignored' at all. However, svn status displayed their ignored status perfectly. Here is the setup:

  $ mkdir new_dir
  $ svn add new_dir
  $ touch new_dir/file-for-repo new_dir/file-to-be-ignored
  $
  $ ls new_dir/
    file-for-repo  file-to-be-ignored
  $ svn status new_dir
    ?      new_dir/file-for-repo
    ?      new_dir/file-to-be-ignored
    A      new_dir
  $ svn propset svn:ignore file-to-be-ignored new_dir
  $ svn status new_dir
    ?      new_dir/file-for-repo
    A      new_dir    .

We're in good shape up to this point. We've added a new directory with 2 new files. We went ahead and added the svn:ignore property for one of the files. As you can see, the svn status properly shows that the file is to be ignored. Now consider this:

  $ svn add new_dir/*
    A         new_dir/file-for-repo
    A         new_dir/file-to-be-ignored

And there it is. While I use the wild card (*) to mean all files in the directory, I expected that the svn:ignore files to be removed from that list. I read one explanation that said that the wild card operator is interpreted by linux as ALL files, who aptly returns the full file list to subversion, which just goes on its merry way adding all the files. This isn't a bug on subversion, however. Instead, the above method (the svn add line) is the incorrect way to handle these situations. The correct method is to do the following in place of the above svn add command.

  $ svn add new_dir --force
    A         new_dir/file-for-repo

Perfect. To get around the use of the wild card, we simple re-add the entire 'new_dir' directory. Normally this would throw the error:

"svn: warning: 'new_dir' is already under version control"

but the --force option tells it to go ahead and add everything anyways.

Thanks for the shares!
  • StumbleUpon
  • Sphinn
  • del.icio.us
  • Facebook
  • TwitThis
  • Google
  • Reddit
  • Digg
  • MisterWong
Posted by ozmrb on 2010-03-17
If not a bug - then a design flaw.
I'd rather type 'svn add *' than 'svn add . --force'. Call me lazy... ;)
Posted by Alok on 2010-05-27
This IS a bug. Design flaws are most common bugs I see.
Posted by Rikki Prince on 2010-07-27
I don't know if behaviour has changed since you wrote this, or if I have an odd version of SVN, but my SVN automatically recurses the directory when I do:
svn add new_dir/

To avoid this, I had to do:
svn add -N new_dir/

Had me puzzled for a little while, so thought I'd put it here for anyone else that comes across this.

Leave a reply

Enter the text you see here

saving...