{"thread":{"id":"46979","subject":"Adding a target prefix to git filter-branch --subdirectory-filter","startedAt":"2017-10-16T23:39:46Z","lastAt":"2017-10-16T23:39:46Z","messageCount":1,"participants":["David Glasser"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"330493","messageId":"CAOz3OdswGKiWesrjp2P0oaVkTjGONsY3CoYq1B5Jh7Qq8tTPZg@mail.gmail.com","threadId":"46979","inReplyTo":null,"subject":"Adding a target prefix to git filter-branch --subdirectory-filter","fromName":"David Glasser","fromEmail":"glasser@meteor.com","sentAt":"2017-10-16T23:39:16Z","receivedAt":"2017-10-16T23:39:46Z","isPatch":false,"sender":{"key":"glasser@meteor.com","avatar":null},"body":"git filter-branch --subdirectory-filter is really useful and easy to\nuse.  It's a commonly used step as part of moving a directory from one\nrepo to another.  It lets you move a subdirectory to the root of the\nrepo.\n\nI've found that, when moving directories between repos, I often want\nto do a task that is very similar to --subdirectory-filter but not\nquite the same — I want to put the subdirectory under a prefix (and\nmaybe in this case the \"subdirectory\" should just be the entire repo).\n\nSearching the web for <git move directory to new repository> shows\nthat wanting to do something like this is pretty common.\n\nIt's certainly possible to do this with --index-filter or\n--tree-filter, and the man page even has an example:\n\n           git filter-branch --index-filter \\\n                   'git ls-files -s | sed \"s-\\t\\\"*-&newsubdir/-\" |\n                           GIT_INDEX_FILE=$GIT_INDEX_FILE.new \\\n                                   git update-index --index-info &&\n                    mv \"$GIT_INDEX_FILE.new\" \"$GIT_INDEX_FILE\"' HEAD\n\nBut gosh, this is just a pain to write.\n\nI'd like to add direct support to git filter-branch for having a\nnon-root target for subdirectory-filter.\n\nI have a couple questions:\n\n(1) What interface should this have? I'd lean towards having this just\nbe part of --subdirectory-filter as a separate option\n--subdirectory-target-prefix.  For the \"move root to subdir\" you maybe\nwould have to type --subdirectory-filter=/, or maybe empty\n--subdirectory-filter combined with --subdirectory-target-prefix does\nthe trick.\n\nAlternatively, it could be a new filter type specific to moving\nsubdirectories around, but I don't know that that makes sense.\n\n(2) The way I'd imagine I would implement this would be to replace the\ncurrent `git read-tree -i -m $commit:\"$filter_subdir\"` with `git\nread-tree --empty && git read-tree --prefix=PREFIX/\n$commit:\"$filter_subdir\"`.  --prefix is incompatible with -m, and I\ndon't really understand the importance of the stat reuse that is done\nby `-i -m` single-tree merge. Is it OK to just drop the -i -m?\n\n--dave\n"}]}