git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git subtree bug
@ 2017-04-12 18:37 Andrew Hoyt
  0 siblings, 0 replies; only message in thread
From: Andrew Hoyt @ 2017-04-12 18:37 UTC (permalink / raw)
  To: git

Hi guys,

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
cd /tmp/project
echo "file in subdirectory" > prj/file_in_subdirectory
echo "file in root" > file_in_root
git init
git add .
git commit -m "Init subproject repository"

mkdir /tmp/test
cd /tmp/test
git init
git commit --allow-empty -m "Init test repository"
git subtree add --prefix prj /tmp/project master

cd /tmp/project
echo "temp file" > temp
git add temp
git commit -m "add temp file"

cd /tmp/test
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,
- Andrew

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-04-12 18:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-12 18:37 git subtree bug Andrew Hoyt

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).