threads / discuss / 26399

git to p4 conversion

Subject: git to p4 conversion

## tl;dr

14 messages between Feb 3, 2011 and Feb 7, 2011.

replies: 13people: 4as markdown or json

Endre Czirbesz· Feb 3, 2011, 13:52 UTC · lore
Hi,

My company is introducing perforce, and the policy is that all source codes should be kept there.

I have some small (and flat) git repos, which I would like to migrate into a perforce depot keeping their histories. I tried git-p4 without any success, and I did not find a good manual for it.

Is there any step-by-step tutorial out there? Is there any living human who ever made a successful conversion in this direction?

Thanks for your help in advance.
Endre Czirbesz
Ian Wienand· Feb 3, 2011, 18:23 UTC · re: Endre Czirbesz · lore

Re: git to p4 conversion

On 03/02/11 05:52, Endre Czirbesz wrote:
> I have some small (and flat) git repos, which I would like to migrate
> into a perforce depot keeping their histories. I tried git-p4 without
> any success, and I did not find a good manual for it.
What exactly did you try?

Theoretically, you could clone your new, empty, company-mandated p4 tree into a fresh git repo, get your existing code onto a new branch in this fresh repo (it's already in git, right, so that should be easy), then use 'git-p4 submit' to submit that branch back to p4.

> Is there any step-by-step tutorial out there? Is there any living human
> who ever made a successful conversion in this direction?
I'm not aware of an existing tutorial for this, sorry
-i
Endre Czirbesz· Feb 3, 2011, 19:50 UTC · re: Ian Wienand · lore

Re: git to p4 conversion

Hello Ian,
Thanks for your reply.
2011/2/3 Ian Wienand <ianw@vmware.com>:
> What exactly did you try?
I am not at my work computer now, but as I remember:

cd workdir git-p4 clone //depot/projectdir/...@all . git clone myprojectrepo .

(Everything went fine till this point.)

git-p4 sync git-p4 submit Fatal error...

I don't remember the exact message, but it tried to reach a non-existing git commit (HEAD~xx, where xx was count of my commits, so it tried to refer to a commit before my initial commit). I tried to change the order of the clone steps, but the result was the same.

Rgds,
Endre
Vitor Antunes· Feb 4, 2011, 00:03 UTC · re: Endre Czirbesz · lore

Re: git to p4 conversion

Hi Endre,
Endre Czirbesz <endre <at> czirbesz.hu> writes:
Show 12 quoted lines
> 
> Hello Ian,
> 
> Thanks for your reply.
> 
> 2011/2/3 Ian Wienand <ianw <at> vmware.com>:
> > What exactly did you try?
> I am not at my work computer now, but as I remember:
> 
> cd workdir
> git-p4 clone //depot/projectdir/...@all .
> git clone myprojectrepo .

I think what you should do is add the git repository as a remote with something like:

git remote add remotename myprojectrepo git pull remotename master git p4 submit

Hope this helps, Vitor

Tor Arvid Lund· Feb 4, 2011, 09:25 UTC · re: Vitor Antunes · lore

Re: git to p4 conversion

[on this mailing list, please don't cull the CC list]
On Fri, Feb 4, 2011 at 1:03 AM, Vitor Antunes <vitor.hda@gmail.com> wrote:
> Hi Endre,
>
<snip>
Show 6 quoted lines
> I think what you should do is add the git repository as a remote with something
> like:
>
> git remote add remotename myprojectrepo
> git pull remotename master
> git p4 submit

That's not what I would do... When I try this, the 'git pull ...' creates a merge, which I don't want to do when using git-p4.

But I think we're close to something that would work ok:

Endre, you should start like you already have; by git-p4 cloning your project from perforce. (You maybe want to have a dummy file checked in to your <projectdir> in perforce, so that the 'git-p4 clone' command produces at least one commit in your git repo)...

Then, do 'git remote add tempremote <path-to-your-existing-git-repo>' like Vitor suggests.

At this point I would do:

$ git checkout -b tempbranch tempremote/master $ git rebase master $ git-p4 submit

So, the 'git rebase master' should be like applying each of your existing git commits *on-top-of* the git-p4 branch that you already have. And that is the key to git-p4 knowing what to push to the perforce server.

Thus, if I wanted to get all my existing git history into perforce, this is how I would do it.

    -- Tor Arvid
Endre Czirbesz· Feb 4, 2011, 10:49 UTC · re: Tor Arvid Lund · lore

Re: git to p4 conversion

Hi All,
Thanks for the replies.
2011/2/4 Tor Arvid Lund <torarvid@gmail.com>:
> On Fri, Feb 4, 2011 at 1:03 AM, Vitor Antunes <vitor.hda@gmail.com> wrote:
>> git remote add remotename myprojectrepo
Show 11 quoted lines
> Endre, you should start like you already have; by git-p4 cloning your
> project from perforce. (You maybe want to have a dummy file checked in
> to your <projectdir> in perforce, so that the 'git-p4 clone' command
> produces at least one commit in your git repo)...
>
> Then, do 'git remote add tempremote <path-to-your-existing-git-repo>'
> like Vitor suggests.
>
> At this point I would do:
>
> $ git checkout -b tempbranch tempremote/master

At this point I got an error message: fatal: git checkout: updating paths is incompatible with switching branches.

So I fetched my tempremote first: $ git fetch tempremote $ git checkout -b tempbranch tempremote/master (I got a warning from fetch, that there are no common commits, but I supposed that it is right. :) )

> $ git rebase master
It applied all my commits.
> $ git-p4 submit
  Synchronizing p4 checkout...
  ... - file(s) up-to-date.
  Applying 1##############################9 Initial commit
  error: ***: already exists in working directory
[...]
  Unfortunately applying the change failed!

It said this error for all my files. :( But I think we are almost there. :)

Regards,
Endre
Tor Arvid Lund· Feb 4, 2011, 14:01 UTC · re: Endre Czirbesz · lore

Re: git to p4 conversion

On Fri, Feb 4, 2011 at 11:49 AM, Endre Czirbesz <endre@czirbesz.hu> wrote:
Show 25 quoted lines
> Hi All,
>
> Thanks for the replies.
>
> 2011/2/4 Tor Arvid Lund <torarvid@gmail.com>:
>> On Fri, Feb 4, 2011 at 1:03 AM, Vitor Antunes <vitor.hda@gmail.com> wrote:
>>> git remote add remotename myprojectrepo
>
>> Endre, you should start like you already have; by git-p4 cloning your
>> project from perforce. (You maybe want to have a dummy file checked in
>> to your <projectdir> in perforce, so that the 'git-p4 clone' command
>> produces at least one commit in your git repo)...
>>
>> Then, do 'git remote add tempremote <path-to-your-existing-git-repo>'
>> like Vitor suggests.
>>
>> At this point I would do:
>>
>> $ git checkout -b tempbranch tempremote/master
> At this point I got an error message:
> fatal: git checkout: updating paths is incompatible with switching branches.
>
> So I fetched my tempremote first:
> $ git fetch tempremote
> $ git checkout -b tempbranch tempremote/master

See, this is what happens when I write a "how-to" and not actually try it out before sending it... Obviously, you are correct in that you have to fetch it before being able to check it out :-)

