tags:

views:

56

answers:

3

I'm trying

svn add *.py --force

As the documentation suggests, but I know for a fact it's missing files nested in deeper folders. Why?

Is there a standard way to do this with other unix commands too? */*.py will nab a few more files, but it's kind of a pain in the butt to do this for every possible depth.

+3  A: 

The find command is the trick to dig out the files you want.

find . -name "*.py" -exec svn add --parents {} ';'

And there's about a million ways to do it, all of which are educational in their own right.

# if you want to make sure you don't find files in your .svn directories
find . -name .svn -prune -o -name "*.py" -exec svn add --parents {} ';'

# execs svn only once; probably a bit faster.
# -print0 and -0 avoid problems if files have spaces in names
find . -name .svn -prune -o -name "*.py" -print0 | xargs -0 exec svn add --parents {} ';'
dave
+1  A: 

As the other person noted with the find command I use svn status. Used as thus

>svn status
?       private/Config.my.php
?       private/log/word_failure
?       private/log/db_err_log.txt
?       private/import/client2
M       public/reports/ReadyForMeeting.report.php
?       public/tools/Connection.class.php.good
M       public/tools/FieldNode.class.php
M       public/tools/PageBuilderForm.class.php
M       public/domain/Report_Setup_Parameter.class.php
M       public/domain/Report_Setup_Page.class.php
M       public/modules/mAdmin/mManageUsers.module.php
M       public/modules/mAdmin.module.php
M       public/modules/mAppraiserSetup.module.php
?       public/js/firebug-lite.js
?       public/js/lang_en-us.js
?       public/js/_composite.js
?       public/js/lang_en.js
M       public/js/uniValidate.js

Ahh see all those with a status of ? that means that they are in the filesystem but not committed. Therefore, I add all php files like thus.

> svn status | grep ^\? | awk '{ print $2 }'  | grep .*php$ | xargs svn add

Or If I wanted to add php python and js files this would work

> svn status | grep ^\? | awk '{ print $2 }'  | egrep ".*php$|.*py$|.*js$" | xargs svn add

'svn status' would then be the best answer to me. This way only what HAS NOT been added to the repo will be selected.
Just as often though, what I do is just go through and delete what I do not want in the repo (why is it there anyways) and then I execute, thus getting all helper images and such.

> svn status | grep ^\? | awk '{ print $2 }' | xargs svn add

Find is a good solution too, this just requires less thinking. And is also not nearly as greedy. Plus if you're on windows then some variation of this would work. Namely take the output of svn status and hack up a short batch file.
Good Luck!

flaxeater
That's pretty cool, but what if the folder isn't versioned? It ignored an entirely new folder I had.
Mark
Gotta say that does surprise me. The regex needs to be modified to include bare directories too. I don't really see an obvious way to do that, you _could_ get rid of the regex filter. I think at the end of the day there's no substitute for good old fashioned paying attention :)
flaxeater
I don't think it's the regex filter... pretty sure `svn status` just won't list unversioned directories.
Mark
A: 
find . ! -wholename ./settings.py | grep -P ".*\.(py|html)$" | xargs -d "\n" svn add
Mark