Reputation: 691
I need to add some files to svn:ignore from the command line.
BUT I need to do this without removing previous values of the svn:ignore property. If I use the command:
svn propset svn:ignore "*.jar" .
it sets the correct ignore value but erases every previous value, which is not what I want.
Using svn propedit
isn't suitable for me since I need to execute this from an Ant script.
EDIT: portability is not an issue for me (I have to work on windows) but I cannot install third-party Ant libraries, I only have the Subversion command line.
Thanks in advance for any hint.
FINAL EDIT: to enyone interested, I implemented the suggested solution in the Ant script this way:
<!-- Read current values and write them to a file -->
<exec executable="svn" output="${build}/current-props-file">
<arg value="propget" />
<arg value="svn:ignore" />
<arg value="." />
</exec>
<!-- Reload the file, stripping away the value possibly already present to avoid duplicate -->
<loadfile srcfile="${build}/current-props-file" property="cleaned-props">
<filterchain>
<linecontains negate="true">
<contains value=".jar" />
</linecontains>
</filterchain>
</loadfile>
<echo message="cleaned-props: ${cleaned-props}" />
<!-- Create file with final values to set -->
<echo file="${build}/cleaned-props-file" message="${cleaned-props}*.jar" />
<!-- Set property values -->
<exec executable="svn">
<arg value="propset" />
<arg value="svn:ignore" />
<arg value="--file" />
<arg value="${build}/cleaned-props-file" />
<arg value="." />
</exec>
Upvotes: 0
Views: 1137
Reputation: 2999
You can read the value of svn:ignore before updating it, then append a new line to this value and set the new value:
$ ignores=$(svn propget svn:ignore .)
$ ignores="$ignores"$'\n'"*.jar"
$ svn propset svn:ignore "$ignores" .
You can also use temporary file to store the older value:
$ svn propget svn:ignore . > /tmp/ignores
$ echo "*.jar" >> /tmp/ignores
$ svn propset svn:ignore -F /tmp/ignores .
$ rm -f /tmp/ignores
But since you're going to execute this code from an Ant script, I'd propose to implement that functionality with SVNKit. The code should look like this:
File target = new File("");
SVNWCClient client = SVNClientManager.newInstance().getWCClient();
SVNPropertyData oldValue = client.doGetProperty(
target,
SVNProperty.IGNORE,
SVNRevision.WORKING,
SVNRevision.WORKING
);
String newValue = SVNPropertyValue.getPropertyAsString(oldValue.getValue()) +
'\n' + "*.jars";
client.doSetProperty(
target,
SVNProperty.IGNORE,
SVNPropertyValue.create(newValue),
false,
SVNDepth.EMPTY,
ISVNPropertyHandler.NULL,
Collections.emptyList()
);
In order to run this code form your ant script, put it into main method of some class IgnoresUpdate. Compile and make .class file available for the script. Then you can invoke it as follows:
<java classname="IgnoresUpdate" fork="true">
<classpath>
<pathelement location="/path/to/compiled/IgnoresUpdate"/>
<pathelement location="/path/to/svnkit.jar"/>
</classpath>
</java>
However, as David pointed out in his answer, you can use ignore task which seems like the best solution in general (although it may be not applicable for you case).
Upvotes: 2
Reputation: 2702
Have you tried the svnant tasks? You can directly integrate SVN client functionality into your Ant builds with it. It also has an ignore task, which looks like it does what you want.
Upvotes: 1