{"thread":{"id":"48525","subject":"git rebase -i --exec and changing directory","startedAt":"2018-05-19T16:39:12Z","lastAt":"2018-05-28T02:48:33Z","messageCount":8,"participants":["Ondrej Mosnáček","Philip Oakley","Phillip Wood","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"348079","messageId":"CAAUqJDu_3DTyd1cFKaNRKOzo3AHosfxP1jjWpa=HGtyAyitTeA@mail.gmail.com","threadId":"48525","inReplyTo":null,"subject":"git rebase -i --exec and changing directory","fromName":"Ondrej Mosnáček","fromEmail":"omosnacek@gmail.com","sentAt":"2018-05-19T16:38:46Z","receivedAt":"2018-05-19T16:39:12Z","isPatch":false,"sender":{"key":"omosnacek@gmail.com","avatar":null},"body":"Hello,\n\nI am trying to run a script to edit multiple commits using 'git rebase\n-i --exec ...' and I ran into a strange behavior when I run 'cd'\ninside the --exec command and subsequently run a git command. For\nexample, if the command is 'cd src && git status', then git status\nreports as if all files in the repository are deleted.\n\nExample command sequence to reproduce the problem:\n\n    # Setup:\n    touch a\n    mkdir dir\n    touch dir/x\n\n    git init .\n    git add --all\n    git commit -m commit1\n    git tag base\n    touch b\n    git add --all\n    git commit -m commit2\n\n    # Here we go:\n    git rebase -i --exec 'cd dir && git status' base\n\n    # Spawning a sub-shell doesn't help:\n    git rebase -i --exec '(cd dir && git status)' base\n\nIs this expected behavior or did I found a bug? Is there any\nworkaround, other than cd'ing to the toplevel directory every time I\nwant to run a git command when I am inside a subdirectory?\n\n$ git --version\ngit version 2.17.0\n\nThanks,\n\nOndrej Mosnacek\n"},{"id":"348627","messageId":"CAAUqJDvsRBJWZh5_A2e2x-CqgXi5gLSjo6-P2sYxsKz3qfidSw@mail.gmail.com","threadId":"48525","inReplyTo":"CAAUqJDu_3DTyd1cFKaNRKOzo3AHosfxP1jjWpa=HGtyAyitTeA@mail.gmail.com","subject":"Re: git rebase -i --exec and changing directory","fromName":"Ondrej Mosnáček","fromEmail":"omosnacek@gmail.com","sentAt":"2018-05-27T10:59:42Z","receivedAt":"2018-05-27T11:00:08Z","isPatch":false,"sender":{"key":"omosnacek@gmail.com","avatar":null},"body":"Bump? Has anyone had time to look at this?\n\nThanks,\n\nOndrej Mosnacek\n\n2018-05-19 18:38 GMT+02:00 Ondrej Mosnáček <omosnacek@gmail.com>:\n> Hello,\n>\n> I am trying to run a script to edit multiple commits using 'git rebase\n> -i --exec ...' and I ran into a strange behavior when I run 'cd'\n> inside the --exec command and subsequently run a git command. For\n> example, if the command is 'cd src && git status', then git status\n> reports as if all files in the repository are deleted.\n>\n> Example command sequence to reproduce the problem:\n>\n>     # Setup:\n>     touch a\n>     mkdir dir\n>     touch dir/x\n>\n>     git init .\n>     git add --all\n>     git commit -m commit1\n>     git tag base\n>     touch b\n>     git add --all\n>     git commit -m commit2\n>\n>     # Here we go:\n>     git rebase -i --exec 'cd dir && git status' base\n>\n>     # Spawning a sub-shell doesn't help:\n>     git rebase -i --exec '(cd dir && git status)' base\n>\n> Is this expected behavior or did I found a bug? Is there any\n> workaround, other than cd'ing to the toplevel directory every time I\n> want to run a git command when I am inside a subdirectory?\n>\n> $ git --version\n> git version 2.17.0\n>\n> Thanks,\n>\n> Ondrej Mosnacek\n"},{"id":"348629","messageId":"1EAAF778D73B4AA689ADB5AE2EE9D1DD@PhilipOakley","threadId":"48525","inReplyTo":"CAAUqJDvsRBJWZh5_A2e2x-CqgXi5gLSjo6-P2sYxsKz3qfidSw@mail.gmail.com","subject":"Re: git rebase -i --exec and changing directory","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":"2018-05-27T12:28:50Z","receivedAt":"2018-05-27T12:28:55Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"You may need to give a bit more background of things that seem obvious to \nyou.\nSo where is the src directory you are cd'ing to relative to the \ndirectory/repository you are creating?\nWhat is [the name of] the directory you are currently in, etc. ?\n\nPhilip\n--\n\nFrom: \"Ondrej Mosnáček\" <omosnacek@gmail.com>\nBump? Has anyone had time to look at this?\n\n2018-05-19 18:38 GMT+02:00 Ondrej Mosnáček <omosnacek@gmail.com>:\n> Hello,\n>\n> I am trying to run a script to edit multiple commits using 'git rebase\n> -i --exec ...' and I ran into a strange behavior when I run 'cd'\n> inside the --exec command and subsequently run a git command. For\n> example, if the command is 'cd src && git status', then git status\n> reports as if all files in the repository are deleted.\n>\n> Example command sequence to reproduce the problem:\n>\n>     # Setup:\n>     touch a\n>     mkdir dir\n>     touch dir/x\n>\n>     git init .\n>     git add --all\n>     git commit -m commit1\n>     git tag base\n>     touch b\n>     git add --all\n>     git commit -m commit2\n>\n>     # Here we go:\n>     git rebase -i --exec 'cd dir && git status' base\n>\n>     # Spawning a sub-shell doesn't help:\n>     git rebase -i --exec '(cd dir && git status)' base\n>\n> Is this expected behavior or did I found a bug? Is there any\n> workaround, other than cd'ing to the toplevel directory every time I\n> want to run a git command when I am inside a subdirectory?\n>\n> $ git --version\n> git version 2.17.0\n>\n> Thanks,\n>\n> Ondrej Mosnacek\n\n"},{"id":"348630","messageId":"CAAUqJDvCgXPubhtSKzMLqTU5au320U15UQ8Lst7+JeZYBp8wTA@mail.gmail.com","threadId":"48525","inReplyTo":"1EAAF778D73B4AA689ADB5AE2EE9D1DD@PhilipOakley","subject":"Re: git rebase -i --exec and changing directory","fromName":"Ondrej Mosnáček","fromEmail":"omosnacek@gmail.com","sentAt":"2018-05-27T12:53:25Z","receivedAt":"2018-05-27T12:53:50Z","isPatch":false,"sender":{"key":"omosnacek@gmail.com","avatar":null},"body":"Hi Philip,\n\n2018-05-27 14:28 GMT+02:00 Philip Oakley <philipoakley@iee.org>:\n> You may need to give a bit more background of things that seem obvious to\n> you.\n> So where is the src directory you are cd'ing to relative to the\n> directory/repository you are creating?\n\nIt is located in the top-level directory of the working tree (in the\nsame directory that .git is in).\n\nFrom git-rebase(1):\n\n    The \"exec\" command launches the command in a shell (the one\n    specified in $SHELL, or the default shell if $SHELL is not set), so\n    you can use shell features (like \"cd\", \">\", \";\" ...). The command is\n    run from the root of the working tree.\n\nSo I need to run 'cd src' if I want to run a command in there\n(regardless of the working directory of the git rebase command\nitself).\n\n> What is [the name of] the directory you are currently in, etc. ?\n\nI don't think that is relevant here. FWIW, when verifying the problem\nI ran the reproducer from my original message in a directory whose\npath did not contain any spaces or special characters.\n\nDid you try to run the reproducing commands I posted? Did you get a\ndifferent result? You should see the following in the output of 'cd\ndir && git status':\n\n[...]\nChanges not staged for commit:\n (use \"git add/rm <file>...\" to update what will be committed)\n (use \"git checkout -- <file>...\" to discard changes in working directory)\n\n       deleted:    a\n       deleted:    b\n       deleted:    dir/x\n       deleted:    reproduce.sh\n\nUntracked files:\n (use \"git add <file>...\" to include in what will be committed)\n\n       x\n[...]\n\nWhen I drop the 'cd dir && ' from before 'git status', the output is\nas expected:\n\nYou are currently editing a commit while rebasing branch 'master' on '19765db'.\n (use \"git commit --amend\" to amend the current commit)\n (use \"git rebase --continue\" once you are satisfied with your changes)\n\nnothing to commit, working tree clean\n\n>\n> Philip\n> --\n>\n> From: \"Ondrej Mosnáček\" <omosnacek@gmail.com>\n> Bump? Has anyone had time to look at this?\n>\n> 2018-05-19 18:38 GMT+02:00 Ondrej Mosnáček <omosnacek@gmail.com>:\n>>\n>> Hello,\n>>\n>> I am trying to run a script to edit multiple commits using 'git rebase\n>> -i --exec ...' and I ran into a strange behavior when I run 'cd'\n>> inside the --exec command and subsequently run a git command. For\n>> example, if the command is 'cd src && git status', then git status\n>> reports as if all files in the repository are deleted.\n>>\n>> Example command sequence to reproduce the problem:\n>>\n>>     # Setup:\n>>     touch a\n>>     mkdir dir\n>>     touch dir/x\n>>\n>>     git init .\n>>     git add --all\n>>     git commit -m commit1\n>>     git tag base\n>>     touch b\n>>     git add --all\n>>     git commit -m commit2\n>>\n>>     # Here we go:\n>>     git rebase -i --exec 'cd dir && git status' base\n>>\n>>     # Spawning a sub-shell doesn't help:\n>>     git rebase -i --exec '(cd dir && git status)' base\n>>\n>> Is this expected behavior or did I found a bug? Is there any\n>> workaround, other than cd'ing to the toplevel directory every time I\n>> want to run a git command when I am inside a subdirectory?\n>>\n>> $ git --version\n>> git version 2.17.0\n>>\n>> Thanks,\n>>\n>> Ondrej Mosnacek\n>\n>\n"},{"id":"348633","messageId":"3465c994-3917-cd45-bb8e-d1121f60bfb4@talktalk.net","threadId":"48525","inReplyTo":"CAAUqJDvCgXPubhtSKzMLqTU5au320U15UQ8Lst7+JeZYBp8wTA@mail.gmail.com","subject":"Re: git rebase -i --exec and changing directory","fromName":"Phillip Wood","fromEmail":"phillip.wood@talktalk.net","sentAt":"2018-05-27T16:07:58Z","receivedAt":"2018-05-27T16:08:10Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Ondrej\n\nOn 27/05/18 13:53, Ondrej Mosnáček wrote:\n> \n> Hi Philip,\n> \n> 2018-05-27 14:28 GMT+02:00 Philip Oakley <philipoakley@iee.org>:\n>> You may need to give a bit more background of things that seem obvious to\n>> you.\n>> So where is the src directory you are cd'ing to relative to the\n>> directory/repository you are creating?\n> \n> It is located in the top-level directory of the working tree (in the\n> same directory that .git is in).\n> \n>  From git-rebase(1):\n> \n>      The \"exec\" command launches the command in a shell (the one\n>      specified in $SHELL, or the default shell if $SHELL is not set), so\n>      you can use shell features (like \"cd\", \">\", \";\" ...). The command is\n>      run from the root of the working tree.\n> \n> So I need to run 'cd src' if I want to run a command in there\n> (regardless of the working directory of the git rebase command\n> itself).\n> \n>> What is [the name of] the directory you are currently in, etc. ?\n> \n> I don't think that is relevant here. FWIW, when verifying the problem\n> I ran the reproducer from my original message in a directory whose\n> path did not contain any spaces or special characters.\n> \n> Did you try to run the reproducing commands I posted? Did you get a\n> different result? You should see the following in the output of 'cd\n> dir && git status':\n\nI tried your recipe and got the same result as you. However I think it \ncould be a problem with 'git status' rather than 'git rebase --exec'. If \nI run your recipe in /tmp/a and do\n\ncd dir\nGIT_DIR=/tmp/a/.git git status\n\nI get the same result as when running 'git status' from 'git rebase \n--exec' So I think the problem might have something to do with GIT_DIR \nbeing set in the environment when 'git status' is run\n\nBest Wishes\n\nPhillip\n\n> \n> [...]\n> Changes not staged for commit:\n>   (use \"git add/rm <file>...\" to update what will be committed)\n>   (use \"git checkout -- <file>...\" to discard changes in working directory)\n> \n>         deleted:    a\n>         deleted:    b\n>         deleted:    dir/x\n>         deleted:    reproduce.sh\n> \n> Untracked files:\n>   (use \"git add <file>...\" to include in what will be committed)\n> \n>         x\n> [...]\n> \n> When I drop the 'cd dir && ' from before 'git status', the output is\n> as expected:\n> \n> You are currently editing a commit while rebasing branch 'master' on '19765db'.\n>   (use \"git commit --amend\" to amend the current commit)\n>   (use \"git rebase --continue\" once you are satisfied with your changes)\n> \n> nothing to commit, working tree clean\n> \n>>\n>> Philip\n>> --\n>>\n>> From: \"Ondrej Mosnáček\" <omosnacek@gmail.com>\n>> Bump? Has anyone had time to look at this?\n>>\n>> 2018-05-19 18:38 GMT+02:00 Ondrej Mosnáček <omosnacek@gmail.com>:\n>>>\n>>> Hello,\n>>>\n>>> I am trying to run a script to edit multiple commits using 'git rebase\n>>> -i --exec ...' and I ran into a strange behavior when I run 'cd'\n>>> inside the --exec command and subsequently run a git command. For\n>>> example, if the command is 'cd src && git status', then git status\n>>> reports as if all files in the repository are deleted.\n>>>\n>>> Example command sequence to reproduce the problem:\n>>>\n>>>      # Setup:\n>>>      touch a\n>>>      mkdir dir\n>>>      touch dir/x\n>>>\n>>>      git init .\n>>>      git add --all\n>>>      git commit -m commit1\n>>>      git tag base\n>>>      touch b\n>>>      git add --all\n>>>      git commit -m commit2\n>>>\n>>>      # Here we go:\n>>>      git rebase -i --exec 'cd dir && git status' base\n>>>\n>>>      # Spawning a sub-shell doesn't help:\n>>>      git rebase -i --exec '(cd dir && git status)' base\n>>>\n>>> Is this expected behavior or did I found a bug? Is there any\n>>> workaround, other than cd'ing to the toplevel directory every time I\n>>> want to run a git command when I am inside a subdirectory?\n>>>\n>>> $ git --version\n>>> git version 2.17.0\n>>>\n>>> Thanks,\n>>>\n>>> Ondrej Mosnacek\n>>\n>>\n\n"},{"id":"348634","messageId":"C6439659F55F4F3ABB149E7128BE00F4@PhilipOakley","threadId":"48525","inReplyTo":"3465c994-3917-cd45-bb8e-d1121f60bfb4@talktalk.net","subject":"Re: git rebase -i --exec and changing directory","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":"2018-05-27T17:25:03Z","receivedAt":"2018-05-27T17:25:08Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Hi Ondrej, Phillip,\n\nFrom: \"Phillip Wood\" <phillip.wood@talktalk.net>\n> Hi Ondrej\n>\n> On 27/05/18 13:53, Ondrej Mosnáček wrote:\n>>\n>> Hi Philip,\n>>\n>> 2018-05-27 14:28 GMT+02:00 Philip Oakley <philipoakley@iee.org>:\n>>> You may need to give a bit more background of things that seem obvious \n>>> to\n>>> you.\n>>> So where is the src directory you are cd'ing to relative to the\n>>> directory/repository you are creating?\n>>\n>> It is located in the top-level directory of the working tree (in the\n>> same directory that .git is in).\n>>\n>>  From git-rebase(1):\n>>\n>>      The \"exec\" command launches the command in a shell (the one\n>>      specified in $SHELL, or the default shell if $SHELL is not set), so\n>>      you can use shell features (like \"cd\", \">\", \";\" ...). The command is\n>>      run from the root of the working tree.\n>>\n>> So I need to run 'cd src' if I want to run a command in there\n>> (regardless of the working directory of the git rebase command\n>> itself).\n>>\n>>> What is [the name of] the directory you are currently in, etc. ?\n>>\n>> I don't think that is relevant here. FWIW, when verifying the problem\n>> I ran the reproducer from my original message in a directory whose\n>> path did not contain any spaces or special characters.\n>>\n>> Did you try to run the reproducing commands I posted? Did you get a\n>> different result? You should see the following in the output of 'cd\n>> dir && git status':\n\nAt the time, I hadn't run the command. I was more interested in \nunderstanding the problem setup, as understanding often brings \nenlightenment.\n\nI was jsut starting to do my own setup and swaw Phillip had responsed which \nprompted me to think it could be that there was no tty attached to the exec, \nso output wasn't being seen (or something like that).\n\n>\n> I tried your recipe and got the same result as you. However I think it \n> could be a problem with 'git status' rather than 'git rebase --exec'. If I \n> run your recipe in /tmp/a and do\n>\n> cd dir\n> GIT_DIR=/tmp/a/.git git status\n>\n> I get the same result as when running 'git status' from 'git \n> rebase --exec' So I think the problem might have something to do with \n> GIT_DIR being set in the environment when 'git status' is run\n>\n\nI too got the same same results.\nI also tried duplicating the exec line and placing it before the pick line, \njust to check it wasn't an issue about termination. Same result.\n\n> Best Wishes\n>\n> Phillip\n>\n>>\n>> [...]\n>> Changes not staged for commit:\n>>   (use \"git add/rm <file>...\" to update what will be committed)\n>>   (use \"git checkout -- <file>...\" to discard changes in working \n>> directory)\n>>\n>>         deleted:    a\n>>         deleted:    b\n>>         deleted:    dir/x\n>>         deleted:    reproduce.sh\n>>\n>> Untracked files:\n>>   (use \"git add <file>...\" to include in what will be committed)\n>>\n>>         x\n>> [...]\n>>\n>> When I drop the 'cd dir && ' from before 'git status', the output is\n>> as expected:\n>>\n>> You are currently editing a commit while rebasing branch 'master' on \n>> '19765db'.\n>>   (use \"git commit --amend\" to amend the current commit)\n>>   (use \"git rebase --continue\" once you are satisfied with your changes)\n>>\n>> nothing to commit, working tree clean\n\nSo I extended the command to be exec'd to `cd dir && ls && git status`, \nagain with duplication of the exec, which then gives a bit more..\n\nfinally I extended the status to pipe it's output to a file, again \nduplicated.\n--\nPhilip@PhilipOakley MINGW32 /usr/src/mosnacek (master)\n\n$ git rebase -i --exec 'cd dir && ls && git status >stat.txt' base\n\nExecuting: cd dir && ls && git status >stat0.txt\n\nx\n\nExecuting: cd dir && ls && git status >stat.txt\n\nstat0.txt x\n\nSuccessfully rebased and updated refs/heads/master.\n\n--\nthe stat0, stat files can then be investigated.\n\nSummary: status is, I think, being clever and dropping the verbiage when not \ndirectly attached to the terminal. (or it is being intelligent and adding a \nlot more status details just because it _is_ within the rebase..)\n\n>>\n>>>\n>>> Philip\n>>> --\n>>>\n>>> From: \"Ondrej Mosnáček\" <omosnacek@gmail.com>\n>>> Bump? Has anyone had time to look at this?\n>>>\n>>> 2018-05-19 18:38 GMT+02:00 Ondrej Mosnáček <omosnacek@gmail.com>:\n>>>>\n>>>> Hello,\n>>>>\n>>>> I am trying to run a script to edit multiple commits using 'git rebase\n>>>> -i --exec ...' and I ran into a strange behavior when I run 'cd'\n>>>> inside the --exec command and subsequently run a git command. For\n>>>> example, if the command is 'cd src && git status', then git status\n>>>> reports as if all files in the repository are deleted.\n\nWhat does that particular report look like? I see no special report of \ndeletions, or additions.\n\n\n>>>>\n>>>> Example command sequence to reproduce the problem:\n>>>>\n>>>>      # Setup:\n>>>>      touch a\n>>>>      mkdir dir\n>>>>      touch dir/x\n>>>>\n>>>>      git init .\n>>>>      git add --all\n>>>>      git commit -m commit1\n>>>>      git tag base\n>>>>      touch b\n>>>>      git add --all\n>>>>      git commit -m commit2\n>>>>\n>>>>      # Here we go:\n>>>>      git rebase -i --exec 'cd dir && git status' base\n>>>>\n>>>>      # Spawning a sub-shell doesn't help:\n>>>>      git rebase -i --exec '(cd dir && git status)' base\n>>>>\n>>>> Is this expected behavior or did I found a bug? Is there any\n>>>> workaround, other than cd'ing to the toplevel directory every time I\n>>>> want to run a git command when I am inside a subdirectory?\n\nNormally the exec capability is used to run compilation tests and then \nexplicitly report errors, rather than be another user interaction. Use 'e' \nedit for that.\n\n>>>>\n>>>> $ git --version\n>>>> git version 2.17.0\n>>>>\n--\nPhilip \n\n"},{"id":"348635","messageId":"D18E1FF6FF904372AB0343830C751094@PhilipOakley","threadId":"48525","inReplyTo":"3465c994-3917-cd45-bb8e-d1121f60bfb4@talktalk.net","subject":"Re: git rebase -i --exec and changing directory","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":"2018-05-27T17:25:03Z","receivedAt":"2018-05-27T17:25:15Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Hi Ondrej, Phillip,\n\nFrom: \"Phillip Wood\" <phillip.wood@talktalk.net>\n> Hi Ondrej\n>\n> On 27/05/18 13:53, Ondrej Mosnáček wrote:\n>>\n>> Hi Philip,\n>>\n>> 2018-05-27 14:28 GMT+02:00 Philip Oakley <philipoakley@iee.org>:\n>>> You may need to give a bit more background of things that seem obvious \n>>> to\n>>> you.\n>>> So where is the src directory you are cd'ing to relative to the\n>>> directory/repository you are creating?\n>>\n>> It is located in the top-level directory of the working tree (in the\n>> same directory that .git is in).\n>>\n>>  From git-rebase(1):\n>>\n>>      The \"exec\" command launches the command in a shell (the one\n>>      specified in $SHELL, or the default shell if $SHELL is not set), so\n>>      you can use shell features (like \"cd\", \">\", \";\" ...). The command is\n>>      run from the root of the working tree.\n>>\n>> So I need to run 'cd src' if I want to run a command in there\n>> (regardless of the working directory of the git rebase command\n>> itself).\n>>\n>>> What is [the name of] the directory you are currently in, etc. ?\n>>\n>> I don't think that is relevant here. FWIW, when verifying the problem\n>> I ran the reproducer from my original message in a directory whose\n>> path did not contain any spaces or special characters.\n>>\n>> Did you try to run the reproducing commands I posted? Did you get a\n>> different result? You should see the following in the output of 'cd\n>> dir && git status':\n\nAt the time, I hadn't run the command. I was more interested in \nunderstanding the problem setup, as understanding often brings \nenlightenment.\n\nI was jsut starting to do my own setup and swaw Phillip had responsed which \nprompted me to think it could be that there was no tty attached to the exec, \nso output wasn't being seen (or something like that).\n\n>\n> I tried your recipe and got the same result as you. However I think it \n> could be a problem with 'git status' rather than 'git rebase --exec'. If I \n> run your recipe in /tmp/a and do\n>\n> cd dir\n> GIT_DIR=/tmp/a/.git git status\n>\n> I get the same result as when running 'git status' from 'git \n> rebase --exec' So I think the problem might have something to do with \n> GIT_DIR being set in the environment when 'git status' is run\n>\n\nI too got the same same results.\nI also tried duplicating the exec line and placing it before the pick line, \njust to check it wasn't an issue about termination. Same result.\n\n> Best Wishes\n>\n> Phillip\n>\n>>\n>> [...]\n>> Changes not staged for commit:\n>>   (use \"git add/rm <file>...\" to update what will be committed)\n>>   (use \"git checkout -- <file>...\" to discard changes in working \n>> directory)\n>>\n>>         deleted:    a\n>>         deleted:    b\n>>         deleted:    dir/x\n>>         deleted:    reproduce.sh\n>>\n>> Untracked files:\n>>   (use \"git add <file>...\" to include in what will be committed)\n>>\n>>         x\n>> [...]\n>>\n>> When I drop the 'cd dir && ' from before 'git status', the output is\n>> as expected:\n>>\n>> You are currently editing a commit while rebasing branch 'master' on \n>> '19765db'.\n>>   (use \"git commit --amend\" to amend the current commit)\n>>   (use \"git rebase --continue\" once you are satisfied with your changes)\n>>\n>> nothing to commit, working tree clean\n\nSo I extended the command to be exec'd to `cd dir && ls && git status`, \nagain with duplication of the exec, which then gives a bit more..\n\nfinally I extended the status to pipe it's output to a file, again \nduplicated.\n--\nPhilip@PhilipOakley MINGW32 /usr/src/mosnacek (master)\n\n$ git rebase -i --exec 'cd dir && ls && git status >stat.txt' base\n\nExecuting: cd dir && ls && git status >stat0.txt\n\nx\n\nExecuting: cd dir && ls && git status >stat.txt\n\nstat0.txt x\n\nSuccessfully rebased and updated refs/heads/master.\n\n--\nthe stat0, stat files can then be investigated.\n\nSummary: status is, I think, being clever and dropping the verbiage when not \ndirectly attached to the terminal. (or it is being intelligent and adding a \nlot more status details just because it _is_ within the rebase..)\n\n>>\n>>>\n>>> Philip\n>>> --\n>>>\n>>> From: \"Ondrej Mosnáček\" <omosnacek@gmail.com>\n>>> Bump? Has anyone had time to look at this?\n>>>\n>>> 2018-05-19 18:38 GMT+02:00 Ondrej Mosnáček <omosnacek@gmail.com>:\n>>>>\n>>>> Hello,\n>>>>\n>>>> I am trying to run a script to edit multiple commits using 'git rebase\n>>>> -i --exec ...' and I ran into a strange behavior when I run 'cd'\n>>>> inside the --exec command and subsequently run a git command. For\n>>>> example, if the command is 'cd src && git status', then git status\n>>>> reports as if all files in the repository are deleted.\n\nWhat does that particular report look like? I see no special report of \ndeletions, or additions.\n\n\n>>>>\n>>>> Example command sequence to reproduce the problem:\n>>>>\n>>>>      # Setup:\n>>>>      touch a\n>>>>      mkdir dir\n>>>>      touch dir/x\n>>>>\n>>>>      git init .\n>>>>      git add --all\n>>>>      git commit -m commit1\n>>>>      git tag base\n>>>>      touch b\n>>>>      git add --all\n>>>>      git commit -m commit2\n>>>>\n>>>>      # Here we go:\n>>>>      git rebase -i --exec 'cd dir && git status' base\n>>>>\n>>>>      # Spawning a sub-shell doesn't help:\n>>>>      git rebase -i --exec '(cd dir && git status)' base\n>>>>\n>>>> Is this expected behavior or did I found a bug? Is there any\n>>>> workaround, other than cd'ing to the toplevel directory every time I\n>>>> want to run a git command when I am inside a subdirectory?\n\nNormally the exec capability is used to run compilation tests and then \nexplicitly report errors, rather than be another user interaction. Use 'e' \nedit for that.\n\n>>>>\n>>>> $ git --version\n>>>> git version 2.17.0\n>>>>\n--\nPhilip \n\n"},{"id":"348643","messageId":"xmqqfu2clcqo.fsf@gitster-ct.c.googlers.com","threadId":"48525","inReplyTo":"3465c994-3917-cd45-bb8e-d1121f60bfb4@talktalk.net","subject":"Re: git rebase -i --exec and changing directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-28T02:45:19Z","receivedAt":"2018-05-28T02:48:33Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood@talktalk.net> writes:\n\n> I tried your recipe and got the same result as you. However I think it\n> could be a problem with 'git status' rather than 'git rebase\n> --exec'. If I run your recipe in /tmp/a and do\n>\n> cd dir\n> GIT_DIR=/tmp/a/.git git status\n>\n> I get the same result as when running 'git status' from 'git rebase\n> --exec' So I think the problem might have something to do with GIT_DIR\n> being set in the environment when 'git status' is run\n\nYup.  \n\nWhen GIT_DIR environment variable appears without GIT_WORKING_TREE,\n\"git\" assumes that you are starting it at the root level of the\nworking tree.  In your example, if there is README at the top-level\nbut dir/README is not there, \"status\" would report that you removed\nit.  You can unset GIT_DIR in your --exec script if you know that\nGit would find the right repository when run from your script.\n\n"}]}