Adam Naylor
Adam Naylor

Reputation: 6330

Possible to branch in Perforce without creating a new folder?

Is it possible to create branches in Perforce in a similar style to Git? I.e. without creating a new folder.

I would prefer for my client to manage the branches transparently whilst I work against a single copy of the directory tree on disk.

It seems awfully wasteful for the client to create an exact copy of the entire tree if you're only modifying say a couple of files. I much prefer Git's workflow in this regard.

If it's not possible using straight Perforce I'm happy to move to GitSwarm.

For info I'm running Perforce version 2015.1/1233444.

Upvotes: 1

Views: 942

Answers (3)

John Williston
John Williston

Reputation: 11

My original answer was deleted because I thought a link was a better idea than repeating content. My mistake.

At any rate, I believe the DVCS features in Perforce Helix supply exactly the sort of thing you're after. In a blog I wrote in the subject (link here for reference) I explained how to create a new in-place branch with a single command:

p4 switch -c newBranchName

That will create a new branch with the name "newBranchName" and save any existing work in progress by default. To discover on which branch you're working you can use the switch command with the list argument as follows:

p4 switch -l

That would show you output like this, the asterisk showing that you're now working on the newBranchName branch.

newBranchName * 
main

You can switch back and forth as you like, changing contexts as needed as often as you like. Your work in progress will continue to be saved on each branch in progress. When you're ready to merge your work back to main and push it back to the server, you can use the following sequence of commands:

p4 switch main
p4 merge --from newBranchName
p4 resolve –as

The first command switches back to the main branch, the second merges your work from the newly created branch into main, and the third resolves any potential conflicts automatically. If there are any conflicts that can't automatically be merged, then you can use the usual commands to walk through the resolution process.

Alternately, if you prefer to stick with Git, you can use that directly with our Helix Versioning Engine through our Git Fusion technology or use Git directly with our new GitSwarm technology. That is a pretty amazing option (in my opinion) as it makes it possible to mirror content automatically and bidirectionally between GitSwarm and the back end server. That way you get all the features of Git with GitSwarm (which itself is based on GitLab) and all the goodies from the rest of Helix.

Hope that helps!

Upvotes: 1

Samwise
Samwise

Reputation: 71454

If you use streams (Perforce's "managed" version of a branch, as opposed to doing completely ad hoc inter-file branching with arbitrary paths), it's pretty simple. As P4Gabe said, "switch -c" is a one-shot option on a local server.

On a shared server it's only a little more complicated because you have to do the "populate" explicitly (this is to keep naive users from accidentally branching lots of files lots of times on a shared server), but it's still only a few steps and it's something that you as an advanced user could script easily:

  1. p4 stream -P (current stream) -t development (new stream name)
  2. p4 populate -r -S (new stream name)
  3. p4 switch (new stream name)

The equivalent is possible using ad hoc ("classic") branches as well if you have a good understanding of how client views work -- use populate to create the new branch, modify your client view to map the new branch into the namespace currently occupied by the old branch, and sync.

This blog post on what exactly "p4 switch" does might help if you're trying to engineer your own solution that's similar-to-but-not-quite the "switch" command: https://www.perforce.com/blog/150428/p4-switch-switching-it

Upvotes: 0

Gabe Weiss
Gabe Weiss

Reputation: 3332

Possible yes, but with the centralized version of the system it involves a bit of 'magic'. Basically, the branch part doesn't need to involve the client at all anymore. Take a peek at p4 populate. That'll create another folder on the server, but won't do anything locally. Then you can edit your client workspace to map the branched files instead of the trunk files, and it'll just re-sync over top the files on your disk.

Now, having said that, if you wanted to take a look at our DVCS version of working, then you can just do "p4 switch -c " and it'll create a new branch locally, switch your workspace over to it (shelving any open current work in the process) and away you go.

Upvotes: 1

Related Questions