1

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?

Samwise
  • 68,105
  • 3
  • 30
  • 44
Payam30
  • 689
  • 1
  • 5
  • 20

1 Answers1

1

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}")
Samwise
  • 68,105
  • 3
  • 30
  • 44
  • Thank you. Should I run those command in turn? First integrate, then resolve and then submit? That resolve command will resolve only that changelist? – Payam30 Apr 05 '20 at 23:08
  • The `resolve` command will resolve any open files that currently require resolve. I don't know enough about the rest of your application to suggest the easiest way to keep the branch workflow from interfering with other workflows; there are many possible solutions but to handle every possible edge case (race conditions with other clients, interactive conflict resolution, etc) will need much more code than the three lines I gave you! :) – Samwise Apr 06 '20 at 00:52
  • Note that Perforce natively handles all those conditions for you very gracefully, but that assumes that you're using it via a normal client and can respond to things like merge conflicts, and/or have contextual awareness so you don't step on your own toes. When you're trying to fully automate everything within an environment where humans are also operating and can be doing anything, you need to do more work to account for possible problem scenarios and handle them as intelligently as a human would. – Samwise Apr 06 '20 at 19:10
  • how about forcing integration and accepting source as resolved. as I did in my update in the original post. – Payam30 Apr 22 '20 at 16:21
  • You can do that, but it's a destructive operation since it'll overwrite whatever is in the target. If in the context of your script you know that nothing that's in the target is valuable, that's a fine tradeoff to make. – Samwise Apr 22 '20 at 16:34
  • Can you please look at my update? what I try to achieve is : if populate didn't work ( because there has been a branch with that name that doesn't exist anymore) use integ. but the code doesn't get to the point where it should integrate. It goes directly to exceptions and stops the program. – Payam30 Apr 25 '20 at 09:52
  • StackOverflow doesn't charge by the post; post a new question if you have a new issue. :) – Samwise Apr 25 '20 at 15:05