How can I prevent sending an empty Perforce change list due to an error?

Attempting to submit a change list without files is considered a Perforce error ( p4 submit ... returns exit code 1). This leads to a failure of periodic integration on our build server (we use the Zutubi Pulse system ); , in this case, I would prefer the assembly to be successful , perhaps with a warning.

Pulse has the functionality of reassigning the exit code, but Perforce does not seem ambiguous between the inability to send an empty change list and any other send failure (such a validation trigger failure that I want to build failure).

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

Are there any better methods to handle this that I don't see?

+6
perforce build build-server pulse
source share
3 answers

There are probably no good methods just with Perforce, if I understand your problem correctly. The problem, as you saw, is that the return codes from the command line on the command line are, well, ambiguous. Is presenting an empty change list really a mistake? Maybe, maybe not - it may depend on who you ask.

In fact, it is not recommended to look at return codes from the "p4" commands. Your best bet, as you suggested, is to parse the output of the command, and then do what you need from there.

Most commands now support the -ztag option (see "Using p4 Help"), which can make it easier to parse the output depending on what you want to do. If your case is probably enough to just look for the text in the output, then decide what to do from there.

+3
source share

Before attempting to submit a list of changes, you can delete it first.

p4 change -d ###

This operation will only succeed if the change list is empty, so do not submit it (you just deleted it). If this fails, there are files in the change list, so keep in mind that they are submitted.

However, if you use tasks, this will not work for you, because you cannot delete the list of changes that has a task attached to it, even if it is empty.

+5
source share

In the end, I ended 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 because the p4 message β€œno files” actually calls stderr. If the output is a message, I consider it "safe" I exit with a zero exit code, otherwise the script will continue with any error level set by the p4 command.

Note that the "no files" message for a numbered list of changes is slightly different if you use this.

0
source share

All Articles