> (I got a warning from fetch, that there are no common commits, but I
> supposed that it is right. :) )
That is correct.
Show 13 quoted lines
>> $ git rebase master
> It applied all my commits.
>
>> $ git-p4 submit
>  Synchronizing p4 checkout...
>  ... - file(s) up-to-date.
>  Applying 1##############################9 Initial commit
>  error: ***: already exists in working directory
> [...]
>  Unfortunately applying the change failed!
>
> It said this error for all my files. :(
> But I think we are almost there. :)
Again, if only I'd tried it myself first! ;)

Well, I can get it to work if I do: $ git p4 sync

before the 'git p4 submit'.

Try that, and see if it works for you. (BTW, when committing half-works, and then fails, oftentimes you need to do a bit of cleanup in perforce... Revert files, manually remove files created by git inside your p4 clientspec root directory, that sort of thing...)

    -- Tor Arvid
Endre Czirbesz· Feb 4, 2011, 16:08 UTC · re: Tor Arvid Lund · lore

Re: git to p4 conversion

2011/2/4 Tor Arvid Lund <torarvid@gmail.com>:
> Well, I can get it to work if I do:
> $ git p4 sync
>
> before the 'git p4 submit'.
Same result. :(
My current workflow is:

$ rm -rf projdir $ git-p4 clone //depot/projdir/...@all $ cd projdir $ git remote add gitremote endre@gitserver/gitrepo.git $ git fetch -q gitremote $ git checkout -b tempbranch gitremote/master $ git rebase -q master $ git-p4 sync $ git-p4 submit

The result is still tons of file already exists in working directory messages.
> Try that, and see if it works for you. (BTW, when committing
> half-works, and then fails, oftentimes you need to do a bit of cleanup
> in perforce... Revert files, manually remove files created by git
> inside your p4 clientspec root directory, that sort of thing...)

I dropped the whole directory, and then recreated it, I do not know any better 'cleanup'. :)

