tags:

views:

27

answers:

1

I check out a working copy of a project using Checkout-WorkingCopy and later delete the directory using Cleanup-WorkingCopy (the code for these functions is at the end of this post).

Problems I am facing:

  1. Instead of echoing "Checking out from svn://somePath1 to C:/somePath2" it echoes "Checking out from svn://somePath1 C:/somePath2 to"
  2. In Cleanup-WorkingCopy, it throws the following error while trying to execute Pushd,

    <Push-Location : Cannot convert 'System.Object[]' to the type 'System.String' 
    required by parameter 'LiteralPath'. Specified method is not supported.
        + Pushd <<<<  $directory
        + CategoryInfo : InvalidArgument: (:) [Push-Location], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.PushLocationCommand>

  3. Finally, I get the error "The syntax of the command is incorrect" while executing Rmdir.

The functions I use are given below. I have checked the arguments sent to the functions and they are correct.

#Checks out a copy from svnPath into appFilePath
Function Checkout-WorkingCopy($svnPath, $appFilePath) {

    Echo "Checking out from $svnPath to $appFilePath"

    svn checkout $svnPath $appFilePath --quiet

    Echo "Checkout Done"
}

#Deletes the working copy previously checked out
Function Cleanup-WorkingCopy($directory, $appFilePath) {

    Pushd $directory
    Cmd /C "Rmdir /S /Q $appFilePath"
}
+2  A: 

It looks like $directory is geting passed an array of values. When you need to debug stuff like this try inspecting the value passed in. Also rather than shell out to cmd.exe just use PowerShell's Remove-Item cmdlet:

Function Cleanup-WorkingCopy($directory, $appFilePath) { 
    $directory | Foreach {"$($_.GetType().Fullname): $_" }
    Pushd $directory 
    Remove-Item $appFilePath -Recurse -Force
}

Actually with this approach you don't need $directory at all and could replace the whole function with:

Remove-Item $appFilePath -Recurse -Force
Keith Hill
You are right. $directory is an array of 2 strings (1) path of the directory (2) path of appFile. But nowhere in the code am I doing any such manipulation except $appFilePath = Join-Path -Path $directory -ChildPath "AppFile". Am I doing something wrong?
Rahul
It happens to be the same thing with my first problem as well. $svnPath is an array of 2 strings, the actual svnPath and appFilePath. Makes me wonder if the function takes all arguments in an array :|
Rahul
A simple Google search took me to http://weblogs.asp.net/soever/archive/2006/11/29/powershell-calling-a-function-with-parameters.aspx which has a neat explanation of how to call a function with parameters
Rahul
Heh, I was just going to suggest that you're using `,` to separate parameters to functions when it should be `<space>`. BTW on PowerShell 2.0 execute `Set-StrictMode -Version 2.0` somewhere at the beginning of your script to catch errors like this.
Keith Hill