开发者

How can I prevent submitting an empty Perforce changelist from being an error?

开发者 https://www.devze.com 2023-02-11 12:06 出处:网络
Attempting to submit a changelist with no files is considered by Perforce to be an error (p4 submit ... returns exit code 1). This causes a perio开发者_如何转开发dic integration build to fail on our b

Attempting to submit a changelist with no files is considered by Perforce to be an error (p4 submit ... returns exit code 1). This causes a perio开发者_如何转开发dic integration build to fail on our build server (we're using Zutubi's Pulse system); in this case I would rather have the build succeed, possibly with a warning.

Pulse has exit code remapping functionality, but Perforce does not appear to disambiguate between a failure to submit an empty changelist and any other submit failure (such a validation trigger failure, which I do want to fail the build).

The immediately obvious (but, in my mind, inelegant) solution that comes to mind is to wrap execution of p4 submit in a batch file that first checks to see if the target changelist is empty by counting lines of output from p4 opened -- or just parsing the output of p4 submit for the "no files" message and returning successfully from the batch file.

Are there better techniques for handling this that I'm not seeing?


Before attempting to submit a changelist, you could first attempt to delete it.

p4 change -d ###

This operation will only succeed if the changelist is empty, so don't submit it (you have just deleted it). If it fails, there are files in the changelist, so go ahead and submit them.

However, if you use jobs, this won't work for you because you can't delete a changelist that has a job attached to it, even if it's empty.


There are probably no good techniques just with Perforce, if I am understanding your problem correctly. The issue, as you have seen, is that the return codes from perforce command line runs are, well, ambiguous. Is a submission of an empty changelist really an error? Maybe, maybe not - might depend on who you ask.

It's is not really that advisable to look at return codes from 'p4' commands. Your best bet as you have suggested is to parse the output of the command and then do what you need to from there.

Most commands now support the -ztag option (see 'p4 help usage'), which will could make parsing the output a bit easier, depending on what you want to do. If your case, it is probably sufficient enough to just look for the text in the output and then decide what to do from there.


I did ultimately end up parsing the output in a batch file, using something like this:

for /f "delims=" %%I in ('p4 submit -d "<message>" 2^>^&1 1^>NUL') do    
set SUBMIT_OUTPUT=%%I
if "%SUBMIT_OUTPUT%"=="No files to submit from the default changelist." exit /b 0

This is necessary since p4's "no files" message is actually writting to stderr normally. If the output is the message I consider "safe" I exit with a zero exit code, otherwise the script will continue with whatever error level was set by the p4 command.

Note that the "no files" message for a numbered changelist is slightly different, if you're using that.

0

精彩评论

暂无评论...
验证码 换一张
取 消