{"thread":{"id":"41872","subject":"git alias quoting help","startedAt":"2016-03-30T04:13:30Z","lastAt":"2016-04-01T12:21:49Z","messageCount":6,"participants":["shawn wilson","Christian Couder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"282189","messageId":"CAH_OBievBBjzLwPZf3-qLn-SQyJG0UHhbdkvyZFfC8b-TsTUJQ@mail.gmail.com","threadId":"41872","inReplyTo":null,"subject":"git alias quoting help","fromName":"shawn wilson","fromEmail":"ag4ve.us@gmail.com","sentAt":"2016-03-30T04:13:30Z","receivedAt":"2016-03-30T04:13:30Z","isPatch":false,"sender":{"key":"ag4ve.us@gmail.com","avatar":null},"body":"I've also tried to make this a plain bash script (w/o the function or\nif statements and am failing at the same place). The issue seems to be\nwith the quoting in the filter-branch | ls-files bit. Also, the end\ngoal here is to be able to move a directory from one repo and keep the\nhistory. While this works if I do it at the command line, it's just\ntoo many steps (is tedious). Also, if there's a way to do the same\nthing with multiple directories in one shot, (or make this work with\nsomething like: cookbooks/{a,b,c} # as a parameter) that'd be perfect.\n\n  reapdir = \"!f() { \\\n    if [ -d \"$1\" ] ; then \\\n      git filter-branch --prune-empty --subdirectory-filter \"$1\" -- --all && \\\n      git gc --aggressive && \\\n      git prune && \\\n      git filter-branch -f --prune-empty --index-filter '\\\n        git ls-files -s \\\n          | sed \\\"s-\\\\t-&$1-\\\" \\\n          | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index\n--index-info && \\\n            mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE'; \\\n    else \\\n      echo \"No directory $1\"; \\\n    fi; }; \\\n  f\"\n"},{"id":"282312","messageId":"CAH_OBie1Bc==wPByestESHz-K8ezC7f5A1D=t1SsP9=Sd-y-eg@mail.gmail.com","threadId":"41872","inReplyTo":"CAH_OBievBBjzLwPZf3-qLn-SQyJG0UHhbdkvyZFfC8b-TsTUJQ@mail.gmail.com","subject":"Re: git alias quoting help","fromName":"shawn wilson","fromEmail":"ag4ve.us@gmail.com","sentAt":"2016-03-31T14:27:35Z","receivedAt":"2016-03-31T14:27:35Z","isPatch":false,"sender":{"key":"ag4ve.us@gmail.com","avatar":null},"body":"BTW, just trying to get filter-branch to interpret the bash script\nstring correctly now and it still isn't working:\n\ngit filter-branch -f --prune-empty --index-filter \"\\\n  git ls-files -s | \\\n  sed \\\"s-\\\\t\\\\\\\"*-&${1}-\\\" | \\\n  GIT_INDEX_FILE=\\$GIT_INDEX_FILE.new \\\n  git update-index --index-info && \\\n    mv \\$GIT_INDEX_FILE.new \\$GIT_INDEX_FILE \\\n\" HEAD\n\n I'm guessing bash is grabbing my actual bash shell is grabbing the\nGIT_INDEX_FILE declaration for itself. If this is the case, I'm not\nsure how to stop it - tried var\\=\\$var.new and that passes the '\\='\nwhich totally messes things up.\n\nRewrite ef54b77e59c7f4e18f00168ba88a8d2fee795802 (1/76)mv: cannot stat\n`/<repo path>/.git-rewrite/t/../index.new': No such file or directory\nindex filter failed:   git ls-files -s |   sed\n\"s-\\t\\\"*-&cookbooks/adjoin/-\" |   GIT_INDEX_FILE=$GIT_INDEX_FILE.new\ngit update-index --index-info &&     mv $GIT_INDEX_FILE.new\n$GIT_INDEX_FILE\n\nOn Wed, Mar 30, 2016 at 12:13 AM, shawn wilson <ag4ve.us@gmail.com> wrote:\n> I've also tried to make this a plain bash script (w/o the function or\n> if statements and am failing at the same place). The issue seems to be\n> with the quoting in the filter-branch | ls-files bit. Also, the end\n> goal here is to be able to move a directory from one repo and keep the\n> history. While this works if I do it at the command line, it's just\n> too many steps (is tedious). Also, if there's a way to do the same\n> thing with multiple directories in one shot, (or make this work with\n> something like: cookbooks/{a,b,c} # as a parameter) that'd be perfect.\n>\n>   reapdir = \"!f() { \\\n>     if [ -d \"$1\" ] ; then \\\n>       git filter-branch --prune-empty --subdirectory-filter \"$1\" -- --all && \\\n>       git gc --aggressive && \\\n>       git prune && \\\n>       git filter-branch -f --prune-empty --index-filter '\\\n>         git ls-files -s \\\n>           | sed \\\"s-\\\\t-&$1-\\\" \\\n>           | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index\n> --index-info && \\\n>             mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE'; \\\n>     else \\\n>       echo \"No directory $1\"; \\\n>     fi; }; \\\n>   f\"\n"},{"id":"282431","messageId":"CAH_OBifdLkszB7ZnKWBuZv8AFmKC9-RLZhxK_tmC9+bNJzXrXA@mail.gmail.com","threadId":"41872","inReplyTo":"CAH_OBie1Bc==wPByestESHz-K8ezC7f5A1D=t1SsP9=Sd-y-eg@mail.gmail.com","subject":"Re: git alias quoting help","fromName":"shawn wilson","fromEmail":"ag4ve.us@gmail.com","sentAt":"2016-04-01T06:10:41Z","receivedAt":"2016-04-01T06:10:41Z","isPatch":false,"sender":{"key":"ag4ve.us@gmail.com","avatar":null},"body":"FWIW, I (finally) found two projects that like they'll do what I want:\ngit-splits and git_filter\nThe later was lacking in documentation and after the build I couldn't\nfigure it out at a glance and I think git-splits will DWIW.\n\nOn Thu, Mar 31, 2016 at 10:27 AM, shawn wilson <ag4ve.us@gmail.com> wrote:\n> BTW, just trying to get filter-branch to interpret the bash script\n> string correctly now and it still isn't working:\n>\n> git filter-branch -f --prune-empty --index-filter \"\\\n>   git ls-files -s | \\\n>   sed \\\"s-\\\\t\\\\\\\"*-&${1}-\\\" | \\\n>   GIT_INDEX_FILE=\\$GIT_INDEX_FILE.new \\\n>   git update-index --index-info && \\\n>     mv \\$GIT_INDEX_FILE.new \\$GIT_INDEX_FILE \\\n> \" HEAD\n>\n>  I'm guessing bash is grabbing my actual bash shell is grabbing the\n> GIT_INDEX_FILE declaration for itself. If this is the case, I'm not\n> sure how to stop it - tried var\\=\\$var.new and that passes the '\\='\n> which totally messes things up.\n>\n> Rewrite ef54b77e59c7f4e18f00168ba88a8d2fee795802 (1/76)mv: cannot stat\n> `/<repo path>/.git-rewrite/t/../index.new': No such file or directory\n> index filter failed:   git ls-files -s |   sed\n> \"s-\\t\\\"*-&cookbooks/adjoin/-\" |   GIT_INDEX_FILE=$GIT_INDEX_FILE.new\n> git update-index --index-info &&     mv $GIT_INDEX_FILE.new\n> $GIT_INDEX_FILE\n>\n> On Wed, Mar 30, 2016 at 12:13 AM, shawn wilson <ag4ve.us@gmail.com> wrote:\n>> I've also tried to make this a plain bash script (w/o the function or\n>> if statements and am failing at the same place). The issue seems to be\n>> with the quoting in the filter-branch | ls-files bit. Also, the end\n>> goal here is to be able to move a directory from one repo and keep the\n>> history. While this works if I do it at the command line, it's just\n>> too many steps (is tedious). Also, if there's a way to do the same\n>> thing with multiple directories in one shot, (or make this work with\n>> something like: cookbooks/{a,b,c} # as a parameter) that'd be perfect.\n>>\n>>   reapdir = \"!f() { \\\n>>     if [ -d \"$1\" ] ; then \\\n>>       git filter-branch --prune-empty --subdirectory-filter \"$1\" -- --all && \\\n>>       git gc --aggressive && \\\n>>       git prune && \\\n>>       git filter-branch -f --prune-empty --index-filter '\\\n>>         git ls-files -s \\\n>>           | sed \\\"s-\\\\t-&$1-\\\" \\\n>>           | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index\n>> --index-info && \\\n>>             mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE'; \\\n>>     else \\\n>>       echo \"No directory $1\"; \\\n>>     fi; }; \\\n>>   f\"\n"},{"id":"282440","messageId":"CAH_OBie81uJASgVs7y=J1iAhpFPW6FFK1RgHp+AyohuPLye07Q@mail.gmail.com","threadId":"41872","inReplyTo":"CAH_OBifdLkszB7ZnKWBuZv8AFmKC9-RLZhxK_tmC9+bNJzXrXA@mail.gmail.com","subject":"Re: git alias quoting help","fromName":"shawn wilson","fromEmail":"ag4ve.us@gmail.com","sentAt":"2016-04-01T10:30:44Z","receivedAt":"2016-04-01T10:30:44Z","isPatch":false,"sender":{"key":"ag4ve.us@gmail.com","avatar":null},"body":"I think I finally figured out how I want to do this:\n\ngit remote add temp ../<temp repo>/\ngit fetch temp\ngit merge -s ours --no-commit temp/master\ngit read-tree --prefix=<wanted directory> -u temp/master:<wanted directory>\ngit commit -m \"foo\"\n\nHowever, when I do this, I've got all of the commits from the original\n(temp) repo. How do I prune these out? None of the files show up, but\nI do see reference to them in: git log --stat. And nothing I do with\ngc or prune seem to have any affect.\n\nOn Fri, Apr 1, 2016 at 2:10 AM, shawn wilson <ag4ve.us@gmail.com> wrote:\n> FWIW, I (finally) found two projects that like they'll do what I want:\n> git-splits and git_filter\n> The later was lacking in documentation and after the build I couldn't\n> figure it out at a glance and I think git-splits will DWIW.\n>\n> On Thu, Mar 31, 2016 at 10:27 AM, shawn wilson <ag4ve.us@gmail.com> wrote:\n>> BTW, just trying to get filter-branch to interpret the bash script\n>> string correctly now and it still isn't working:\n>>\n>> git filter-branch -f --prune-empty --index-filter \"\\\n>>   git ls-files -s | \\\n>>   sed \\\"s-\\\\t\\\\\\\"*-&${1}-\\\" | \\\n>>   GIT_INDEX_FILE=\\$GIT_INDEX_FILE.new \\\n>>   git update-index --index-info && \\\n>>     mv \\$GIT_INDEX_FILE.new \\$GIT_INDEX_FILE \\\n>> \" HEAD\n>>\n>>  I'm guessing bash is grabbing my actual bash shell is grabbing the\n>> GIT_INDEX_FILE declaration for itself. If this is the case, I'm not\n>> sure how to stop it - tried var\\=\\$var.new and that passes the '\\='\n>> which totally messes things up.\n>>\n>> Rewrite ef54b77e59c7f4e18f00168ba88a8d2fee795802 (1/76)mv: cannot stat\n>> `/<repo path>/.git-rewrite/t/../index.new': No such file or directory\n>> index filter failed:   git ls-files -s |   sed\n>> \"s-\\t\\\"*-&cookbooks/adjoin/-\" |   GIT_INDEX_FILE=$GIT_INDEX_FILE.new\n>> git update-index --index-info &&     mv $GIT_INDEX_FILE.new\n>> $GIT_INDEX_FILE\n>>\n>> On Wed, Mar 30, 2016 at 12:13 AM, shawn wilson <ag4ve.us@gmail.com> wrote:\n>>> I've also tried to make this a plain bash script (w/o the function or\n>>> if statements and am failing at the same place). The issue seems to be\n>>> with the quoting in the filter-branch | ls-files bit. Also, the end\n>>> goal here is to be able to move a directory from one repo and keep the\n>>> history. While this works if I do it at the command line, it's just\n>>> too many steps (is tedious). Also, if there's a way to do the same\n>>> thing with multiple directories in one shot, (or make this work with\n>>> something like: cookbooks/{a,b,c} # as a parameter) that'd be perfect.\n>>>\n>>>   reapdir = \"!f() { \\\n>>>     if [ -d \"$1\" ] ; then \\\n>>>       git filter-branch --prune-empty --subdirectory-filter \"$1\" -- --all && \\\n>>>       git gc --aggressive && \\\n>>>       git prune && \\\n>>>       git filter-branch -f --prune-empty --index-filter '\\\n>>>         git ls-files -s \\\n>>>           | sed \\\"s-\\\\t-&$1-\\\" \\\n>>>           | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index\n>>> --index-info && \\\n>>>             mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE'; \\\n>>>     else \\\n>>>       echo \"No directory $1\"; \\\n>>>     fi; }; \\\n>>>   f\"\n"},{"id":"282446","messageId":"CAP8UFD3y_hFVT_PjAQFJ_091M83nmGGFsPGii0YFKOORbHqkKg@mail.gmail.com","threadId":"41872","inReplyTo":"CAH_OBievBBjzLwPZf3-qLn-SQyJG0UHhbdkvyZFfC8b-TsTUJQ@mail.gmail.com","subject":"Re: git alias quoting help","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-04-01T11:05:40Z","receivedAt":"2016-04-01T11:05:40Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Wed, Mar 30, 2016 at 6:13 AM, shawn wilson <ag4ve.us@gmail.com> wrote:\n> I've also tried to make this a plain bash script (w/o the function or\n> if statements and am failing at the same place). The issue seems to be\n> with the quoting in the filter-branch | ls-files bit. Also, the end\n> goal here is to be able to move a directory from one repo and keep the\n> history.\n\nDid you try git subtree\n(https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt)?\n"},{"id":"282452","messageId":"CAH_OBif6v3WiQ0+bz0hNGvAzqXdXjy+NJNYB65QxMexDy5s=og@mail.gmail.com","threadId":"41872","inReplyTo":"CAP8UFD3y_hFVT_PjAQFJ_091M83nmGGFsPGii0YFKOORbHqkKg@mail.gmail.com","subject":"Re: git alias quoting help","fromName":"shawn wilson","fromEmail":"ag4ve.us@gmail.com","sentAt":"2016-04-01T12:21:49Z","receivedAt":"2016-04-01T12:21:49Z","isPatch":false,"sender":{"key":"ag4ve.us@gmail.com","avatar":null},"body":"On Fri, Apr 1, 2016 at 7:05 AM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> On Wed, Mar 30, 2016 at 6:13 AM, shawn wilson <ag4ve.us@gmail.com> wrote:\n>> I've also tried to make this a plain bash script (w/o the function or\n>> if statements and am failing at the same place). The issue seems to be\n>> with the quoting in the filter-branch | ls-files bit. Also, the end\n>> goal here is to be able to move a directory from one repo and keep the\n>> history.\n>\n> Did you try git subtree\n> (https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt)?\n\nYeah, it looked like it left the repo in the same state as\nsubdirectory-filter and the merge failed. But I'll try it again when I\nget to work.\n"}]}