<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pontus Östlund &#187; Subversion</title>
	<atom:link href="http://www.poppa.se/blog/tag/subversion/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.poppa.se/blog</link>
	<description>My blog about web development and such</description>
	<lastBuildDate>Mon, 16 Jan 2012 00:38:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Script for adding all new files in a SVN repository</title>
		<link>http://www.poppa.se/blog/svn-script-for-adding/</link>
		<comments>http://www.poppa.se/blog/svn-script-for-adding/#comments</comments>
		<pubDate>Thu, 26 Jul 2007 19:14:15 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=138</guid>
		<description><![CDATA[When working with revision controlled stuff you sometimes add loads of new files to an already existing repository. Then when you are about to check in the next revision you have forgotten where all the new files are and you probably don&#8217;t feel like writing svn add thefile too many times. This is of course [...]]]></description>
			<content:encoded><![CDATA[<p>When working with revision controlled stuff you sometimes add loads of new files to an already existing repository. Then when you are about to check in the next revision you have forgotten where all the new files are and you probably don&#8217;t feel like writing <code>svn add thefile</code> too many times. This is of course no problem if you&#8217;r using a decent SVN client &#8211; like Tortoise SVN on Windows &#8211; but I prefer the command line so the solution was writing a script that adds all new files in a directory structure to the SVN repository.</p>
<p>There are &#8220;one liners&#8221; for this but I wanted a bit more flexibility and ease of use so I wrote the a script that also lets you define regexp patterns for files you don&#8217;t want to add even if they exist in the directory structure.</p>
<p>This is how to use it:</p>
<pre><code lang='shell'># Add all new files
svnadd path/to/repository/
# Add all new files except those matching the regexp
svnadd -s ".*.txt|tmp/.*" path/to/repository/
# Add all new files except those matching the regexp in
# the file defined by the "-f" flag
svnadd -f regexp.txt path/to/repository/</code></pre>
<p>Quite easy! If you don&#8217;t feel like remembering the pattern for files to skip, put the regexp in a file and use the <code>svn add thefile</code> flag.</p>
<pre><code lang='shell'>#!/bin/bash
##########################################################################
#
# Script for adding all new files in a directory structure to an SVN
# repository.
#
# copyright © 2007 Pontus Östlund <spam@poppa.se>
#
# The svnadd script is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# The svnadd script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
##########################################################################

while getopts "s:f:h" opts
do
  case $opts in
    s) skip="$OPTARG";;
    f) if [ -f "$OPTARG" ]; then
         skip=$(head -n 1 $OPTARG)
       else
         echo "$OPTARG doesn't exist!"
       fi
       ;;
    h) help=1;;
  esac
done

shift $(($OPTIND - 1))

if [ -z $1 ] || [ "$help" ]; then
  echo "About: svnadd enables you to add all new files in [dir] to a "
       "subversion repository"
  echo "Usage: svnadd [flags] [dir]"
  echo
  echo "  -s
<pattern>  Regexp pattern for files to skip"
  echo "  -f
<path>     Path to file containing regexp for files to skip"
  echo "                The regexp should be placed in line one!"
  echo "  [dir]         The path to the repository"
  echo
  echo "Example: svnadd svnsrc/"
  echo "Example: svnadd -s 'tmp/.*.xml' svnsrc/"
  echo "Example: svnadd -f regexp.txt svnsrc/"
  echo

  exit 0
fi

dir=$1

if [ ! -d "$dir" ]; then
  echo "$dir is not a directory"
  exit 1
fi

while read status file; do
  if [ "$status" = "?" ]; then
    res=$( echo "$file" | egrep -o "$skip" )
    if [ -z "$res" ]; then
      svn add "$file"
    fi
  fi
done<<EOF
$( svn st "$dir" )
EOF

exit 0</code></pre>
<h2>Download</h2>
<p><a href='/blog/data/scripts/svnadd'>svnadd</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/svn-script-for-adding/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

