Perforce Public Knowledge Base - 'p4 move' and 'p4 rename' return "Needs toFile" or "Needs fromFile" errors
× PRODUCTS SOLUTIONS CUSTOMERS LEARN SUPPORT
Downloads Company Partners Careers Contact Free Trials
Menu Search
Perforce
Reset Search
 

 

Article

'p4 move' and 'p4 rename' return "Needs toFile" or "Needs fromFile" errors

« Go Back

Information

 
Problem

This article explains why the p4 move and p4 rename commands can return needs toFile and needs fromFile errors, and how to avoid and fix these errors.

Solution

This article explains why the p4 move and p4 rename commands can return needs toFile and needs fromFile errors, and how to avoid and fix these errors.

'p4 move' and 'p4 rename' operations?

To move a file from one depot location to another, or to rename a file, you can use either the p4 move or the p4 rename command (p4 rename is an alias for p4 move). Either command reopens an already-open file, fromFile, creating two pending operations: move/add and move/delete. The target file, toFile, is created with a move/add operation. The source file, fromFile, is erased with a move/delete operation.

'p4 move' and 'p4 rename' operations are atomic - you can't split the move/add and move/delete pair

The p4 move and p4 rename commands are atomic, which means you should think of these move/add and move/delete operations as one single, inseparable pair of operations (a move/add, move/delete pair). It then follows naturally that the move/add, move/delete pair must be submitted in the same changelist.

If you try to split the pair by submitting one of the move/add or move/delete operations without having its partner in the same changelist, your submit will fail with a needs toFile error or needs fromFile error, respectively. The fix for these errors is to reunite the move/add, move/delete pair in the same changelist and resubmit.

Example: Simple Successful 'p4 move'

This example shows the simple case of using the p4 move command to rename a file. Renaming is the same as moving a file from one depot location to another except that the source and destination files are both in the same directory. Exactly the same operations apply to moving a file from one depot directory to another.

Run p4 opened to verify  that you have //depot/src open for edit in the default changelist, and no other files open.

p4 opened
//depot/src #1 - edit default change (text)

Run p4 move.
p4 move //depot/src //depot/dst
//depot/dst#1 - moved from //depot/src#1

Now p4 opened shows the edit has become a move/add, move/delete pair of operations.
p4 opened
//depot/dst#1 - move/add default change (text)
//depot/src#1 - move/delete default change (text)

These submit just fine, as both halves of the move/add, move/delete pair are in the same changelist, in this case the default changelist.
p4 submit -d "Complete move add/deplete pair submits okay."
Submitting change 837.
Locking 2 files ...
move/add //depot/dst#1
move/delete //depot/src#2
Change 837 submitted.

Example: "needs toFile" error and "needs fromFile" error

This example illustrates how a needs toFile error or needs fromFile error situation comes about, and how to resolve it by  reuniting both halves of the move/add, move/delete pair in the same changelist.

Start with an empty changelist and //depot/src already open for edit in the default changelist. No other files are open.
p4 opened
//depot/src#1 - edit default change (text)

p4 changes -s pending
Change 847 on 2012/05/17 by bruno@bruno_ws *pending* 'Changelist description'

p4 describe 847
Change 847 by bruno@bruno_ws on 2012/05/17 11:27:36 *pending*

Changelist description

Affected files ...

Run p4 move.
p4 move //depot/src //depot/dst
//depot/dst#1 - moved from //depot/src#1

p4 opened shows that the edit has become a move/add, move/delete pair in the default changelist.
p4 opened
//depot/dst#1 - move/add default change (text)
//depot/src#1 - move/delete default change (text)

Split the atomic move/add, move/delete pair to create the error condition by reopening //depot/dst, the toFile, in another changelist.
p4 reopen -c 847 //depot/dst
//depot/dst#1 - reopened; change 847

p4 opened
//depot/dst#1 - move/add change 847 (text)
//depot/src#1 - move/delete default change (text)

Now that move operations are split across two changelists, you can't submit either. p4 move (and its alias p4 rename) is required to be atomic, and one half of the inseparable move pair is in the default changelist while the other half in changelist 847.

"needs toFile" Error

If you try to submit the default change you receive a needs toFile error because the default changlist only contains //depot/src, the fromFile.

p4 submit -d "Attempt Move"
Submitting change 848.
Locking 1 files ...
//depot/src - needs tofile //depot/dst
Submit aborted -- fix problems then use 'p4 submit -c 848'.

p4 opened
//depot/dst#1 - move/add change 847 (text)
//depot/src#1 - move/delete change 848 (text) *locked*

"needs fromFile" Error

If you had tried to submit change 847 instead of of the default changelist, you would have received a needs fromFile error, because changelist 847 only contains //depot/dst, the toFile.
p4 submit -c 847
Submitting change 847.
Locking 1 files ...
//depot/dst - needs fromfile //depot/src
Submit aborted -- fix problems then use 'p4 submit -c 847'.

p4 opened
//depot/dst#1 - move/add change 847 (text) *locked*
//depot/src#1 - move/delete default change (text)

To fix this all you need do is reunite the move/add, move/delete pair in the same changelist so they can be submitted together. Use p4 reopen to move fromFile to change 847.
p4 reopen -c 847 //depot/src
//depot/src#1 - reopened; change 847

p4 opened
//depot/dst#1 - move/add change 847 (text)
//depot/src#1 - move/delete change 847 (text) *locked*

p4 submit -c 847
Submitting change 847.
Locking 1 files ...
move/add //depot/dst#1
move/delete //depot/src#2
Change 847 submitted.

It does not matter whether you shift //depot/dst from change 847 to the default changelist or shift //depot/src from the default changelist to changelist 847. As long as the move/addmove/delete pair end up together in the same changelist, the submit will succeed. You could just as well have done the following to reunite the move/addmove/delete pair in the same changelist and successfully submit the move:
p4 reopen -c default //depot/dst
//depot/dst#1 - reopened; default change

p4 opened
//depot/dst#1 - move/add default change (text) *locked*
//depot/src#1 - move/delete default change (text)

p4 submit -d "This works too"
Submitting change 847.
Locking 1 files ...
move/add //depot/dst#1
move/delete //depot/src#2
Change 847 submitted.


 
Related Links

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255