Mercurial patch building is broken? "Failed to build patch for build"

I recently removed some files from source control (via the mercurial delete), and now the patches aren't being built correctly and are causing my builds to fail. See this message:

[Updating sources: server side checkout...] Failed to build patch for build #17 {build id=92}, VCS root: mercurial: {id=7}, due to error: '"C:\Program Files\TortoiseHg\hg.exe" cat -o C:\TeamCity\temp\mercurial7520992316082275493catresult\%p -r 30c08ac2698e TypedCollectionGenerator\TypedCollectionGenerator.sln TypedCollectionGenerator\TypedCollectionGenerator\Program.cs TypedCollectionGenerator\TypedCollectionGenerator\Properties\AssemblyInfo.cs TypedCollectionGenerator\TypedCollectionGenerator\TypedCollectionGenerator.csproj TypedCollectionGenerator\TypedCollectionGenerator\bin\Debug\TypedCollectionGenerator.exe TypedCollectionGenerator\TypedCollectionGenerator\bin\Debug\TypedCollectionGenerator.pdb TypedCollectionGenerator\TypedCollectionGenerator\bin\Debug\TypedCollectionGenerator.vshost.exe TypedCollectionGenerator\TypedCollectionGenerator\bin\Debug\TypedCollectionGenerator.vshost.exe.manifest YNABLibrary\libs\asx3m_0.91.swc YNABParser\build\ YNABParser\build\ YNABParser\src\TabTest.mxml' command failed. stderr: TypedCollectionGenerator\TypedCollectionGenerator.sln: no such file in rev 30c08ac2698e TypedCollectionGenerator\TypedCollectionGenerator\Program.cs: no such file in rev 30c08ac2698e TypedCollectionGenerator\TypedCollectionGenerator\Properties\AssemblyInfo.cs: no such file in rev 30c08ac2698e TypedCollectionGenerator\TypedCollectionGenerator\TypedCollectionGenerator.csproj: no such file in rev 30c08ac2698e TypedCollectionGenerator\TypedCollectionGenerator\bin\Debug\TypedCollectionGenerator.exe: no such file in rev 30c08ac2698e TypedCollectionGenerator\TypedCollectionGenerator\bin\Debug\TypedCollectionGenerator.pdb: no such file in rev 30c08ac2698e TypedCollectionGenerator\TypedCollectionGenerator\bin\Debug\TypedCollectionGenerator.vshost.exe: no such file in rev 30c08ac2698e TypedCollectionGenerator\TypedCollectionGenerator\bin\Debug\TypedCollectionGenerator.vshost.exe.manifest: no such file in rev 30c08ac2698e YNABLibrary\libs\asx3m_0.91.swc: no such file in rev 30c08ac2698e YNABParser\build\ no such file in rev 30c08ac2698e YNABParser\build\ no such file in rev 30c08ac2698e YNABParser\src\TabTest.mxml: no such file in rev 30c08ac2698e

Which folder on the build machine do I need to delete to get it to forget about the TypedCollectionGenerator files that it is insistent upon trying to include in the patch somehow?

Many thanks for any help you can offer!

Comment actions Permalink

Hello Taylor,
what version of Teamcity do you use?

Comment actions Permalink

Taylor, I checked our code - we do not try to build diff for deleted files. In our hg support we rely on default format of hg messages, have you customized them?

Comment actions Permalink

I am also experiencing this issue, using 6.0.2. However, I don't see the issue when the build is triggered by the VCS trigger, only when I try to run the build manually.

The stack trace I see whenever I try to manually start a build is as follows:

jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl$1: Server was not able to build correct patch, most likely due to VCS errors, will try again. at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.throwError(
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.checkPatch(
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.copyPatchAndCheck(
at jetbrains.buildServer.agent.impl.patch.UpdateSourcesPatcherBase.copyPatchToTempFile(
at jetbrains.buildServer.agent.impl.patch.UpdateSourcesFromServer.updateSources(
at jetbrains.buildServer.agent.impl.patch.UpdateSourcesBuildStageBase.doSourceUpdate(
at jetbrains.buildServer.agent.impl.patch.UpdateSourcesBuildStageBase.doRecoverableStage(
at jetbrains.buildServer.agent.impl.buildStages.startStages.RecoverableBuildStage.doLastAttempt(
at jetbrains.buildServer.agent.impl.buildStages.startStages.RecoverableBuildStage.doBuildStage(
at jetbrains.buildServer.agent.impl.buildStages.BuildStagesExecutor$1.callStage(
at jetbrains.buildServer.agent.impl.buildStages.BuildStagesExecutor$1.callStage(
at jetbrains.buildServer.agent.impl.buildStages.StagesExecutor.callRunStage(
at jetbrains.buildServer.agent.impl.buildStages.StagesExecutor.doStages(
at jetbrains.buildServer.agent.impl.buildStages.BuildStagesExecutor.doStages(
at jetbrains.buildServer.agent.impl.BuildRunAction.doStages(
at jetbrains.buildServer.agent.impl.BuildRunAction.runBuild(
at jetbrains.buildServer.agent.impl.BuildAgentImpl.doActualBuild(
at jetbrains.buildServer.agent.impl.BuildAgentImpl.access$100(
at jetbrains.buildServer.agent.impl.BuildAgentImpl$
at Source)

Caused by: jetbrains.buildServer.vcs.patches.UnsuccessfulPatchException: Failed to build patch for build #2.af885cd2ff24 {build id=162}, VCS root: mercurial: http://[url redacted] {id=3}, due to error: 'cmd /c hg cat -o C:\TeamCity\temp\mercurial144187046310189202catresult\%p -r af885cd2ff24 [filename redacted] [filename redacted] [filename redacted] [...] [filename redacted]' command failed.
[filename redacted]: no such file in rev af885cd2ff24
[filename redacted]: no such file in rev af885cd2ff24
[filename redacted]: no such file in rev af885cd2ff24
[filename redacted]: no such file in rev af885cd2ff24
at jetbrains.buildServer.vcs.patches.AbstractPatcher$
at jetbrains.buildServer.vcs.patches.LowLevelPatcher.readPatchStream(
at jetbrains.buildServer.vcs.patches.LowLevelPatcher.applyPatch(
at jetbrains.buildServer.vcs.patches.AbstractPatcher.applyPatch(
at jetbrains.buildServer.agent.impl.patch.PatchApplierImpl.applyPatch(
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.checkPatchInFileIsCompleted(
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.checkPatch(
... 18 more
Comment actions Permalink

Sorry guys, I still cannot reproduce it. I did several commits which remove/add/change files and TeamCity detects changes and build patches correctly. At the moment I can see only one reason for this error - hg output which TeamCity cannot parse.

Could you please run a following command at TeamCity server machine in one of repositories at <BuildServerHome>/system/caches/mercurial:

hg status --rev <from>:<to>

where interval of revisions <from>:<to> contains commits with file removal, and provide an output?

Comment actions Permalink

Hi Dmitry,

I looked back through the revision logs to find out where the files mentioned in the error logs were removed, and was surprised to find that firstly they were from different revisions and secondly that neither was the most recent revision when I attempted to build.

Here's the HG status output for the revision that removed the majority of affected files:

 C:\Users\Administrator\.BuildServer\system\caches\mercurial\hg_498477970932201378>hg status --rev 2463:2464
R company\page1.aspx
R company\page1.aspx.cs
R company\page2.aspx
R company\page2.aspx.cs
R company\page3.aspx
R company\page3.aspx.cs
R company\page4.aspx
R company\page4.aspx.cs
R company\page5.aspx
R company\page6.aspx
R company\page6.aspx.cs
R company\page7.aspx
R company\page7.aspx.cs
R company\page8.aspx
R company\page8.aspx.cs
R company\page9.aspx
R company\page9.aspx.cs
R company\page10.aspx
R company\page10.aspx.cs
R company\page11.aspx
R company\page11.aspx.cs
R company\page12.aspx
R company\page12.aspx.cs
R company\page13.aspx
R company\page13.aspx.cs
R company\page14.aspx
R company\page14.aspx.cs
R company\page15.aspx
R company\page15.aspx.cs

I'm having to munge what I paste here slightly so our marketing department can't claim I'm interfering with their SEO (amongst other reasons), but I assure you there's nothing unusual about the paths. Also, when I look up the corresponding revision in TeamCity's revision history, it clearly shows all of those files as being removed, which suggests to me that it isn't a parse issue - unless TeamCity reads from hg again when building the patches?

There are also files removed in more recent revisions that it isn't complaining about...
Comment actions Permalink

Oh, and just to reiterate, the changesets containing the removal of the files TC is now complaining about built perfectly happily when they were pushed to the repository TC is watching and the VCS trigger caused the build - it's only when I run the builds manually that I see this issue.

Comment actions Permalink

Andy, could you please enable 'debug-vcs' logging preset at 'Administration > Server Configuration > Diagnostics' tab and reproduce the issue. After that teamcity-vcs.log in TeamCityHome/logs dir should contain all hg commands teamcity run and their output. Could you please provide this output? Real file/revision names do not matter unless they are unusual in some respect.

Comment actions Permalink

Hi Dmitry,

Unfortunately, at about 13,000 lines it's a bit long for me to censor :) Is there any way I could email it to you?

Comment actions Permalink

Yes, send it to with a link to this thread.

Comment actions Permalink

Dmitry spotted that the repository working directory had been populated with the problematic files, as I'd run an hg update there manually in an attempt to diagnose an unrelated issue. Cleaning the repository out completely and starting afresh (remove all files, hg init followed by hg pull) has resolved the problem. Thanks Dmitry :)


Please sign in to leave a comment.