@@ -9,6 +9,7 @@ static char *do_askpass(const char *cmd, const char *prompt)
9
9
struct child_process pass ;
10
10
const char * args [3 ];
11
11
static struct strbuf buffer = STRBUF_INIT ;
12
+ int err = 0 ;
12
13
13
14
args [0 ] = cmd ;
14
15
args [1 ] = prompt ;
@@ -19,25 +20,30 @@ static char *do_askpass(const char *cmd, const char *prompt)
19
20
pass .out = -1 ;
20
21
21
22
if (start_command (& pass ))
22
- exit ( 1 ) ;
23
+ return NULL ;
23
24
24
- strbuf_reset (& buffer );
25
25
if (strbuf_read (& buffer , pass .out , 20 ) < 0 )
26
- die ( "failed to get '%s' from %s\n" , prompt , cmd ) ;
26
+ err = 1 ;
27
27
28
28
close (pass .out );
29
29
30
30
if (finish_command (& pass ))
31
- exit (1 );
31
+ err = 1 ;
32
+
33
+ if (err ) {
34
+ error ("unable to read askpass response from '%s'" , cmd );
35
+ strbuf_release (& buffer );
36
+ return NULL ;
37
+ }
32
38
33
39
strbuf_setlen (& buffer , strcspn (buffer .buf , "\r\n" ));
34
40
35
- return buffer . buf ;
41
+ return strbuf_detach ( & buffer , NULL ) ;
36
42
}
37
43
38
44
char * git_prompt (const char * prompt , int flags )
39
45
{
40
- char * r ;
46
+ char * r = NULL ;
41
47
42
48
if (flags & PROMPT_ASKPASS ) {
43
49
const char * askpass ;
@@ -48,12 +54,15 @@ char *git_prompt(const char *prompt, int flags)
48
54
if (!askpass )
49
55
askpass = getenv ("SSH_ASKPASS" );
50
56
if (askpass && * askpass )
51
- return do_askpass (askpass , prompt );
57
+ r = do_askpass (askpass , prompt );
52
58
}
53
59
54
- r = git_terminal_prompt (prompt , flags & PROMPT_ECHO );
55
60
if (!r )
56
- die_errno ("could not read '%s'" , prompt );
61
+ r = git_terminal_prompt (prompt , flags & PROMPT_ECHO );
62
+ if (!r ) {
63
+ /* prompts already contain ": " at the end */
64
+ die ("could not read %s%s" , prompt , strerror (errno ));
65
+ }
57
66
return r ;
58
67
}
59
68
0 commit comments