How to get --detect-branches to work with git-p4?

吃可爱长大的小学妹 提交于 2019-12-22 03:53:10

问题


My p4 repository has a structure similar to:

//depot/project/branch1
//depot/project/branch2
//depot/project/branch3
... etc

However, when I use git-p4 to clone "project", all 3 branches are not considered as branches and all get cloned into the single master branch.

This is how I'm invoking git-p4:

git-p4 clone --detect-branches //depot/project

I was expecting git-p4 to create a git database for "project" with three branches, and the root of the project would be mapped to the portion of the path after the branch name (for example: if //depot/project/branch1 has a subdirectory called "lib" (//depot/project/branch1/lib) then my local file system should be something like /git_project/lib with 3 git branches).

Is what I'm expecting wrong? Am I invoking git-p4 incorrectly?


回答1:


If you look at git-p4 code (also originally here), you see:

if self.detectBranches:
  branches = self.splitFilesIntoBranches(description)
  for branch in branches.keys():
    ## HACK  --hwn
    branchPrefix = self.depotPaths[0] + branch + "/"

with splitFilesIntoBranches exploring the p4 repo for branches.

So maybe git-p4 clone //depot/project@all --detect-branches would be fine (with the @all as in this SO answer, and the --detect-branches option after the repo path)?

That being said, if the script is not smart enough to manage that, may be a simpler solution is to run it 3 times, one per branch and import the result in one Git repo.




回答2:


I just worked on a related bug with --detect-branches. The script does a few things:

  1. detect the branch names using p4 data
  2. create a map of the parent of each branch
  3. map the files to a specific branch
  4. remove the branch prefix before committing into git

You'll have to follow the code to make sure each step is being done correctly. Using pdb to do this works well enough.

Step 1 and 2 is done in P4Sync.getBranchMapping

Step 3 is done in P4Sync.splitFilesIntoBranches

For step 4. this is done with P4Sync.stripRepoPath. Set a break point there, and you can see if the branches have been detected and files are being renamed properly.



来源:https://stackoverflow.com/questions/2737999/how-to-get-detect-branches-to-work-with-git-p4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!