<?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>Drop By! &#187; ivy</title>
	<atom:link href="http://www.rekk.de/bloggy/category/ivy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rekk.de/bloggy</link>
	<description>Dropping Brain Crumbs ...</description>
	<lastBuildDate>Wed, 09 Jun 2010 16:59:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Bash Script &#8211; Add &#124; Include only certain Files to Subversion Repository</title>
		<link>http://www.rekk.de/bloggy/2009/bash-script-add-include-only-certain-files-to-subversion-repository/</link>
		<comments>http://www.rekk.de/bloggy/2009/bash-script-add-include-only-certain-files-to-subversion-repository/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 10:43:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[build management]]></category>
		<category><![CDATA[ivy]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://www.rekk.de/bloggy/?p=122</guid>
		<description><![CDATA[Recently I had to face a limitation of subversion &#8211; you can set files and patterns for ignoring files (using svn:ignore) but you can not specify certain files or patterns for files to be included. In my situation, I wanted to build an Ivy repository and put only the ivy files under the version control [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had to face a limitation of subversion &#8211; you can set files and patterns for ignoring files (using svn:ignore) but you can not specify certain files or patterns for files to be included. In my situation, I wanted to build an <a href="http://ant.apache.org/ivy/">Ivy</a> repository and put only the ivy files under the version control cause all other artifacts could be rebuild using SCM.</p>
<p>So I came up with a simple bash script, which is run just before commit and is actually called from an ant script in a build environment:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># adds only certain files to repository, adds</span>
<span style="color: #666666; font-style: italic;"># all intermediate directories on their paths,</span>
<span style="color: #666666; font-style: italic;"># it also works with empty space in path (except newline)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># @todo Add some bells and whistles!</span>
&nbsp;
<span style="color: #007800;">REPO_NAME</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>some_repo<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Running $0 on&quot;</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #ff0000;">&quot;with <span style="color: #007800;">$REPO_NAME</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># this file will help to limit the search, if it's modified on commit</span>
<span style="color: #666666; font-style: italic;"># for example the log file of last commit, the idea here is to run </span>
<span style="color: #666666; font-style: italic;"># this script always before commit</span>
<span style="color: #007800;">REF_TIME_FILE</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>some_file<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #007800;">REP_PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>some<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>copies<span style="color: #000000; font-weight: bold;">/</span>root
&nbsp;
<span style="color: #007800;">FILE_PATTERN</span>=<span style="color: #ff0000;">'ivy.xml*'</span>
<span style="color: #007800;">DIR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$REP_PATH</span>
<span style="color: #007800;">IFS_ORIG</span>=<span style="color: #007800;">$IFS</span>
<span style="color: #666666; font-style: italic;"># this allows paths with whitespace, but not with newline</span>
<span style="color: #007800;">IFS</span>=$<span style="color: #ff0000;">'\n'</span>
<span style="color: #666666; font-style: italic;">#IFS=&quot;$(echo)&quot; another way to get newline</span>
<span style="color: #000000; font-weight: bold;">for</span> ivy <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-newer</span> <span style="color: #007800;">$REF_TIME_FILE</span>  <span style="color: #660033;">-type</span> f  <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILE_PATTERN</span>&quot;</span>  -print<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;found fresh file <span style="color: #007800;">$ivy</span>&quot;</span>
	<span style="color: #007800;">p</span>=<span style="color: #007800;">$ivy</span>
	<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$p</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">do</span> 
			<span style="color: #007800;">all_paths</span>=<span style="color: #800000;">${all_paths}</span><span style="color: #800000;">${del}</span><span style="color: #800000;">${p}</span>
			<span style="color: #007800;">p</span>=<span style="color: #800000;">${p%/*}</span>	
			<span style="color: #007800;">del</span>=:
	<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #007800;">IFS</span>=<span style="color: #007800;">$IFS_ORIG</span>
<span style="color: #666666; font-style: italic;">#echo $all_paths | tr ':' '\n' | sort | uniq |  tr '\n' '\0' | xargs -0 -i echo {}</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$all_paths</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">':'</span> <span style="color: #ff0000;">'\n'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">'\n'</span> <span style="color: #ff0000;">'\0'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span>  <span style="color: #c20cb9; font-weight: bold;">svn</span> add <span style="color: #660033;">--non-recursive</span>  <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^A&quot;</span>
&nbsp;
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$DIR</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Finish $0 on&quot;</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #ff0000;">&quot;with <span style="color: #007800;">$REPO_NAME</span>&quot;</span></pre></div></div>

<p>It&#8217;s not a big deal but might help you to spare some time. There might be better ways to do it and I wonder if same can be done using &#8220;plain ant&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rekk.de/bloggy/2009/bash-script-add-include-only-certain-files-to-subversion-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

