windows batch file exits when running mercurial commands - windows

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

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

SVN update by executing TortoiseProc.exe in a script created in bash

I need to run a SVN update in script create in bash but it fails. Can please you help to find out what am I doing wrong?
Script:
echo SVN Update
alias svn="cd C/Program Files/TortoiseSVN/bin"
START TortoiseProc.exe /command:update /path:"cd C/CCUE" /closeonend:0
Error in output:
+echo SVN $'Update\r'
SVN Update
' alias 'svn=cd C/Program Files/TortoiseSVN/bin
+ START TortoiseProc.exe /command:update '/path:cd C/CCUE' $'/closeonend:0\r' - line 7: START: command not found
Defining an alias for a directory change is not the same as executing that directory change. Also changing directory is not a good idea since then TortoiseProc would not know what directory you want to update.
I'd recommend using TortoiseProc.exe full path or putting TortoiseSVN/bin in PATH.
The error could be caused also by bash not finding START.EXE.
I was able to invoke by hand TortosieProc without START using the following line
$ "/c/Program Files/TortoiseSVN/bin/TortoiseProc.exe" /command:update /path:"d:\Dir\LocalRepo" /closeonend:0 &
Notice how the path parameter has to be invoked by TortoiseProc and therefore has to follow Windows syntax. TortoiseProc complained if I used a UNIX style for the path.
Tested on cygwin, Windows 7, TortoiseSVN 1.7

Windows scheduled task to git push to github

I hope to add a Windows Scheduled Task to git push to github every night. I have a CMD file. When I run the CMD file on the windows command prompt, it works fine. But when I run it via windows scheduled task. It's stuck forever. The status is "running". And from the log I can see it successfully started the git bash shell. Any idea?
echo git push > i:\gitpush
echo 'pushing' >>log1
C:\WINDOWS\SysWOW64\cmd.exe /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login i:\gitpush" >>log1 2>>error
echo 'done pushing' >>log1
del i:\gitpush
Here is the log output:
'pushing'
Welcome to Git (version 1.7.4-preview20110204)
Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.
Then I did an experiment to rename gitpush script to a wrong file name. And it exited immediately with the error "No such file or directory", which is expected. It shows the gitpush script is passing in correctly to the bash but for some reason it's stuck.
The reason I have to go through git bash shell is because I don't know how to setup public key in windows command line shell without using git bash shell.
Thanks!
I don't know how to setup public key in windows command line shell
Public/private keys work also in a DOS shell, provided you define the %HOME% environment variable (referencing the parent directory of the .ssh)
The trick with Windows Scheduled Task is to make sure:
who is actually running the task (the "system account"? or the actual user?)
Displaying "env" can help debugging the issue.
where it is run: if git push depends on the current path to properly push the current repo, you need to be certain that your task runs where it is supposed to.

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