Wednesday, May 30, 2012

Git-p4: create a new project in Perforce

The wiki and tutorial of Git-P4 usually ask you to clone a project from perforce. Can I create a new project in git and import it into Perforce using Git-P4? I don't know if there is a better way to do it. Here is how I do it:
  • Create a new p4 client spec: bewang-my-app-ws with this map "//depot/my-app/... //bewang-my-app-ws/..."
  • Create a p4 workspace directory: ~/p4-ws/my-app
  • Create .p4config with one line "P4CLIENT=bewang-my-app-ws" under ~/p4-ws/my-app
  • Create a new file in ~/p4-ws/my-app, and check it into perforce.

    Although you can see a Perforce file in nested folders/directories, but there are not such objects (folders/directories) in perforce indeed. You cannot just create an empty folder and check it into Perforce.

    This step creates the depot folder. Otherwise you may see this error when you run "git p4 rebase":

    [bewang@pmaster my-app]$ git p4 rebase 
    Traceback (most recent call last):
      File "/usr/local/bin/git-p4", line 1926, in ?
        main()
      File "/usr/local/bin/git-p4", line 1921, in main
        if not cmd.run(args):
      File "/usr/local/bin/git-p4", line 1716, in run
        sync.run([])
      File "/usr/local/bin/git-p4", line 1673, in run
        changes = p4ChangesForPaths(self.depotPaths, self.changeRange)
      File "/usr/local/bin/git-p4", line 442, in p4ChangesForPaths
        assert depotPaths
    
  • Create a folder for git repository: ~/git/my-app
  • Copy ~/p4-ws/my-app/.p4config to ~/git/my-app/.p4config
  • Run "git p4 clone //depot/my-app ."
  • You should see the file you just checked in and .git folder under ~/git/my-app
  • Work on your git repository
  • Run "git p4 rebase" before you want to check-in into perforce
  • Then run "git p4 submit" to submit each git commit to perforce
  • I can totally work offline without Perforce server

No comments:

Post a Comment