Cerd
Cerd

Reputation: 153

How to write a batch file for svn commit and update

so far I have used Tortoise SVN to commit and update folders under version control. When I commit I check "all" in the GUI dialog so that deletions as well as additions are committed.

Now I have more and more folders under version control and I would like to have a batch file for committing and updating all of them.

So far I have experimented with the command line and found this:

svn add . --force
svn commit -m"Adding missing files"

This adds new files but does not reflect any deletions.

Could you please help me with the batch files? It would make my work a lot easier but I am really too unexperienced with SVN/batch files to do this on my own...

I use Win7x64 and Tortoise SVN 1.7.12 with the command line extension.

Thank you!

Upvotes: 1

Views: 21790

Answers (2)

Cerd
Cerd

Reputation: 153

I think I figured something out using gammay's and this input:

cd "C:\Users\User\Desktop"
for /f "usebackq tokens=2*" %%i in (`svn status ^| findstr /r "^\?"`) do svn add "%%i %%j"
for /f "usebackq tokens=2*" %%i in (`svn status ^| findstr /r "^\!"`) do svn delete "%%i %%j"
svn commit -m "Commit via Batch"

And

cd "C:\Users\User\Desktop"
svn update

and repeatedly for different paths!

Thank you :)

Upvotes: 7

gammay
gammay

Reputation: 6215

Firstly, which svn command line tools do you use? You can use CollabNet for 'svn' commands.

Secondly, to delete files, you need to checkout existing files from svn, then use svn delete and then svn commit.

Your question is not clear - if this doesn't answer your question, please provide a few more details.


Edited to answer asker's requirement (in comments below): OK. What you want is a script which will find the new files in the folder and add them to SVN automatically and find deleted files in folder and delete them from SVN too. I can tell you this is a dangerous as undesired files can get added/deleted.

Still, if you want to go ahead with this script this is what the script can do:

  • Run svn status which displays missing (deleted) files and unknown (to be added) files
!    FileA [Missing - deleted]
?    FileD [Unknown - to be added]
  • Parse the output to find the ! files and run svn delete on these files
svn delete FileA
  • Parse the output to find the ? files and run svn add on these files
svn add FileD
  • svn commit
    • This commits the above deleted & added files and also any modifications.
    • If you do not want to commit modifications, commit individual added/deleted files

Upvotes: 0

Related Questions