{"thread":{"id":"59091","subject":"test_pause giving '__git_ps1: not found' warning","startedAt":"2023-01-14T14:54:52Z","lastAt":"2023-01-18T14:10:44Z","messageCount":4,"participants":["Philip Oakley","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"470342","messageId":"bce6ac3a-17a6-beed-43ef-5a1e0dd92a5d@iee.email","threadId":"59091","inReplyTo":null,"subject":"test_pause giving '__git_ps1: not found' warning","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2023-01-14T14:54:45Z","receivedAt":"2023-01-14T14:54:52Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"I was trying to refine a test_expect_failure test [1] and tried \ninserting a `test_pause &&` test line [2].\n\nI then found, when it paused, I was repeatedly given the warning line\n     /bin/sh: 1: __git_ps1: not found\nin the terminal until I expected the test shell.\n\nmy PS1 is working normally in the terminal, but not here.  Is this \nexpected, or do I need to set up anything else?\n\nNormally I'm on Git for Windows, but this was on my old laptop (Acer \n7741 i5 4GB ram..) converted to Ubuntu 20.04, which I use when away.\n\nThe basic sequence was\n\n~$ cd repos/git\n~/repos/git (doctrunc *)$ cd t\n~/repos/git/t (doctrunc *)$ ./t4205-log-pretty-formats.sh  -i -x -v\nInitialized empty Git repository in /home/philip/repos/git/t/trash \ndirectory.t4205-log-pretty-formats/.git/\n\n[... ...]\n\n+ git log --format=%<(5,mtrunc)%s -4\n+ test_pause\n+ PAUSE_TERM=dumb\n+ PAUSE_SHELL=/bin/sh\n+ PAUSE_HOME=/home/philip/repos/git/t/trash \ndirectory.t4205-log-pretty-formats\n+ test 0 != 0\n+ TERM=dumb HOME=/home/philip/repos/git/t/trash \ndirectory.t4205-log-pretty-formats /bin/sh\n/bin/sh: 1: __git_ps1: not found\n\\w$ git status\nOn branch source-b\n[...]\nnothing added to commit but untracked files present (use \"git add\" to track)\n/bin/sh: 1: __git_ps1: not found\n\nI added the gits status to see when/where the warning was emitted.\n\n[1] \nhttps://github.com/PhilipOakley/git/blob/doctrunc/t/t4205-log-pretty-formats.sh#L1021-L1046\n[2] https://github.com/git/git/blob/master/t/test-lib-functions.sh#L137-L188\n\n\nAny suggestions as to how to set this up correctly to avoid the warning?\n--\nPhilip\n"},{"id":"470359","messageId":"8355f48b-dbf9-7cfe-c85c-0d6ca5926c8c@iee.email","threadId":"59091","inReplyTo":"bce6ac3a-17a6-beed-43ef-5a1e0dd92a5d@iee.email","subject":"Re: test_pause giving '__git_ps1: not found' warning","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2023-01-14T17:49:15Z","receivedAt":"2023-01-14T17:49:29Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"On 14/01/2023 14:54, Philip Oakley wrote:\n> I was trying to refine a test_expect_failure test [1] and tried \n> inserting a `test_pause &&` test line [2].\n>\n> I then found, when it paused, I was repeatedly given the warning line\n>     /bin/sh: 1: __git_ps1: not found\n> in the terminal until I expected the test shell.\n>\n> my PS1 is working normally in the terminal, but not here.  Is this \n> expected, or do I need to set up anything else?\n>\n> Normally I'm on Git for Windows, but this was on my old laptop (Acer \n> 7741 i5 4GB ram..) converted to Ubuntu 20.04, which I use when away.\n>\n> The basic sequence was\n>\n> ~$ cd repos/git\n> ~/repos/git (doctrunc *)$ cd t\n> ~/repos/git/t (doctrunc *)$ ./t4205-log-pretty-formats.sh  -i -x -v\n> Initialized empty Git repository in /home/philip/repos/git/t/trash \n> directory.t4205-log-pretty-formats/.git/\n>\n> [... ...]\n>\n> + git log --format=%<(5,mtrunc)%s -4\n> + test_pause\n> + PAUSE_TERM=dumb\n> + PAUSE_SHELL=/bin/sh\n> + PAUSE_HOME=/home/philip/repos/git/t/trash \n> directory.t4205-log-pretty-formats\n> + test 0 != 0\n> + TERM=dumb HOME=/home/philip/repos/git/t/trash \n> directory.t4205-log-pretty-formats /bin/sh\n\nI think the 'gotcha' is here in the setting of HOME within the \ntest_pause which in some ways conflicts with the setting of the \n__git_ps1 instructions [3].\n\nMy local .bashrc has\n\n     . /home/philip/git-completion.bash\n     . ~/git-prompt.sh\n     export GIT_PS1_SHOWDIRTYSTATE=1\n     export PS1='\\w$(__git_ps1 \" (%s)\")\\$ '\n\nNot sure why I have a relative and an absolute path but... ,  so I'll \ntry updating the git-prompt.sh to an absolute path, and if that works, \nmaybe think about adding an extra comment to the `test-lib-functions.sh` \nto note the change of HOME and potential '__git_ps1' problem\n\n[3] \nhttps://git-scm.com/book/uz/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Bash\n\n> /bin/sh: 1: __git_ps1: not found\n> \\w$ git status\n> On branch source-b\n> [...]\n> nothing added to commit but untracked files present (use \"git add\" to \n> track)\n> /bin/sh: 1: __git_ps1: not found\n>\n> I added the gits status to see when/where the warning was emitted.\n>\n> [1] \n> https://github.com/PhilipOakley/git/blob/doctrunc/t/t4205-log-pretty-formats.sh#L1021-L1046\n> [2] \n> https://github.com/git/git/blob/master/t/test-lib-functions.sh#L137-L188\n>\n>\n> Any suggestions as to how to set this up correctly to avoid the warning?\n> -- \n> Philip\n\n"},{"id":"470448","messageId":"Y8WLmmjL2HH2szGs@coredump.intra.peff.net","threadId":"59091","inReplyTo":"8355f48b-dbf9-7cfe-c85c-0d6ca5926c8c@iee.email","subject":"Re: test_pause giving '__git_ps1: not found' warning","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-01-16T17:38:34Z","receivedAt":"2023-01-16T17:58:58Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jan 14, 2023 at 05:49:15PM +0000, Philip Oakley wrote:\n\n> On 14/01/2023 14:54, Philip Oakley wrote:\n> > I was trying to refine a test_expect_failure test [1] and tried\n> > inserting a `test_pause &&` test line [2].\n> > \n> > I then found, when it paused, I was repeatedly given the warning line\n> >     /bin/sh: 1: __git_ps1: not found\n> > in the terminal until I expected the test shell.\n> > \n> > my PS1 is working normally in the terminal, but not here.  Is this\n> > expected, or do I need to set up anything else?\n> > \n> > Normally I'm on Git for Windows, but this was on my old laptop (Acer\n> > 7741 i5 4GB ram..) converted to Ubuntu 20.04, which I use when away.\n\nOn Ubuntu, your /bin/sh is likely to be dash. And unless you've set\nTEST_SHELL_PATH, that's what test_pause will use.\n\n> My local .bashrc has\n> \n>     . /home/philip/git-completion.bash\n>     . ~/git-prompt.sh\n>     export GIT_PS1_SHOWDIRTYSTATE=1\n>     export PS1='\\w$(__git_ps1 \" (%s)\")\\$ '\n\nIt's unusual to export PS1. Only the shell needs it. But by exporting\nit, the child \"dash\" will see it, but of course doesn't have the\n__git_ps1() function defined. And thus the complaint.\n\nIf you stop exporting it, then you'd see dash's regular prompt. Which\nfixes the \"whoops, __git_ps1() is not defined\" problem, but probably is\nnot quite what you want, if you really wanted a nice prompt.\n\n> Not sure why I have a relative and an absolute path but... ,  so I'll try\n> updating the git-prompt.sh to an absolute path, and if that works, maybe\n> think about adding an extra comment to the `test-lib-functions.sh` to note\n> the change of HOME and potential '__git_ps1' problem\n\nIt looks like test_pause() has various options for retaining shell,\nterm, home, etc, and includes documentation. I haven't played with them\nmyself, though. Usually I just use \"-i\" to stop the test, and then\ninvestigate the result in one of my regular shells (and in the rare case\nof \"oops, it succeeds when I expect it to fail, I insert \"false &&\" as\nappropriate).\n\n-Peff\n"},{"id":"470621","messageId":"3cc61b40-6493-ead3-37fb-0af97213122c@iee.email","threadId":"59091","inReplyTo":"Y8WLmmjL2HH2szGs@coredump.intra.peff.net","subject":"Re: test_pause giving '__git_ps1: not found' warning","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2023-01-18T13:50:40Z","receivedAt":"2023-01-18T14:10:44Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"On 16/01/2023 17:38, Jeff King wrote:\n> On Sat, Jan 14, 2023 at 05:49:15PM +0000, Philip Oakley wrote:\n>\n>> On 14/01/2023 14:54, Philip Oakley wrote:\n>>> I was trying to refine a test_expect_failure test [1] and tried\n>>> inserting a `test_pause &&` test line [2].\n>>>\n>>> I then found, when it paused, I was repeatedly given the warning line\n>>>     /bin/sh: 1: __git_ps1: not found\n>>> in the terminal until I expected the test shell.\n>>>\n>>> my PS1 is working normally in the terminal, but not here.  Is this\n>>> expected, or do I need to set up anything else?\n>>>\n>>> Normally I'm on Git for Windows, but this was on my old laptop (Acer\n>>> 7741 i5 4GB ram..) converted to Ubuntu 20.04, which I use when away.\n> On Ubuntu, your /bin/sh is likely to be dash. And unless you've set\n> TEST_SHELL_PATH, that's what test_pause will use.\n\nThanks. Some of these little tidbits passed me by.\n\nI wasactually  trying to understand why  $(printf \"\\145\\314\\201\") wasn't\nworking as expected (or the hex equivalent) depending on which machine\n(Ubuntu / Windows) I was on (when running in a test as part of\nt/t4205-log-pretty-formats.sh). I.e. sometimes the results looked like\nthe unicode was being recognised, and others as if part were just ascii\ncharacters, ignoring the octal/hex escaping)\n \n>\n>> My local .bashrc has\n>>\n>>     . /home/philip/git-completion.bash\n>>     . ~/git-prompt.sh\n>>     export GIT_PS1_SHOWDIRTYSTATE=1\n>>     export PS1='\\w$(__git_ps1 \" (%s)\")\\$ '\n> It's unusual to export PS1. Only the shell needs it. \n\nIt's the default setting described in the git-scm book's Appendix A \"Git\nin Bash\" [1].\n\nNot sure if extra clarification is needed, or where that advice\noriginated from. It (export'ing) is not currently part of contrib's\ngit-prompt.sh comments [2].\n\n> But by exporting\n> it, the child \"dash\" will see it, but of course doesn't have the\n> __git_ps1() function defined. And thus the complaint.\n>\n> If you stop exporting it, then you'd see dash's regular prompt. Which\n> fixes the \"whoops, __git_ps1() is not defined\" problem, but probably is\n> not quite what you want, if you really wanted a nice prompt.\n>\n>> Not sure why I have a relative and an absolute path but... ,  so I'll try\n>> updating the git-prompt.sh to an absolute path, and if that works, maybe\n>> think about adding an extra comment to the `test-lib-functions.sh` to note\n>> the change of HOME and potential '__git_ps1' problem\n> It looks like test_pause() has various options for retaining shell,\n> term, home, etc, and includes documentation. I haven't played with them\n> myself, though. \n\n> Usually I just use \"-i\" to stop the test, and then\n> investigate the result in one of my regular shells (and in the rare case\n> of \"oops, it succeeds when I expect it to fail, \n\n> I insert \"false &&\" as\n> appropriate).\n\nThat's a neat alternative.\n>\n> -Peff\n--\nPhilip\n[1]\nhttps://git-scm.com/book/uz/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Bash\n[2] https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh\n"}]}