{"thread":{"id":"45674","subject":"git subtree bug","startedAt":"2017-04-12T18:37:55Z","lastAt":"2017-04-12T18:37:55Z","messageCount":1,"participants":["Andrew Hoyt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"316697","messageId":"CAOiUhTHqbjN=S5eFWVs1x2dvCeyai_ys6EhWvKPjj21QozEtOg@mail.gmail.com","threadId":"45674","inReplyTo":null,"subject":"git subtree bug","fromName":"Andrew Hoyt","fromEmail":"andrewhoyt@gmail.com","sentAt":"2017-04-12T18:37:46Z","receivedAt":"2017-04-12T18:37:55Z","isPatch":false,"sender":{"key":"andrewhoyt@gmail.com","avatar":null},"body":"Hi guys,\n\nI've been using git subtrees extensively to include third party tools\nin my projects. Today I stumbled across a bug with git-subtree when I\nwas trying to update the jacoco (https://github.com/jacoco/jacoco.git)\nsubtree in one of my projects.\n\nThe problem stems from adding a project as a subtree with a prefix\nthat has the same name as a top-level subdirectory in that project.\nFrom then on, any changes made to the top-level directory of that\nsub-project will cause issues when you attempt a git subtree pull\n(e.g. the entire subtree AND the parent project will be deleted in\nyour working directory).\n\nSteps to reproduce:\n====================================================================\nmkdir --parents /tmp/project/prj\ncd /tmp/project\necho \"file in subdirectory\" > prj/file_in_subdirectory\necho \"file in root\" > file_in_root\ngit init\ngit add .\ngit commit -m \"Init subproject repository\"\n\nmkdir /tmp/test\ncd /tmp/test\ngit init\ngit commit --allow-empty -m \"Init test repository\"\ngit subtree add --prefix prj /tmp/project master\n\ncd /tmp/project\necho \"temp file\" > temp\ngit add temp\ngit commit -m \"add temp file\"\n\ncd /tmp/test\ngit subtree pull --prefix=prj /tmp/project master\n====================================================================\n\nIn the above example, the problem occurs because we've added the\nsubtree with the prefix \"prj\" when it happens to contain a top-level\ndirectory also called \"prj\". A change is then made to \"project\"s\ntop-level directory (the file \"temp\" is created) and thus the \"git\nsubtree pull\" command puts \"test\" into a broken state. If we had added\nthe subtree with any other prefix, the problem would not have\noccurred. Likewise, if we had added \"temp\" anywhere other than the top\nlevel of \"project\" the subtree pull would not have caused problems.\n\nAnyhow, I'm not sure if you guys are aware of the problem or not, but\nI figured I'd bring it to your attention just in case.\n\nThanks so much,\n- Andrew\n"}]}