Rgds,
Endre
Endre Czirbesz· Feb 4, 2011, 16:52 UTC · lore

Re: git to p4 conversion

Hi Vitor,
2011/2/4 Vitor Antunes <vitor.hda@gmail.com>:
Show 6 quoted lines
>> I dropped the whole directory, and then recreated it, I do not know
>> any better 'cleanup'. :)
>
> Which directory did you drop? Was is the git repository or the P4 workspace?
> You need to clean up the later. Basically, a "rm -rf
> path/to/p4_workspace" and a "p4 sync -f" should do the trick :)

It is almost the same in my case. :) My p4 client root is ~/work/, my project dir is ~/work/projdir (and at the moment this is the only directory within ~/work/), and I dropped the latter. And then it was created again by git-p4 clone.

I can drop the workspace root, but I do not think it would help.
Regards,
Endre
Tor Arvid Lund· Feb 5, 2011, 00:53 UTC · re: Endre Czirbesz · lore

Re: git to p4 conversion

On Fri, Feb 4, 2011 at 5:52 PM, Endre Czirbesz <endre@czirbesz.hu> wrote:
Show 15 quoted lines
> Hi Vitor,
>
> 2011/2/4 Vitor Antunes <vitor.hda@gmail.com>:
>>> I dropped the whole directory, and then recreated it, I do not know
>>> any better 'cleanup'. :)
>>
>> Which directory did you drop? Was is the git repository or the P4 workspace?
>> You need to clean up the later. Basically, a "rm -rf
>> path/to/p4_workspace" and a "p4 sync -f" should do the trick :)
>
> It is almost the same in my case. :)
> My p4 client root is ~/work/, my project dir is ~/work/projdir (and at
> the moment this is the only directory within ~/work/), and I dropped
> the latter.
> And then it was created again by git-p4 clone.
I... wonder if we're maybe talking past one another here...

Let's take a few things from the top, just in case... If we think about the perforce setup (before we start doing any git stuff)... You have a perforce workspace/client-spec, right? That is - a setup that tells perforce where you want the files to be placed on your hard drive when you do a standard "p4 sync". Let's call it ~/p4root/ and let us say that your project will then be synced by perforce to ~/p4root/myproj/

When you want to do a git-p4 clone, you should definitely be *outside* of ~/p4root/ . Let's say we have a ~/gitroot/ as well. So do cd ~/gitroot/ so that the git-p4 clone will be under ~/gitroot/myproj/ ; and then do all the git-p4 stuff (clone, add remote, fetch, rebase, sync, submit).

I think Vitors point was that before you do git-p4 submit, you should clean - not ~/gitroot/myproj - but ~/p4root/myproj/.

This is probably not something that you need to do everytime you want to submit back to perforce, but since we have had some rounds with trial-and-error with this, we have probably placed some dirty files inside the perforce folders... Make sure that you don't have files opened in perforce before you sync.

Clearer? More confused? Best of luck anyway :)
    -- Tor Arvid
