git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git subtree bug

From
AHAndrew Hoyt <andrewhoyt@gmail.com>
Date
Apr 12, 2017, 18:37 UTC
Message-ID
<CAOiUhTHqbjN=S5eFWVs1x2dvCeyai_ys6EhWvKPjj21QozEtOg@mail.gmail.com>
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
Message 1 of 1 in “git subtree bug”
  1. Andrew HoytApr 12, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.