0

(I am new to perforce and am trying to avoid getting myself into problems, I have hit problems doing this with other source code control systems)

When I rename I class I need to

  • Change the class name it’s self
  • Get Visual Studio to Refactor all the code that uses the class
  • Rename the file in the Visual Studio project
  • Rename the file in Perforce
  • Check the changes into perforce
  • Then maybe merge the change from my working branch into the main branch

What’s the best way to do the above with perforce? What issues to I need to be aware of?

Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317

4 Answers4

2

If you have a new enough version of Perforce, it now supports the move command, which will maintain file history across different names. If this is available, your steps are straightforward and should work just fine (from the Perforce side; I'm less experienced with VS).

If you don't have the move command available, you might want to look at this question for a further discussion on renaming/editing files in Perforce.

Community
  • 1
  • 1
Caleb Huitt - cjhuitt
  • 14,785
  • 3
  • 42
  • 49
  • Thanks, the possible problem is that the "Rename the file in the Visual Studio project" step also renames the file on the disk. – Ian Ringrose Oct 26 '10 at 15:29
  • @Ian Ringrose: It might still work. First, check the file for edit in Perforce, then do the VS move, then the p4 move. P4 might object to the existence of the file in the place it is moving, though; I don't know on that one. – Caleb Huitt - cjhuitt Oct 26 '10 at 16:29
2

This is a multi-step process unfortunately. What you need to do move it first using resharper and then move it again using perforce.

This is how I do it (in Perforce 9.2 and above):

  1. First, checkout the files in Perforce. This will clear the readonly flags for those files and let Resharper modify the files as part of the move.
  2. Use Resharper's Move refactoring and move the classes to the new directory.
  3. The previous step also moved the files from the old folder to the new folder. So now we have to fix that so we can do also do the move operation in Perforce. Use Windows Explorer (or whatever is your favorite tool) to move the files from the new location back to the old location.
  4. Go to Perforce and using the Rename/Move context menu to move the files. This will create a pair entries in the changelist for each file; the first entry is for deleting the file from the original folder and the second entry is for adding it to the new one.
Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317
jop
  • 82,837
  • 10
  • 55
  • 52
  • Could you elaborate more on step #4 please? What exactly are we renaming/moving? I thought ReSharper already _"moved the files from the old folder to the new folder"_ or did I miss something? –  Nov 11 '22 at 03:02
0

I have written a macro for adding a "p4 move -k" action to Visual Sudio's Rename event.
See answer of "How to keep change history while renaming files in Visual Studio using Perforce".

With that macro you can do at least steps 3 and 4 at once by renaming file in Visual Studio.

Community
  • 1
  • 1
brgerner
  • 4,287
  • 4
  • 23
  • 38
0

Have you had a look at the Visual Studio integration (P4SCC) that's available on the Perforce products page? I'd assume that it supports a rename rather nicely (disclaimer: I'm not using Visual Studio with Perforce myself, so I might be wrong).

jhwist
  • 15,201
  • 3
  • 40
  • 47