Howto determine if an SVN working copy needs updating (from a script)? - windows

I'd like to determine from a batch file on Windows if a local SVN working copy needs to be updated from the server. On a unix-like machine, I would run "svn status -u" and count the '*'s. How do I achieve the same thing in a batch file?
Background: I'm trying to determine if a dependency library is out-of-date since it takes a long time to re-build it and we only update it about once every 3 months. This is for an automated build process.

If I'm following you, maybe something like:
svn st -u | find "*"
if not "%errorlevel%"=="0" goto end
svn update
:end
find sets errorlevel to 0 if it successfully found "*".
EDIT: accidentally left off the "" around %errorlevel%.

Related

How to execute batch file as Tortoise SVN hook

I wish to run a batch file either in START commit or PRE commit via TortoiseSVN hook scripts. No tests I have done has worked.
I have created a batch file (svnadd.bat) that just writes a message to a text file for now, so I know it fired. However, the batch file does not appear to run as the message does not get written.
echo YES>C:\Temp\commit.txt
Here is my hook setup.
My process. Right click on a folder which is under svn version control and select SVN Commit. The commit dialog shows, however, the batch file does not execute.
All svn software, repositories and folder/file structure under svn control reside on the same computer/drive.
As per the screen shot, I also tried adding cmd.exe to the front of the command line as
C:\windows\system32\cmd.exe /c C:\Tools\SVN\svnadd.bat
I config it like this. It is successful.
post_commit_hook.bat:
echo Hello World >file.txt
After commit, file.txt will be save to
E:\SVN\XXX\branches\autoCommit
#lazybadger's comment provides the answer in that the "path" needs to be at the highest working copy path. For me, this is C:\Projects.
Once I set C:\Projects as the path, the script hook ran.
You can try and use team city, if you want certain scripts to be executed on SVN events (like SVN Commit). Though TeamCity is mainly used as a build server, I think it can do what you desire.

svn post-commit hook on windows server

