perforcep4python

branching when ther has been a a branch with the same name that doesn't exist anymore p4python


While testing my application using p4python I came across an intressting issue. I branch a while ago from a main stream directory to a testing directory, I did a revert on that branching since something was wrong with it so the testing branch disappeared (revert and submit). after fixing the issue, I decided to branch again with the same name but P4python said Can't populate target path when files already exist. That branch isn't there any more I don't understand why p4python would output such error. This is the code I use for branching:

result = p4.run("populate", path +"@"+ changelist, destination)

so my question is how to be able to branch again with the same name if the old branch wth that name is deleted?


Solution

  • The populate command only works for the specific case where you're creating a brand new branch; it doesn't handle any cases where you might potentially need to resolve the source against the target, so it will automatically fail if there are any files (even deleted ones) in the target.

    If the branch was just for testing, you could obliterate it:

    p4 obliterate -y destination/...
    

    Or you could change your code to account for existing files:

    p4.run("integrate", f"{path}@{changelist}", destination)
    p4.run("resolve", "-as")
    result = p4.run("submit", "-d", 
                    f"integrated from {path}@{changelist} to {destination}")