SVN Auto Commit

This is a dirty hack to use SVN as FTP with version control. You don't want to do that unless you don't care about the benefits of the version control system. On slower systems it tends to consume way to much resources.

by humancoder 2 years ago and tagged with: bash cron svn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# 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
# You need to set-up a "path" file in the same directory as the script in this form:
# /absolute/working-copy/|https://repository-path/
#
# Known 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

script_path="/home/sasha/Scripts/"
paths_file="/home/sasha/Scripts/svn-paths"

while [ true ]; do
	message="*Auto-message*"
	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)" $local_path >/dev/null 2>>"$script_path"commit_log
			fi
			# 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 add $add_files>/dev/null 2>/dev/null # Add new files if there are any
				svn commit --non-interactive -m "$message (add)" $local_path >/dev/null 2>>"$script_path"commit_log # Finaly commit
			fi
			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
		fi
	done
	sleep 1
done

Currently 0 comments

To post a comment, you must login.