Re: test_pause giving '__git_ps1: not found' warning
- From
Philip Oakley <philipoakley@iee.email>
- Date
- Jan 18, 2023, 13:50 UTC
- Message-ID
- <3cc61b40-6493-ead3-37fb-0af97213122c@iee.email>
- In-Reply-To
- <Y8WLmmjL2HH2szGs@coredump.intra.peff.net>
On 16/01/2023 17:38, Jeff King wrote:
Show 17 quoted lines
> On Sat, Jan 14, 2023 at 05:49:15PM +0000, Philip Oakley wrote: > >> On 14/01/2023 14:54, Philip Oakley wrote: >>> I was trying to refine a test_expect_failure test [1] and tried >>> inserting a `test_pause &&` test line [2]. >>> >>> I then found, when it paused, I was repeatedly given the warning line >>> /bin/sh: 1: __git_ps1: not found >>> in the terminal until I expected the test shell. >>> >>> my PS1 is working normally in the terminal, but not here. Is this >>> expected, or do I need to set up anything else? >>> >>> Normally I'm on Git for Windows, but this was on my old laptop (Acer >>> 7741 i5 4GB ram..) converted to Ubuntu 20.04, which I use when away. > On Ubuntu, your /bin/sh is likely to be dash. And unless you've set > TEST_SHELL_PATH, that's what test_pause will use.
Thanks. Some of these little tidbits passed me by.
I wasactually trying to understand why $(printf "\145\314\201") wasn't working as expected (or the hex equivalent) depending on which machine (Ubuntu / Windows) I was on (when running in a test as part of t/t4205-log-pretty-formats.sh). I.e. sometimes the results looked like the unicode was being recognised, and others as if part were just ascii characters, ignoring the octal/hex escaping)
Show 8 quoted lines
> >> My local .bashrc has >> >> . /home/philip/git-completion.bash >> . ~/git-prompt.sh >> export GIT_PS1_SHOWDIRTYSTATE=1 >> export PS1='\w$(__git_ps1 " (%s)")\$ ' > It's unusual to export PS1. Only the shell needs it.
It's the default setting described in the git-scm book's Appendix A "Git in Bash" [1].
Not sure if extra clarification is needed, or where that advice originated from. It (export'ing) is not currently part of contrib's git-prompt.sh comments [2].
Show 15 quoted lines
> But by exporting > it, the child "dash" will see it, but of course doesn't have the > __git_ps1() function defined. And thus the complaint. > > If you stop exporting it, then you'd see dash's regular prompt. Which > fixes the "whoops, __git_ps1() is not defined" problem, but probably is > not quite what you want, if you really wanted a nice prompt. > >> Not sure why I have a relative and an absolute path but... , so I'll try >> updating the git-prompt.sh to an absolute path, and if that works, maybe >> think about adding an extra comment to the `test-lib-functions.sh` to note >> the change of HOME and potential '__git_ps1' problem > It looks like test_pause() has various options for retaining shell, > term, home, etc, and includes documentation. I haven't played with them > myself, though.
> Usually I just use "-i" to stop the test, and then > investigate the result in one of my regular shells (and in the rare case > of "oops, it succeeds when I expect it to fail,
> I insert "false &&" as > appropriate).
That's a neat alternative.
> > -Peff
-- Philip [1] https://git-scm.com/book/uz/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Bash [2] https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh