Solved

SVN (Tortoise )  update using powershell

Posted on 2012-03-27
16
4,215 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:jpsaini
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks. Ok let me give it a try and will get back shortly.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:jpsaini
Comment Utility
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
Comment Utility
What version of SVN are you using?
0
 

Author Comment

by:jpsaini
Comment Utility
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
Comment Utility
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
Comment Utility
Try changing "svn add --force" line to "svn add --force cons".

I missed the folder name to add.
0
 

Author Comment

by:jpsaini
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now