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.