Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SVN (Tortoise )  update using powershell

Posted on 2012-03-27
16
Medium Priority
?
4,662 Views
Last Modified: 2012-04-22
I am very new to PowerShell and Tortoise SVN both , and need to accomplish the following via PowerShell.

I am working off a Windows 2008 server that has Tortoise SVN installed.  
•      The SVN repository has been checked out locally to a c:\alpha\testops.
•      I have a local folder on the server “C:\beta\cons “which has a lot of subfolders and each subfolder has a few config files
•      This entire “cons” folder from the local server needs to be checked into SVN under the “testops\cons” folder.
•      The “CONS” folder already exists in the repository: Eg : c:\alpha\testops\cons)

The local folder where I have all the config files looks something like this:
C:\beta\cons \app1\config1.txt
C:\beta\cons \ app1\config2.txt

C:\beta\cons \ app2\config1.txt
C:\beta\cons \ app2\config2.txt

C:\beta\cons\ app3\config1.txt
C:\beta\cons\ app3\config2.txt

C:\beta\cons\app4\config1.txt
C:\beta\cons\ app4\config2.txt
etc

When checked into SVN, it should look something like this:
C:\alpha\testops\cons\
                                         \app1\
                                              config1.txt
                                              config2.txt
                                            \app2\
                                                      config1.txt
                                               config2.txt
                                               \app3\
                                                   Config1.txt
                                                 Config2.txt
Etc…

So the SVN steps that need to be accomplished via powershell   are:
1.      Run an update first to get the latest version of the repository.
2.      Add the  sub folders under  from c:\beta\cons\ (source folder )  to  c:\alpha\testops\cons\ (repository)
3.      Commit
4.      Update

Would very much appreciate your help .

 Thanks much ..
0
Comment
Question by:jpsaini
  • 10
  • 6