i'm trying to set up a svn post-commit hook on a windows server, so that every time a commit is made, it is connected to an issue of an existing project on my bug tracking website.
since there is no pre made post-commit hook for windows (or at least i haven't find one that would fit my needs), i tried to write the batch file for myself.
SET REPOS=%1
SET REV=%2
SET SVNLOOK="C:\Program Files (x86)\VisualSVN Server\bin\svnlook.exe"
SET PROJECT=3
%SVNLOOK% log -r %REV% "%REPOS%" > COMMIT_MSG
SET /p COMMIT_MSG= < COMMIT_MSG
echo %COMMIT_MSG%
C:\curl\bin\curl "http://www.mybugtrackingsite.de/vcs_integration/report/%PROJECT%/?passkey=KEY" --data-urlencode "msg=%COMMIT_MSG%"
when i'm setting REPOS and REV by myself and run the script from the command line it works, but when i make a commit it doesn't work and my COMMIT_MSG only contains "echo is on" instead of the actual message.
i've read, that the svn repository executes hook programs with an empty environment, means that no environment variables are set at all and that could be why my script runs fine by hand and not when run by svn.
but what variables do i have to set and how? my paths are already absolute, so that shouldn't be the problem. i'm not a windows guy and am not really into batch - so any help or ideas how i get this thing to work would be appreciated!
When you redirect the commit message to the file you use a relative path 'COMMIT_MESSAGE'.
%SVNLOOK% log -r %REV% "%REPOS%" > COMMIT_MSG
The working directory which is used by the svn hook may not be the same as yours and the svn process has not the rights to write at this location. You may use an absolute path.
You can also try to redirect STDERR to see if you get an error from svnlook.
Also delete the file at the beginning of the hook script to ensure that you don't use a file from a previous run.
Your are setting both REPOS and REV to %1. One of them should be %2
You should also place #ECHO OFF at the top of the file to avoid unnecessary output on screen

windows batch file exits when running mercurial commands

For daily backup of my mercurial repositories on Windows XP I used a simple batch file hg_backup.bat which just did some directory changes and mercurial calls with a pause command in the end like this:
#Z:
#cd \hg_backup\drawings
hg pull -v
#cd \hg_backup\src\scripts
hg pull -v
#cd \hg_backup\eagle4\lbr
hg pull -v
#pause
This worked fine with mercurial up to 1.7 (installed with TortoiseHg). However since mercurial 1.8 it starts the very first mercurial command and then exits abruptly without reaching the following commands or even the end of the script. The command window just disappears.
I had the same problem some time before, when I tried the same thing with git, but didn't investigate further, because I use git for one repository only. It seems to me, there's some return code of the hg command line call involved which causes the script to end instead of executing the other command but I couldn't verify this yet.
Has anyone an idea why this happens or maybe even how to fix it?
If your hg is a hg.bat or hg.cmd, use call hg and see if it starts working.
The command.com shell executes batch files replacing the old script (to save memory), and requires using call to start a batch script and continue execution later. This behavior remains in Windows cmd.exe for compatibility.
I had the exact same problem, but the solution provided by #grawity didn't work for me (and I have no idea why).
The solution in my case was to replace call with cmd /C, like so:
cmd /C hg sum
cmd /C hg stat

SourceSafe Merge at the project level

I'm running SourceSafe and I have two branches of my code. I'm currently using the manual approach of running a report to show differences and then manually merging each file one by one. However I'm trying to find a streamlined way to do this on the project level. It's ok if the process shows me each file one at a time, I'm just worried if I go manually one by one to each file and merge each file separately that I'll accidentally skip a file. Whereas a "wizard" I could trust to hit every file even if it shows me each and every file before merging them.
I'm new to merging but not sourcesafe so I guess you could say I'm a half newbie.
Looks like there isn't a built-in way to do this through the UI. But they do provide a command line tool which I ended up writing a batch file for to streamline option specification:
ECHO OFF
SET SSDIR=K:\Archive
SET /P MainProject=Please enter the project to merge into (e.g. "$/Trunk"):
SET /P BranchedProject=Please enter the branched project (e.g. "$/Active Branches/Branch1"):
SET /P Comment=Comment:
SS CP %MainProject%
IF NOT EXIST C:/BranchCheckouts MKDIR "C:/BranchCheckouts"
IF EXIST "C:/BranchCheckouts/mergelog.txt" DEL "C:/BranchCheckouts/mergelog.txt"
SS MERGE %BranchedProject% -GL"C:/BranchCheckouts" -O#"C:/BranchCheckouts/mergelog.txt" -C%Comment% -R
PAUSE

How do I automatically update a Subversion working copy?

Does anybody know how I can automatically run svn update? If anybody has a script or something like that, could you show me an example?
I'm using TortoiseSVN. On the production server I have a scheduled task that runs the following batch file.
CD C:\Program Files\TortoiseSVN\bin\
START TortoiseProc.exe /command:update /path:"C:\www\MyRepo\" /closeonend:0
Hopefully this saves someone else some time!
I use SVN Notifier which sits in the system tray and notifies me every time the repository changes. And I can highly recommend it. It means you only update when there's something to update!
Alternatively you can set up a scheduled task/cron job to run svn update in the appropriate directory every hour/day/whatever.
EDIT: OK, take a look at this Microsoft article on setting up a scheduled task.
You want a batch file called svnUpdate.bat or something which looks like this:
cd C:/path/to/your/working/copy
svn update
Get the scheduled task to run this as often as you like (once an hour seems sensible)
Make sure you have the command line version of svn installed (I use SlikSvn) and available on your PATH (in a command window type svn and ensure it says 'Type svn help...' or similar.
#echo off
cls
echo == Initiating system instance variables...
echo. -- Setting the variables...
:: Here you need to make some changes to suit your system.
set SOURCE=C:\sauce\CURRENT
set SVN=C:\Program Files\TortoiseSVN\bin
:: Unless you want to modify the script, this is enough.
echo. %SOURCE%
echo. %SVN%
echo. ++ Done setting variables.
echo.
echo == Updating source from SVN
echo. -- Running update...
"%SVN%\TortoiseProc.exe" /command:update /path:"%SOURCE%" /closeonend:2
echo. ++ Done.
echo. -- Cleaning up...
set SOURCE=
set SVN=
echo. ++ Done.
If you are using TortoiseSVN then the above batch script will suit fine. Otherwise you can just modify it to use whatever SVN client you are currently using. Just pop this in a .bat file and run it on demand.
You can also download and use Commit-Monitor from http://code.google.com/p/commitmonitor/. It monitors SVN repositories for commits and notifies the user when it happens. It is in GNU GPL, ver 2.
Note: Once I know your operating system, I will be able to give you a more detailed answer.
General Instructions
Never change anything in the local repository.
Read this link on how to use AT to schedule from the command line in windows.
Use the AT command to schedule the following command (assuming you have the command-line version of svn installed):
svn update reporsitory_directory
Profit!

Resources