THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.4KB

  1. #include "cache.h"
  2. #include "config.h"
  3. #include "run-command.h"
  4. #include "strbuf.h"
  5. #include "prompt.h"
  6. #include "compat/terminal.h"
  7. static char *do_askpass(const char *cmd, const char *prompt)
  8. {
  9. struct child_process pass = CHILD_PROCESS_INIT;
  10. const char *args[3];
  11. static struct strbuf buffer = STRBUF_INIT;
  12. int err = 0;
  13. args[0] = cmd;
  14. args[1] = prompt;
  15. args[2] = NULL;
  16. pass.argv = args;
  17. pass.out = -1;
  18. if (start_command(&pass))
  19. return NULL;
  20. strbuf_reset(&buffer);
  21. if (strbuf_read(&buffer, pass.out, 20) < 0)
  22. err = 1;
  23. close(pass.out);
  24. if (finish_command(&pass))
  25. err = 1;
  26. if (err) {
  27. error("unable to read askpass response from '%s'", cmd);
  28. strbuf_release(&buffer);
  29. return NULL;
  30. }
  31. strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));
  32. return buffer.buf;
  33. }
  34. char *git_prompt(const char *prompt, int flags)
  35. {
  36. char *r = NULL;
  37. if (flags & PROMPT_ASKPASS) {
  38. const char *askpass;
  39. askpass = getenv("GIT_ASKPASS");
  40. if (!askpass)
  41. askpass = askpass_program;
  42. if (!askpass)
  43. askpass = getenv("SSH_ASKPASS");
  44. if (askpass && *askpass)
  45. r = do_askpass(askpass, prompt);
  46. }
  47. if (!r) {
  48. const char *err;
  49. if (git_env_bool("GIT_TERMINAL_PROMPT", 1)) {
  50. r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
  51. err = strerror(errno);
  52. } else {
  53. err = "terminal prompts disabled";
  54. }
  55. if (!r) {
  56. /* prompts already contain ": " at the end */
  57. die("could not read %s%s", prompt, err);
  58. }
  59. }
  60. return r;
  61. }