git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: test_pause giving '__git_ps1: not found' warning

From
Jeff King <peff@peff.net>
Date
Jan 16, 2023, 17:38 UTC
Message-ID
<Y8WLmmjL2HH2szGs@coredump.intra.peff.net>
In-Reply-To
<8355f48b-dbf9-7cfe-c85c-0d6ca5926c8c@iee.email>
On Sat, Jan 14, 2023 at 05:49:15PM +0000, Philip Oakley wrote:
Show 13 quoted lines
> 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.

Show 6 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. 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).

-Peff
Previous: Philip OakleyNext: Philip Oakley
Message 3 of 4 in “test_pause giving '__git_ps1: not found' warning”
  1. Philip OakleyJan 14, 2023
  2. Philip OakleyJan 14, 2023
  3. Jeff KingJan 16, 2023
  4. Philip OakleyJan 18, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.