It's possible to make Subversion ignore unversioned files, so they don't show up in the status overview and you get a better signal to noise ratio. The command line interface to add ignore rules this is however a bit clunky. First, you need to remember following command:
svn propedit svn:ignore .
(which can be quite confusing, especially with the slightly similar looking but different propset command).
Then you get a file editor where you have to add the rule (make sure you remembered the file name or pattern you want to ignore), save the file and exit the editor.
A bit too much hoops to jump through for something that could be just one command like svn-ignore filename.
I wrote this simple python script to get this functionality:
#!/usr/bin/env python """ Script to make it easier to add svn-ignore rules. """ import sys import os import subprocess def svn_propget_svnignore(path): '''fetch the svn:ignore property of given path''' p = subprocess.Popen(['svn', 'propget', 'svn:ignore', path], stdout=subprocess.PIPE) p.wait() data = p.stdout.read().strip() return data def svn_propset_svnignore(path, value): '''set the svn:ignore property of the given path''' p = subprocess.Popen(['svn', 'propset', 'svn:ignore', value, path]) p.wait() def main(): if len(sys.argv) < 2: print 'Usage: %s filenames' % sys.argv[0] sys.exit() for path in sys.argv[1:]: print path dirpath, filename = os.path.split(path) svnignore_data = svn_propget_svnignore(dirpath) if filename not in svnignore_data.split('\n'): svnignore_data += '\n' + filename svn_propset_svnignore(dirpath, svnignore_data) if __name__ == '__main__': main()
I saved it as svn-ignore.py, made it executable, put it somewhere in my PATH and now I can just do
svn-ignore.py foo.txt bar.zzs "*.backup"
Note that it also supports wildcard rules, but these have to be put in quotes, so the shell does not expands them.
script
nice script it help alot!
Works great for me, no bugs
Works great for me, no bugs showed.
good and useful scripts
good and useful scripts
little bug!
Files that partialy match a filename already added are not
added, so I propose a little correction:
Thanks for this nice script anyway!
fixed
Yep, I noticed it too.
Should be fixed now
Bug when similiar name already in proplist
Files that partialy matches filename already added are not
added, so I add a little correction:
if '\n'+filename+'\n' not in '\n'+svnignore_data+'\n':
Thanks for this nice script
Nice script ...
... but the subprocess module is only available for Python >= 2.4. Anyway, you can replace the subprocess.Popen function with os.Popen.
Cheers
Pieter-Jan
Got confused also
nice script, but a little confusing where python said. got it right though
Blacktackle
I just discovered that i already had a similar script ...
Have a look at http://www.cubewano.org/blacktackle
Greetz
Handy script
That's indeed a lot handier than the propedit thing.
In fact i even managed to get confused because i was adding multiple ignore patterns in a row like
/> svn propset svn:ignore files
/> svn propset svn:ignore .project
/> svn propset svn:ignore .cache
...
It took me some minutes to discover that this command does not ADD extra ignore patterns, it just sets an new one, so only the last pattern was retained.. Hence the need for
/> svn propedit svn:ignore
I just added your script to my growing list of handy (drupal) scripts.
Thanks.
Post new comment