Branching work in progress
Moving workspace edits to a new target directory
PROBLEM
How do I branch work in progress?
What do you do if you have completed work on opened files in your workspace
and then realized that, for one reason or another,
you are not allowed to submit them?
(This could happen, for example, if you found that you have added a new feature in a codeline
designated for bug fixes only, or if the codeline you are working in
was frozen before you completed your work.)
SOLUTION
If you do not want to lose your changes, you can branch your work in progress. This involves branching the files in your workspace, syncing to the newly branched files, then moving your opened files to the new branch path in your client workspace.
For the following example, the initial client view looks like this:
Client: home Root: c:\app-src View: //depot/... //home/...
The files you are working on are located in
//depot/project/...and you want to branch them to the path
//depot/work-project/...
This example uses the MS-DOS command shell; if you are on UNIX you can probably figure out the sh or csh equivalents. In MS-DOS these are the commands you would use:
p4 integ -v //depot/project/...@home //depot/work-project/... p4 submit //depot/work-project/... xcopy/s/i c:\app-src\project c:\app-src\work-project p4 flush //depot/work-project/... p4 diff -sd c:\app-src\work-project... | p4 -x - delete p4 diff -se c:\app-src\work-project... | p4 -x - edit dir/s/b c:\app-src\work-project | p4 -x - add p4 revert //depot/project/...
And here is the detailed explanation of each step:
First, branch the files that you are working on into a work-in-progress branch:
p4 integ -v //depot/project/...@home //depot/work-project/... p4 submit //depot/work-project/...
This creates the new branch in the depot, but does nothing in your workspace. (Note the "@home" revision on the source branch -- "home" is your client name, and using it here assures that the new branch starts out with files at the revisions you were working on. In other words, the @home revision specifier is equivalent to #have for the "home" client.)
Next, use your platform's copy command (cp, xcopy, or Windows
Explorer) to clone the local c:app-src\project path into
c:app-src\work-project:
xcopy/s/i c:\app-src\project c:\app-src\work-project
You now have two identical hierarchies of files.
Next, use p4 flush to make Perforce think it is in sync with the new branch:
p4 flush //depot/work-project/...
Now, open the missing files for delete, the modified files for edit, and the brand new files for add. This is the same procedure used in Working Disconnected to reconcile a workspace after working disconnected.
p4 diff -sd c:\app-src\work-project... | p4 -x - delete p4 diff -se c:\app-src\work-project... | p4 -x - edit dir/s/b c:\app-src\work-project | p4 -x - add
After comparing to make sure everything in c:app-src\work-project
is exactly as you want, switch your client back to the "home" client (with Root: c:\appr-src\project) and revert the edits from the original branch:
p4 revert //depot/project/...
These files will remain in your workspace, but once they have been reverted, there will be no chance of your edits being submitted to the original branch.
The work-project branch is now in exactly the same state that the
project branch was in originally, allowing you to continue making changes
where you left off.
