bufferoverflow76
bufferoverflow76

Reputation: 797

git clone multiple p4 paths in one git repo

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?

Upvotes: 8

Views: 2540

Answers (2)

Antonio Alecrim
Antonio Alecrim

Reputation: 86

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

Upvotes: 5

benj
benj

Reputation: 723

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.

Upvotes: 0

Related Questions