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

89 views Asked by At

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.

2

There are 2 answers

0
Tahjid Ashfaque On BEST ANSWER

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()
0
ildar.hm On

I'm not a PowerShell expert either, but got some experience with SubGit. I don't see any issues in the way you are using SubGit apart form the fact that 'subgit configure' with 'layout auto' requires some interactivity as the 'auto' layout means SubGit will connect to the SVN server, read its history and try to create a suitable mapping configuration based on the history; and for that SubGit always asks for SVN credentials, maybe that could cause an error and subsequent task switch?

A possible way to avoid the interactivity (at least to check) is omitting the 'layout' option -- in this case SubGit will just create a 'standard' layout mapping thus not requiring to connect to the SVN server and not requiring any interactivity.

I've tried to do the same as you do with a PS script and it worked more or less ok on my machine: it started the first command, stopped to ask for credentials and once I provided username and password it continued with the configuration and after it finished, switched to the 'import'. The only thing I had to change before run my script was the execution policy, I had to change it from default Restricted to Unrestricted to be able to run the script. So for me the issue you got looks more like a PS issue, probably related to PS settings (the execution policy, maybe?).