16 Comments
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37777306
Do you really need to use power shell to so svn operations? ( as you already have tortoise SVN?

Tortoise SVN is very easy to use interface. So I recommend you to use this to achieve your task.

First make sure that you dont have any files that are not in repository. You can check this by right clicking on "c:\alpha\testops\cons" folder and select TortoiseSVN->Add menu (If it is repository you should see an add menu). Now a new window will popup. If you see nothing in the new window, it is okay, skip the first step. If you see any files listed there in the new window, start from step 1.

1. check out the repository or cons folder in a fresh location
2. Use windows explorer to copy the files from source (c:\beta\cons) to destionation (c:\alpha\testops\cons)
3. Right click on the "cons" from the repository folder, select TortoiseSVN->Add menu.
A new window will popup with all the files and folder that you copied now. Click Ok.
4. Right click "cons" folder and select TortoiseSVN->Commit. Enter the description of the newly added files in the comment section
5. Right click->tortoiseSVN->update.

Now you have the latest repository with your files.

Feel free to ask if you need steps with powershell
0
 

Author Comment

by:jpsaini
ID: 37777520
Hi RushtoSankar,

Thanks for your response. Yes you are right .  Tortoise SVN is an easy to use interface and I have tested the above steps and it works fine.
However the direction within the team is " scripting and automation" and we have been asked to script pretty much everything via powershell and hence the reason for my post.  

Would really appreciate help with getting this scripted in powershell..
 

Thanks
0
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37778884
You have provided the list of steps that needs to be followed in a script.
Do you want the script to copy the files every time when it runs?
Do you have new folders/files under "c:\beta\cons" when the script runs every time? or Do you want the different folder folder to be copied every time?

Please explain me the steps other than last two lines - update/commit.
Like, coping the file from folders / get input from the user something like that.

if it has only simple steps, these can be achieved using simple dos batch files as well.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 

Author Comment

by:jpsaini
ID: 37779138
Hi

The c:\beta\cons folder could have new
        1. New folder and files every time the script runs
        2. Existing folders with updated config1.txt or config2.txt

I have a script which creates the  C:\beta\cons \app1 or C:\beta\cons\app2 etc folders and moves the respective config files to them.  
Once that script finishes, that is when I need this SVN  script to kick in :
Hope I answered your questions. Please let me know if you need any more information. I really appreciate your time and help.  

1. Checkout repository
2.Update
3. Add the folders\files  ( I thought copying the folders over to the local repository folder c:\alpha\testops\cons was enough. But the "Add" function still needs to be performed is what I realised).
4.commit
5. Update

I looked up   Tortoise SVN CLI   at http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-cli-main.html to get an understanding  of the commands

Thanks
0
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37779281
Copy the following lines to a batch file and try running it. It is simple easy to maintain batch file. It should work as you expected.

Make sure that svn.exe (svn client) is in PATH. If you need svn command line client you can use slik subversion as well.

@echo off
::save the current directory & change to repository folder
pushd C:\alpha\testops

:: update the working directory from SVN server/repository
svn update

::copying files from C:\Beta\cons to C:\alpha\testops\cons folder
xcopy C:\Beta\cons C:\alpha\testops\cons /E /F /Y

:: add the files that are newly copied
svn add --force

:: commit the newly added files with messsage
svn commit -m "Your log message goes here"

::restore (go back to) the original directory
popd
0
 

Author Comment

by:jpsaini
ID: 37779511
Hi ,

Thanks for the quick response with the dos batch file.  It definitely looks like it will do the job Unfortunately  the requirement is for a power shell script to do exactly the same.  It is a team wide initiate to use power shell only , coming from the top and hence the reason.

Could you please help with a power shell equivalent script as well?
I tried using something in the likes of below but it does not work.

Set-Alias tsvn 'C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe'
set-alias commit fn_commit
set-alias commit fn_update
function fn_commit($path = "C:\alpha\testops") {tsvn /command:commit /path:$path}
#function fn_update($path = "C:\alpha\testops") {tsvn /command:update /path:$path}

Then realized that I will have to use the svn cli commands like the one you have used in the DOS batch script, but just need it as a  power shell script.

Thanks again!  Much appreciated.
0
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37781842
Powershell can run most of the things that a normal cmd shell can run.

try copying the following lines in a powershell script (.ps1 extension) and run

#save the current directory & change to repository folder
#pushd may give errors if the destination is not present
pushd C:\alpha\testops

# update the working directory from SVN server/repository
svn update

#copying files from C:\Beta\cons to C:\alpha\testops\cons folder
xcopy C:\Beta\cons C:\alpha\testops\cons /E /F /Y

#add the files that are newly copied
svn add --force

#commit the newly added files with messsage
svn commit -m "Your log message goes here"

#restore (go back to) the original directory
popd

You can remove the push and pop commands if you dont need.
0
 

Author Comment

by:jpsaini
ID: 37782318
Thanks. Ok let me give it a try and will get back shortly.
0
 

Author Comment

by:jpsaini
ID: 37784555
Hi,

I was running the steps manually before running it via powershell and for
for svn add --force , it says
svn: E205001: Try 'svn help' for more info
svn: E205001: Not enough arguments provided

what could be causing it?

thanks!
0
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37786336
What version of SVN are you using?
0
 

Author Comment

by:jpsaini
ID: 37786948
Tortoise SVN 1.6.16, Build 21511 and the CLI is  CollabNetSubversion-client-1.7.4-1-x64 .
I was able to  svn add by specifying the folder like:

 >svn add cons\

Thought of giving the powershell script a shot and I  used these commands in a powershell script and ran it: But i get the below error:

The term 'svn' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
g of the name, or if a path was included, verify that the path is correct and try again.
At C:\test\asha\copytorepo_svn_v1.ps1:2 char:4
+ svn <<<<  update
    + CategoryInfo          : ObjectNotFound: (svn:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


This is the script. I substituted xcopy with Copy-Item cmdlet.

pushd C:\alpha\testops
svn update

# Set variables  here
$source = "c:\test\consumer\"
$destination = "C:\alpha\testops"
copy-item $source $destination -recurse
svn add consumer/
svn commit -m "Test checkin "
popd
0
 

Author Comment

by:jpsaini
ID: 37787009
In the path:

PATH=C:\Program Files\CollabNet\Subversion Client;C:\Windows\system32;C:\Windows
;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows
\idmu\common;C:\wintools;C:\Program Files\TortoiseSVN\bin
0
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37787373
Try changing "svn add --force" line to "svn add --force cons".

I missed the folder name to add.
0
 

Author Comment

by:jpsaini
ID: 37787391
ok  will try that..
but running it from powershell will still throw this error: thoughts>?


 Thought of giving the powershell script a shot and I  used these commands in a powershell script and ran it: But i get the below error:

The term 'svn' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
g of the name, or if a path was included, verify that the path is correct and try again.
At C:\test\asha\copytorepo_svn_v1.ps1:2 char:4
+ svn <<<<  update
    + CategoryInfo          : ObjectNotFound: (svn:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
 

Accepted Solution

by:
jpsaini earned 0 total points
ID: 37856062
Hi Rushtosankar,

i was able to accomplish what I was looking for. Your replies helped me get direction to the problem and I could  work off it.

Thanks!
0
 

Author Closing Comment

by:jpsaini
ID: 37877324
i was able to accomplish what I was looking for. Your replies helped me get direction to the problem and I could  work off it.
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question