Difference between revisions of "Using git-p4"

From LSDevLinux
Jump to: navigation, search
m (With a topic branch)
m (Categorize)
Line 93: Line 93:
  
 
You may find it helpful to browse and view history using gitk and make commits and manage your index using git-cola.
 
You may find it helpful to browse and view history using gitk and make commits and manage your index using git-cola.
 +
 +
[[Category:Linux tools]]

Revision as of 23:07, 11 June 2010

Using git as a front-end to the Perforce FieldWorks repository.

While p4v has many good features, some developers may be more comfortable using a different front-end to the Perforce FieldWorks repository, such as git-p4. Note that you will still need a Perforce checkout on your machine for git-p4 to commit back to Perforce (see Build_FieldWorks#Check_out_from_VCS for information on checking out from Perforce).

Install git-p4

Install dependencies

Install p4

The latest version of p4 can be found at http://www.perforce.com/perforce/downloads/.

$ cd $(mktemp -dt)
$ http_proxy=proxy.example.com:1234 wget 'http://www.perforce.com/downloads/perforce/r09.2/bin.linux26x86/p4'
$ sudo install p4 /usr/local/bin

Append to ~/.bashrc:

export P4CLIENT=your_workspace_name
export P4PORT=src.sil.org:1934 (or hydra:1935)
export P4USER=your_username (or anonymous)

Close and re-open your terminal.

git-p4

~$ git clone git://github.com/ermshiperete/git-p4.git

Link to the git-p4 script from a directory in your PATH, such as ~/bin:

$ mkdir ~/bin && cd ~/bin
bin$ ln -s ~/git-p4/git-p4

Updating git-p4

To update git-p4, do

$ cd ~/git-p4
git-p4$ git pull

Check out repository using git-p4

Prepare a place for the code:

$ mkdir -p ~/gp/Calgary
$ cd ~/gp/Calgary

Check out from Perforce using git-p4:

gp/Calgary$ git-p4 clone //depot/Calgary/WW

In the gp/Calgary directory, you will need COM, Win32Base, and Win32More, or symlinks to them if they are already checked out elsewhere. See Build_FieldWorks#Check_out_libcom_from_svn for information on checking out libcom from svn.

If you already have COM, Win32Base, and Win32More checked out where Build_FieldWorks#Check_out_libcom_from_svn prescribes, then you can just symlink to them by doing:

gp/Calgary$ for dir in ~/p4repo/Calgary/{COM,Win32Base,Win32More}; do ln -s $dir; done

Alternate usage of git-p4

Instead of creating a link in ~/bin you can create a link in /usr/lib/git-core/git-p4:

$ cd /usr/lib/git-core
$ sudo ln -s ~/git-p4/git-p4

This will add git-p4 as a regular git command, so you can e.g. clone a Perforce repo with:

$ git p4 clone //depot/Calgary/WW

Workflow

There is a readme about a different version of git-p4 at http://github.com/dtrott/git-p4 .

Your workflow might look like:

  • Edit files
$ vim foo.cs
  • Commit locally
$ git commit
  • Update from Perforce
$ git stash
$ git-p4 rebase
$ git stash pop
  • Commit your work to Perforce
$ git stash
$ git-p4 rebase
$ git-p4 submit
$ git-p4 rebase
$ git stash pop

With a topic branch

If your master is tracking remotes/p4/master, you made a topic branch "crashbug" to work on a bug or feature, and you've made several commits to crashbug but don't want to push all of them since they aren't all ready, but you do want to push just one or two right now, you can push by:

# Cherry pick some_commit from crashbug
$ git checkout master && git p4 rebase && git cherry-pick some_commit
$ git p4 submit && git p4 rebase
$ git checkout crashbug && git merge master

Quirks

Renaming files

git-p4 has the option -M to track renames (consistent with git-diff and git-log, see [1]), i.e. the following command will correctly record renames as integrations in Perforce:

$ git-p4 submit -M

As of commit c1dcb20fe8 tracking renames can be added to the git config file (works if you use "git p4...", not sure if it also works if you use "git-p4..."):

For current repo:

$ git config git-p4.detectRename true

Globally for any repos:

$ git config --global git-p4.detectRename true

Protecting csproj files

Since your files are read-write by default when you use git-p4 (rather than read-only when using p4v), you may want to protect .csproj files most of the time so that monodevelop does not rewrite them when you don't want it to. You can easily do that by running:

gp/Calgary/WW$ find -name \*csproj -print0 | xargs -0 chmod u-w

To make a csproj writable again, run:

gp/Calgary/WW$ chmod u+w Src/Foo/Baz.csproj

It may be easier to edit the csproj by hand depending on what you want to change.

Git GUI tools

There are numerous git GUI tools available.

You may find it helpful to browse and view history using gitk and make commits and manage your index using git-cola.