git subtree bug
- Date: Wed, 12 Apr 2017 14:37:46 -0400
- From: Andrew Hoyt <andrewhoyt@xxxxxxxxx>
- Subject: git subtree bug
I've been using git subtrees extensively to include third party tools
in my projects. Today I stumbled across a bug with git-subtree when I
was trying to update the jacoco (https://github.com/jacoco/jacoco.git)
subtree in one of my projects.
The problem stems from adding a project as a subtree with a prefix
that has the same name as a top-level subdirectory in that project.
>From then on, any changes made to the top-level directory of that
sub-project will cause issues when you attempt a git subtree pull
(e.g. the entire subtree AND the parent project will be deleted in
your working directory).
Steps to reproduce:
mkdir --parents /tmp/project/prj
echo "file in subdirectory" > prj/file_in_subdirectory
echo "file in root" > file_in_root
git add .
git commit -m "Init subproject repository"
git commit --allow-empty -m "Init test repository"
git subtree add --prefix prj /tmp/project master
echo "temp file" > temp
git add temp
git commit -m "add temp file"
git subtree pull --prefix=prj /tmp/project master
In the above example, the problem occurs because we've added the
subtree with the prefix "prj" when it happens to contain a top-level
directory also called "prj". A change is then made to "project"s
top-level directory (the file "temp" is created) and thus the "git
subtree pull" command puts "test" into a broken state. If we had added
the subtree with any other prefix, the problem would not have
occurred. Likewise, if we had added "temp" anywhere other than the top
level of "project" the subtree pull would not have caused problems.
Anyhow, I'm not sure if you guys are aware of the problem or not, but
I figured I'd bring it to your attention just in case.
Thanks so much,