Coverage Report

Created: 2026-01-09 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/git/prompt.c
Line
Count
Source
1
#define USE_THE_REPOSITORY_VARIABLE
2
3
#include "git-compat-util.h"
4
#include "parse.h"
5
#include "environment.h"
6
#include "run-command.h"
7
#include "strbuf.h"
8
#include "prompt.h"
9
#include "compat/terminal.h"
10
11
static char *do_askpass(const char *cmd, const char *prompt)
12
0
{
13
0
  struct child_process pass = CHILD_PROCESS_INIT;
14
0
  static struct strbuf buffer = STRBUF_INIT;
15
0
  int err = 0;
16
17
0
  strvec_push(&pass.args, cmd);
18
0
  strvec_push(&pass.args, prompt);
19
20
0
  pass.out = -1;
21
22
0
  if (start_command(&pass))
23
0
    return NULL;
24
25
0
  strbuf_reset(&buffer);
26
0
  if (strbuf_read(&buffer, pass.out, 20) < 0)
27
0
    err = 1;
28
29
0
  close(pass.out);
30
31
0
  if (finish_command(&pass))
32
0
    err = 1;
33
34
0
  if (err) {
35
0
    error("unable to read askpass response from '%s'", cmd);
36
0
    strbuf_release(&buffer);
37
0
    return NULL;
38
0
  }
39
40
0
  strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));
41
42
0
  return buffer.buf;
43
0
}
44
45
char *git_prompt(const char *prompt, int flags)
46
0
{
47
0
  char *r = NULL;
48
49
0
  if (flags & PROMPT_ASKPASS) {
50
0
    const char *askpass;
51
52
0
    askpass = getenv("GIT_ASKPASS");
53
0
    if (!askpass)
54
0
      askpass = askpass_program;
55
0
    if (!askpass)
56
0
      askpass = getenv("SSH_ASKPASS");
57
0
    if (askpass && *askpass)
58
0
      r = do_askpass(askpass, prompt);
59
0
  }
60
61
0
  if (!r) {
62
0
    const char *err;
63
64
0
    if (git_env_bool("GIT_TERMINAL_PROMPT", 1)) {
65
0
      r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
66
0
      err = strerror(errno);
67
0
    } else {
68
0
      err = "terminal prompts disabled";
69
0
    }
70
0
    if (!r) {
71
      /* prompts already contain ": " at the end */
72
0
      die("could not read %s%s", prompt, err);
73
0
    }
74
0
  }
75
0
  return r;
76
0
}
77
78
int git_read_line_interactively(struct strbuf *line)
79
0
{
80
0
  fflush(stdout);
81
  return strbuf_getline(line, stdin);
82
0
}