8

I know that if I need to clone a perforce an existing p4 repository using command

git p4 clone //depot/path/project

But what if I want to multiple p4 paths into one git repo?
say I have the following structure

    //depot---/Path1----/APath/...
           |          |
           |          |
           |          --/BPath/...
           |       
           |     
           ---/Path2----/CPath/...
           |
           |
           ---/Path3

I only want to clone files under //depot/Path1/APath/ and //depot/Path2/CPath/ in my local directory ~/Desktop/mylocalRepo/ how to do it?

bufferoverflow76
  • 767
  • 1
  • 8
  • 23

2 Answers2

5

The solution that I found was clonning different Perforce paths into different Git repositories and later merge them into a new repository while keeping the history.

//depot/Projects/A
...
//depot/Projects/C
//depot/Projects/...

Clonning Perforce repository into git:

git p4 clone //depot/Projects/A@all
git p4 clone //depot/Projects/C@all

Then create an empty Git repository:

mkdir project
cd project
git init

Add repositories path:

git remote add -f a ../A
git remote add -f c ../C

Merge Project A:

git merge --allow-unrelated-histories a/master

Move Project A into a subdir:

mkdir dir_a
find . -maxdepth 1 -not -name ".git" -and -not -name "dir_a" -exec git mv {} dir_a/ \;

Commit changes:

git commit -m "Merge Project A"

Merge Project C:

git merge --allow-unrelated-histories c/master
mkdir dir_c
find . -maxdepth 1 -not -name ".git" -and -not -name "dir_a" -and -not -name "dir_c" -exec git mv {} dir_c/ \;
git commit -m "Merge Project C"

Using Git:

$ git --version
git version 2.14.1
  • This method makes sense to me. But it failed for me because I had crlf issues, probably due to my use of cygwin with a binary mount point. When I tried to use git config core.autocrlf true to workaround the crlf differences, that resulted in a different issue. In the end I followed a different set of instructions described here: https://stackoverflow.com/questions/21376692/extending-git-p4-clientspec-after-initial-clone , and that avoided the crlf issue. Note that I did use --use-client-spec when I did git p4 clone, then later I added more paths to my p4 client's workspace view. – JeffJ Feb 16 '19 at 21:32
  • I did have success with this. One issue I did find was the history gets duplicated when there is a p4 commit across multiple folders. – GrantByrne Dec 28 '21 at 14:09
0

You can do this with the --use-client-spec option to git-p4. See the "CLIENT SPEC" section in the git-p4 documentation.

When you use this option, git-p4 uses your Perforce client view to map depot paths into your Git repository. By setting up a Perforce client with the mappings you want, you can selectively import parts of your Perforce depot.

benj
  • 713
  • 6
  • 12
  • This is just a repeat of the documentation. An example would be more helpful. – Frank Smith Mar 22 '18 at 12:15
  • Also, the P4 documentation states: "Note: The (untested) git p4 clone --use-client-spec command line option restricts Git-p4 to files that are visible within a Perforce client view. Unfortunately, --use-client-spec is untested, and using it can result in missing files, or exclusion/minus-mapped lines incorrectly treated as inclusions." – Frank Smith Mar 22 '18 at 12:32
  • While this answer looks like it might be correct, it isn't. The `--use-client-spec` flag has no effect on what is cloned where. – Andreas Haferburg Aug 09 '19 at 15:30