Search code examples
gitpowershellsvnscriptingsubgit

Problem while automating SVN to Git migration using Subgit and Powershell Scripting


I am trying to write a powershell script that automates svn to git migration using Subgit. I am new to powershell. I have figured out how to do it using individual commands, but the problem occurs when I try to put those commands together in a script.

Specifically,

subgit configure --layout auto $SVN_PROJECT_URL $GIT_REPO_PATH 
subgit import $GIT_REPO_PATH

These 2 commands trigger an external process, so powershell does not wait for these 2 to finish executing before moving on to the next part, which is causing errors. I have tried to put these 2 lines in their separate processes and waiting for those processes to finish, but both Wait-Process and Wait-Job commands in powershell does not work, Instead of waiting for the lines to finish executing, it does not finish executing and immediately goes to the next line. I have tried the following, with no result,

$job1 = Start-Job { subgit import $GIT_REPO_PATH }
Wait-Job $job1
Receive-Job $job1

and

 $sb = Start-Job -ScriptBlock {
     subgit configure --layout auto $SVN_PROJECT_URL $GIT_REPO_PATH 
 }
 Wait-Job $sb.Name

I think the issue might be caused by the way I am using subgit, but I am not sure.


Solution

  • I found the solution was use precess in the following way by passing the arguments via argumentlist

    $procConfigure = Start-Process subgit -ArgumentList "configure
    --layout auto $SVN_PROJECT_URL $GIT_REPO_PATH" -PassThru 
    $procConfigure.WaitForExit()