git-p4 import trees contain subdirectory .git

467 views Asked by At

Our company uses Perfoce to manage projects, and I am using git-p4 to sync Perforce repository on my local side. But on P4 repository, it is combined with many module and may contain .git folder for some module. Someone uses git on local and put the .git/ to Perforce :(

When I clone the P4 by git-p4 clone, then it always say some files were removed.

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    module-by-git/.git/FETCH_HEAD
#       deleted:    module-by-git/.git/HEAD
#       deleted:    module-by-git/.git/ORIG_HEAD
#       deleted:    module-by-git/.git/config
#       deleted:    module-by-git/.git/description
#       deleted:    module-by-git/.git/hooks/commit-msg
#       deleted:    module-by-git/.git/hooks/pre-auto-gc
#       deleted:    module-by-git/.git/index
#       deleted:    module-by-git/.git/info/exclude
#       deleted:    module-by-git/.git/logs/HEAD
#       deleted:    module-by-git/.git/logs/refs/remotes/m/master

I try to use "git filter-branch" to remove these files, but it forbid to use on a dirty working directory.

How can I do to fix this problem? In my previous workaround, I just remove these .git folders by Perforce tool, and then clone the entire project again.

2

There are 2 answers

0
Norbert On

Try to exclude the .git repos when cloning, i.e.

git p4 clone ... -//module-by-git/.git
0
Swordow On

You can modify the git-p4 code and convert the path that contains .git dir to a fake path replaced .git with some_fake_git dir while writing the git stream, for example:

  def writeToGitStream(self, gitMode, relPath, contents):
    fakePath = self.convertToSubGitFakePath(relPath)
    self.gitStream.write(encode_text_stream(u'M {} inline {}\n'.format(gitMode, fakePath)))

The above method is not perfect but could keep the git records in sub directories.