Vitor Antunes· Feb 5, 2011, 01:11 UTC · re: Tor Arvid Lund · lore

Re: git to p4 conversion

Hi Tor,
On Sat, Feb 5, 2011 at 12:53 AM, Tor Arvid Lund <torarvid@gmail.com> wrote:
Show 29 quoted lines
> I... wonder if we're maybe talking past one another here...
>
> Let's take a few things from the top, just in case... If we think
> about the perforce setup (before we start doing any git stuff)... You
> have a perforce workspace/client-spec, right? That is - a setup that
> tells perforce where you want the files to be placed on your hard
> drive when you do a standard "p4 sync". Let's call it ~/p4root/ and
> let us say that your project will then be synced by perforce to
> ~/p4root/myproj/
>
> When you want to do a git-p4 clone, you should definitely be *outside*
> of ~/p4root/ . Let's say we have a ~/gitroot/ as well. So do cd
> ~/gitroot/ so that the git-p4 clone will be under ~/gitroot/myproj/ ;
> and then do all the git-p4 stuff (clone, add remote, fetch, rebase,
> sync, submit).
>
> I think Vitors point was that before you do git-p4 submit, you should
> clean - not ~/gitroot/myproj - but ~/p4root/myproj/.
>
> This is probably not something that you need to do everytime you want
> to submit back to perforce, but since we have had some rounds with
> trial-and-error with this, we have probably placed some dirty files
> inside the perforce folders... Make sure that you don't have files
> opened in perforce before you sync.
>
> Clearer? More confused? Best of luck anyway :)
>
>    -- Tor Arvid
>

Yeah, I think we're in sync here. I'm almost sure your (much more detailed) instructions will solve Endre's problem :)

Kind regards,
-- 
Vitor Antunes
Endre Czirbesz· Feb 7, 2011, 13:57 UTC · re: Vitor Antunes · lore

Re: git to p4 conversion

Hi,

Thanks for your patience and the detailed help. I forgot only one thing, that I need two separate directories... :)

So, after some minor mods in git-p4 (I have some directories with spaces, and some files with #@*% in their names), it seems as if it worked, my files are in P4 depot, although I got an error message:

Failed to merge in the changes. Patch failed at 0001 Initial commit

When you have resolved this problem run "git rebase --continue". If you would prefer to skip this patch, instead run "git rebase --skip". To restore the original branch and stop rebasing run "git rebase --abort".

Exception: command failed: git rebase remotes/p4/master
Regards,
Endre
Tor Arvid Lund· Feb 7, 2011, 14:13 UTC · re: Endre Czirbesz · lore

Re: git to p4 conversion

On Mon, Feb 7, 2011 at 2:57 PM, Endre Czirbesz <endre@czirbesz.hu> wrote:
Show 17 quoted lines
> Hi,
>
> Thanks for your patience and the detailed help.
> I forgot only one thing, that I need two separate directories... :)
>
> So, after some minor mods in git-p4 (I have some directories with
> spaces, and some files with #@*% in their names), it seems as if it
> worked, my files are in P4 depot, although I got an error message:
>
> Failed to merge in the changes.
> Patch failed at 0001 Initial commit
>
> When you have resolved this problem run "git rebase --continue".
> If you would prefer to skip this patch, instead run "git rebase --skip".
> To restore the original branch and stop rebasing run "git rebase --abort".
>
> Exception: command failed: git rebase remotes/p4/master

Maybe you could run "git p4 submit --verbose"? (the 'verbose' option might give you a clue as to what the underlying problem is)

    -- Tor Arvid
> Regards,
>
> Endre
>
Endre Czirbesz· Feb 7, 2011, 15:07 UTC · re: Tor Arvid Lund · lore

Re: git to p4 conversion

2011/2/7 Tor Arvid Lund <torarvid@gmail.com>:
> Maybe you could run "git p4 submit --verbose"? (the 'verbose' option
> might give you a clue as to what the underlying problem is)
I did that actually, just did not want to send the whole output. :)

I will investigate it further, but my boss gave a new highest priority task for me... :(

Endre

← back to recent threads