views:

134

answers:

1

At work, development uses perforce to handle code sharing. I won't say "revision control", because we aren't allowed to check in changes until they are ready for regression testing. In order to get my personal change sets under revision control, I've been given the go-ahead to build my own git and initialize the client view of the perforce depot as a git repo.

There are some difficulties in doing this, however.

  1. The client view lives in a subfolder of ~, (~/p4), and I want to put ~ under revision control as well, with its own separate history. I can't figure out how to keep the history for ~ separate from ~/p4 without using a submodule. The problem with a submodule is that it looks like I have to go make a repository that will become the submodule and then git submodule add <repo> <path>. But there is nowhere to make the submodule's repository except in ~. There seems to be no safe place to create the initial client view of the depot with git p4 clone.

    (I'm working off of the assumption that initing or cloning a repo into a subdirectory of a git repo is not supported. At least, I can find nothing authoritative on nested git repos.)

    edit: Is merely ignoring ~/p4 in the repo rooted at ~ enough to allow me to init a nested repo in ~/p4? My __git_ps1 function still thinks I'm in a git repository when I visit an ignored subdirectory of a git repo, so I'm inclined to think not.

  2. I need the "remote" repository created by git p4 sync to be a branch in ~/p4. We are required to keep all of our code in ~/p4 so that it doesn't get backed up. Can I pull from a "remote" branch that is really a local branch?

  3. This one is just for convenience, but I thought I could learn something by asking it. For 99% of the project, I just want to start the with the p4 head revision as the inital commit object. For the other 1%, I would like to suck down the entire p4 history so that I can browse it in git. IOW, after I'm done initalizing it, the initial commit of remotes/p4/master branch will contain:

    revision 1 of //depot/prod/Foo/Bar/*
    revision X of other files in //depot/prod/*, where X is the head revision
    

    and the remotes/p4/master branch contains Y commits, where Y is the number of changelists that had a file in //depot/prod/Foo/Bar/*, with each commit in the history corresponding to one of those p4 changelists, and HEAD looking like p4's head.

Edit: meagar's answer didn't quite work for me.

I have initalized ~ and checked in a few commits to it. I have ignored ~/p4 and ~/p4 is not in any commit object.=:

[~@ernie02] (master) $ git show HEAD:p4
fatal: Path 'p4' exists on disk, but not in 'HEAD'.

I then went to ~/p4/prod, a branch I want to check out. But this repo is broken:

[~/p4/prod@ernie02] (master) $ git log
(shows the log for the repo rooted at ~)
[~/p4/prod@ernie02] (master) $ git init
Initialized empty Git repository in ~/p4/prod/.git/
[~/p4/prod@ernie02] (master) $ git log
fatal: bad default revision 'HEAD'

Edit edit: Oops, I forgot to commit something to ~/p4/prod. I'm trying a git p4 sync //depot/prod to it now...

+2  A: 

In answer to #1, if you really want to have your whole home directory in a git repository, but have ~/p4 in a seperate repository, just add "p4" to .git_ignore in your home directory, and make another repo in p4:

$ cd ~
$ git init
$ echo "p4" > .git_ignore
$ git add .git_ignore
# add all files/directories except p4
$ git commit
$ cd p4
$ git init
$ git add .
$ git commit

I don't quite follow #2, but yes, you can pull from a "remote" repo that is local to your file system. As far as "pulling" from local branches, that isn't pulling; pulling involves a fetch and a merge. If you omit the fetch, it's just a merge, so you're really talking about merging from a local branch.

meagar