Over a million developers have joined DZone.

SVN Auto Commit Bash Script

DZone's Guide to

SVN Auto Commit Bash Script

Free Resource
A convenient way to make auto commits when the files change.
You need the svn client to make this script work.
Add it as a startup script and worry no more.

# Run commit every second.
# Why? Cron can't do that.
# This can be used combined with a post-commit hook to make a kind of a versioned FTP :P

# This script needs a initial checkout! A working copy must exist a priori!

# You need to set-up a "svn-path" file in the same directory as the script with one working copy a line
# /absolute/working-copy/
# /absolute/working-copy2/

# Bugs: 
# Sometimes when you work with someone else on the same file it can overwrite others modifications with yours without throwing a conflict
# Good thing it's svn and you can easily merge the modifications afterwards. Still this bug is annoying

# Change this to your paths

while [ true ]; do
	for local_path in `cat $paths_file| grep -v "#"`; do
		stat=`svn status $local_path`
		if [[ $stat != '' ]]; then #Are there any changes?
			delete_files=`echo $stat|grep -e "^\!"|cut -d" " -f2`
			if [[ $delete_files != '' ]]; then
				svn delete $delete_files>/dev/null 2>/dev/null
				svn commit --non-interactive -m "$message (delete)" $remote_url >/dev/null 2>>"$script_path"commit_log
			# Do we have any files to add
			add_files=`echo $stat|grep -e "^\?"|cut -d" " -f2`
			if [[ $add_files != '' ]]; then
				svn add $add_files >/dev/null 2>/dev/null # Add new files if there are any
				svn commit --non-interactive -m "$message (add)" $remote_url >/dev/null 2>>"$script_path"commit_log # Finaly commit
			svn update $local_path >/dev/null 2>>/dev/null #Checkout first
			svn commit --non-interactive -m "$message (modified)" $local_path >/dev/null 2>>"$script_path"commit_log # Finaly commit
	sleep 1

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}