3

We have a script to delete the svn:mergeinfo property from all folders inside a Subversion working copy, but not the working copy root directory itself. It's currently an NAnt build script invoked via a separate batch file, so I'm trying to replace it with a simpler PowerShell script. I've had three attempts at it, ranging from the naïve to the slightly more sophisticated. All three fail my criteria, outputting the line property 'svn:mergeinfo' deleted from '.'.

Checking the SVN properties of the working copy root indicates that the svn:mergeinfo property has indeed been removed from this folder which is not what I want. Each version is designed to be run from the working copy root.

Attempt 1:

# I understand why this one fails, it's a poor attempt.
Get-ChildItem -Recurse | svn propdel svn:mergeinfo -R $_

Attempt 2:

# This one correctly lists everything except the working copy root, but
# still removes the svn:mergeinfo property from the working copy root.
Get-ChildItem -Recurse -Exclude $pwd | svn propdel svn:mergeinfo -R $_

Attempt 3:

# Again, this one works fine until the svn propdel is added.
Get-ChildItem | ForEach-Object { ls -R $_ } | svn propdel svn:mergeinfo -R $_

Any thoughts on where the flaw in my logic is?

1 Answer 1

3

svn is an external application and you cannot use PowerShell piping technique directly with it. I am not familiar with svn syntax and can be wrong about the details but all your commands presumably should use ForEach-Object (%). That is:

... | %{ svn propdel svn:mergeinfo -R $_ }

Then svn should “understand” the $_ correctly. Also, it is quite possible that you should use something like $_.FullName or $_.Name instead of $_ (again, because svn is an external application and it expects a string (e.g. $_.FullName/$_.Name), not an object $_). NB: $_ is often converted to strings as expected automatically but this is not always the case.

Sign up to request clarification or add additional context in comments.

3 Comments

Nice catch, thanks. Do I still need the middle term, then? The foreach-object { ls -R %_ }? It seems like the second attempt, which is much nicer and more concise, would work correctly with this fix.
AFAIK, there is no %_ construct. Anyway, I would recommend just to experiment a little bit on your own. Use cmd instead of svn: ... | %{ cmd /c echo $_.FullName } etc. and see what you get. If svn can accept a list of parameters after -R then there are other solutions, too.
Typo, sorry; I meant $_. Thanks for the tip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.