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

3

7

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 periodic 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?

Immodest answered 17/2, 2011 at 17:58 Comment(2)
No, but I might if it would solve the problem (I know nothing about them).Immodest
Another reason to use something besides Perforce now that it's 2015.Einkorn
P
2

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.

Possing answered 18/2, 2011 at 13:55 Comment(0)
F
5

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.

Francoise answered 17/2, 2011 at 20:2 Comment(0)
P
2

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.

Possing answered 18/2, 2011 at 13:55 Comment(0)
I
0

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.

Immodest answered 7/11, 2014 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.