git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Andrew Hoyt <andrewhoyt@gmail.com>
To: git@vger.kernel.org
Subject: git subtree bug
Date: Wed, 12 Apr 2017 14:37:46 -0400	[thread overview]
Message-ID: <CAOiUhTHqbjN=S5eFWVs1x2dvCeyai_ys6EhWvKPjj21QozEtOg@mail.gmail.com> (raw)

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

                 reply	other threads:[~2017-04-12 18:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOiUhTHqbjN=S5eFWVs1x2dvCeyai_ys6EhWvKPjj21QozEtOg@mail.gmail.com' \
    --to=andrewhoyt@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).