git-p4将perforce的“main”分支迁移到git分支中作为子目录(在git分支中存在重复代码)

4

问题描述

尝试从Perforce迁移到Git的过程中,需要将一个“主”分支和两个分支映射到Perforce。在使用规范将分支映射到Perforce后,我尝试了一次典型的迁移,但是遇到了代码目录重复的问题。

问题原因

当运行“git p4”(无论是克隆还是同步)时,主分支代码的副本与分支一起包含在内,并且分支代码位于与主分支相邻的目录中。我希望在Git暂存区中只看到分支代码。

设置

#Perforce Repo Structure
//depot/main/branches/MAINT_01
//depot/main/branches/MAINT_02
//depot/main/branches/mobile

# perforce branch maps
# note: mobile and MAINT_02 are branched (in perforce) from MAINT_01
MAINT_02 -> //depot/main/branches/MAINT_01/... //depot/main/branches/MAINT_02/...
mobile  -> //depot/main/branches/MAINT_01/... //depot/main/branches/mobile/...

# Perforce info
Server version: P4D/LINUX26X86_64/2009.2/241896 (2010/04/10)
Client Spec: (need to exclude many branches here)
//depot/main/branches/... //buildmaster-scm01/...
-//depot/main/branches/BranchA/... //buildmaster-scm01/BranchA/...
-//depot/main/branches/BranchB/... //buildmaster-scm01/BranchB/...
-//depot/main/branches/tempBranch/... //buildmaster-scm01/tempBranch/...
-//depot/main/branches/Bar/... //buildmaster-scm01/Bar/...
-//depot/main/branches/Foo/... //buildmaster-scm01/Foo/...
-//depot/main/branches/Cheese/... //buildmaster-scm01/Cheese/...

# Git Info (Linux Box)
 /git/buildmaster/git2 302  % git --version
 git version 1.7.12.rc2

迁移尝试

以下是具体过程...

agvscm01.inq.com /git/buildmaster/git 225  % git init
Initialized empty Git repository in /git/buildmaster/git/.git/
agvscm01.inq.com /git/buildmaster/git 226  % git p4 sync --detect-branches --use-client-spec //depot/main/branches@all
Importing revision 20482 (88%)
    Importing new branch branches/MAINT_01

    Resuming with change 20482
Importing revision 21137 (96%)
    Importing new branch branches/mobile

    Resuming with change 21137
Importing revision 21396 (100%)
Updated branches: MAINT_01 MAINT_02 mobile
agvscm01.inq.com /git/buildmaster/git 227  % git checkout -b master p4/branches/MAINT_01
Checking out files: 100% (14923/14923), done.
Already on 'master'
agvscm01.inq.com /git/buildmaster/git 228  % git checkout -b rel_2 p4/branches/MAINT_02
Checking out files: 100% (15142/15142), done.
Switched to a new branch 'rel_2'
agvscm01.inq.com /git/buildmaster/git 229  % git checkout -b mobile p4/branches/mobile
Checking out files: 100% (29960/29960), done.
Switched to a new branch 'mobile'
agvscm01.inq.com /git/buildmaster/git 233  % git checkout master
Switched to branch 'master'
  agvscm01.inq.com /git/buildmaster/git2 303  % git branch -a
* master
  mobile
  rel_2
  remotes/p4/branches/MAINT_01
  remotes/p4/branches/MAINT_02
  remotes/p4/branches/mobile

结果

agvscm01.inq.com /git/buildmaster/git2 304  % git checkout mobile
Checking out files: 100% (15073/15073), done.
Switched to branch 'mobile'
agvscm01.inq.com /git/buildmaster/git2 305  % ls
MAINT_01  mobile
agvscm01.inq.com /git/buildmaster/git2 306  %

请注意,MAINT_01和mobile目录都有正确的历史记录,但是只应该在此级别看到mobile目录的内容。
期望:
在mobile分支中不应包括MAINT_01目录。 mobile是MAINT_01的一个分支。这可能是非常简单的问题,但我看不出来。此外,检出主分支只包括MAINT_01作为根目录。 MAINT_01的内容应该是分支的根目录。
agvscm01.inq.com /git/buildmaster/git2_bak 307  % git checkout master
Switched to branch 'master'
agvscm01.inq.com /git/buildmaster/git2_bak 308  % ls
MAINT_01
agvscm01.inq.com /git/buildmaster/git2_bak 309  %

非常感谢您在这里提供的任何帮助。



在1.7.12.rc2版本中,git-p4脚本似乎存在问题。 - JavaArchitect
我使用发布版本进行了更强大的导入,我认为这可能是我的问题。正在验证... - JavaArchitect
我也遇到了同样的问题。请看我的答案,链接在这里:https://dev59.com/XWfWa4cB1Zd3GeqPfUfA#11978694 - cmcginty
1个回答

2
截至git 1.7.11版本,git-p4模块存在已确认的bug,当同时使用--use-client-spec和--detect-branches选项时,将perforce代码映射到git repo时会出错。以下是我向git开发团队报告该问题时收到的邮件回复摘录...
感谢您提供详细的报告。这是1.7.12-rc2版本中的一个错误。 该系列修复了它,在origin/master之上。
问题的关键在于,当同时启用--use-client-spec和--branch-detection选项时,文件被映射到错误的位置。
Pete Wyckoff(5): - git p4测试:将client_view()函数移动到库中 - git p4测试:添加损坏的--use-client-spec --detect-branches测试 - git p4:在初始化中设置self.branchPrefixes - git p4:在stripRepoPath中进行通配符解码 - git p4:使分支检测与--use-client-spec一起工作
 git-p4.py                     | 75 +++++++++++++++++++++++++++--------------

 t/lib-git-p4.sh               | 18 ++++++++++

 t/t9801-git-p4-branch.sh      | 77 +++++++++++++++++++++++++++++++++++++++++++

 t/t9809-git-p4-client-view.sh | 17 ----------

 4 files changed, 146 insertions(+), 41 deletions(-)

目前他们发布了1.7.12rc2版本。等待修复版本。


有没有办法手动同步那些文件夹到仓库并保留历史记录? - Dvid Silva

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接