Merge branch 'jk/credential-quit'
authorJunio C Hamano <gitster@pobox.com>
Mon, 22 Dec 2014 20:27:19 +0000 (12:27 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Dec 2014 20:27:20 +0000 (12:27 -0800)
Credential helpers are asked in turn until one of them give
positive response, which is cumbersome to turn off when you need to
run Git in an automated setting. The credential helper interface
learned to allow a helper to say "stop, don't ask other helpers."
Also GIT_TERMINAL_PROMPT environment can be set to false to disable
our built-in prompt mechanism for passwords.

* jk/credential-quit:
prompt: respect GIT_TERMINAL_PROMPT to disable terminal prompts
credential: let helpers tell us to quit

1  2 
Documentation/git.txt
credential.c
prompt.c
diff --combined Documentation/git.txt
index 73dc0ad0a03607db45a4f6056d9cdac58dbeca5e,72b6a2df14c115c14cb57dd5bef6bd33ef2d4c5d..179615195fd260d4d6d87bc1cda6f5c8a699719d
@@@ -22,7 -22,7 +22,7 @@@ unusually rich command set that provide
  and full access to internals.
  
  See linkgit:gittutorial[7] to get started, then see
 -link:everyday.html[Everyday Git] for a useful minimum set of
 +linkgit:giteveryday[7] for a useful minimum set of
  commands.  The link:user-manual.html[Git User's Manual] has a more
  in-depth introduction.
  
@@@ -43,45 -43,35 +43,45 @@@ unreleased) version of Git, that is ava
  branch of the `git.git` repository.
  Documentation for older releases are available here:
  
 -* link:v2.1.3/git.html[documentation for release 2.1.3]
 +* link:v2.2.1/git.html[documentation for release 2.2.1]
  
  * release notes for
 +  link:RelNotes/2.2.1.txt[2.2.1],
 +  link:RelNotes/2.2.0.txt[2.2].
 +
 +* link:v2.1.4/git.html[documentation for release 2.1.4]
 +
 +* release notes for
 +  link:RelNotes/2.1.4.txt[2.1.4],
    link:RelNotes/2.1.3.txt[2.1.3],
    link:RelNotes/2.1.2.txt[2.1.2],
    link:RelNotes/2.1.1.txt[2.1.1],
    link:RelNotes/2.1.0.txt[2.1].
  
 -* link:v2.0.4/git.html[documentation for release 2.0.4]
 +* link:v2.0.5/git.html[documentation for release 2.0.5]
  
  * release notes for
 +  link:RelNotes/2.0.5.txt[2.0.5],
    link:RelNotes/2.0.4.txt[2.0.4],
    link:RelNotes/2.0.3.txt[2.0.3],
    link:RelNotes/2.0.2.txt[2.0.2],
    link:RelNotes/2.0.1.txt[2.0.1],
    link:RelNotes/2.0.0.txt[2.0.0].
  
 -* link:v1.9.4/git.html[documentation for release 1.9.4]
 +* link:v1.9.5/git.html[documentation for release 1.9.5]
  
  * release notes for
 +  link:RelNotes/1.9.5.txt[1.9.5],
    link:RelNotes/1.9.4.txt[1.9.4],
    link:RelNotes/1.9.3.txt[1.9.3],
    link:RelNotes/1.9.2.txt[1.9.2],
    link:RelNotes/1.9.1.txt[1.9.1],
    link:RelNotes/1.9.0.txt[1.9.0].
  
 -* link:v1.8.5.5/git.html[documentation for release 1.8.5.5]
 +* link:v1.8.5.6/git.html[documentation for release 1.8.5.6]
  
  * release notes for
 +  link:RelNotes/1.8.5.6.txt[1.8.5.6],
    link:RelNotes/1.8.5.5.txt[1.8.5.5],
    link:RelNotes/1.8.5.4.txt[1.8.5.4],
    link:RelNotes/1.8.5.3.txt[1.8.5.3],
@@@ -886,21 -876,19 +886,21 @@@ othe
        and the `core.editor` option in linkgit:git-config[1].
  
  'GIT_SSH'::
 -      If this environment variable is set then 'git fetch'
 -      and 'git push' will use this command instead
 -      of 'ssh' when they need to connect to a remote system.
 -      The '$GIT_SSH' command will be given exactly two or
 -      four arguments: the 'username@host' (or just 'host')
 -      from the URL and the shell command to execute on that
 -      remote system, optionally preceded by '-p' (literally) and
 -      the 'port' from the URL when it specifies something other
 -      than the default SSH port.
 +'GIT_SSH_COMMAND'::
 +      If either of these environment variables is set then 'git fetch'
 +      and 'git push' will use the specified command instead of 'ssh'
 +      when they need to connect to a remote system.
 +      The command will be given exactly two or four arguments: the
 +      'username@host' (or just 'host') from the URL and the shell
 +      command to execute on that remote system, optionally preceded by
 +      '-p' (literally) and the 'port' from the URL when it specifies
 +      something other than the default SSH port.
  +
 -To pass options to the program that you want to list in GIT_SSH
 -you will need to wrap the program and options into a shell script,
 -then set GIT_SSH to refer to the shell script.
 +`$GIT_SSH_COMMAND` takes precedence over `$GIT_SSH`, and is interpreted
 +by the shell, which allows additional arguments to be included.
 +`$GIT_SSH` on the other hand must be just the path to a program
 +(which can be a wrapper shell script, if additional arguments are
 +needed).
  +
  Usually it is easier to configure any desired options through your
  personal `.ssh/config` file.  Please consult your ssh documentation
@@@ -913,6 -901,10 +913,10 @@@ for further details
        and read the password from its STDOUT. See also the 'core.askpass'
        option in linkgit:git-config[1].
  
+ 'GIT_TERMINAL_PROMPT'::
+       If this environment variable is set to `0`, git will not prompt
+       on the terminal (e.g., when asking for HTTP authentication).
  'GIT_CONFIG_NOSYSTEM'::
        Whether to skip reading settings from the system-wide
        `$(prefix)/etc/gitconfig` file.  This environment variable can
@@@ -1111,7 -1103,7 +1115,7 @@@ subscribed to the list to send a messag
  SEE ALSO
  --------
  linkgit:gittutorial[7], linkgit:gittutorial-2[7],
 -link:everyday.html[Everyday Git], linkgit:gitcvs-migration[7],
 +linkgit:giteveryday[7], linkgit:gitcvs-migration[7],
  linkgit:gitglossary[7], linkgit:gitcore-tutorial[7],
  linkgit:gitcli[7], link:user-manual.html[The Git User's Manual],
  linkgit:gitworkflows[7]
diff --combined credential.c
index 1886ea50b3b3c2a213e34876de691fa3d0a83b6c,0f974f1987b78fb506e044fd8180c2f24fb86703..b146ad8481b133892a542691c7e36f5e7974cfdc
@@@ -173,6 -173,8 +173,8 @@@ int credential_read(struct credential *
                        c->path = xstrdup(value);
                } else if (!strcmp(key, "url")) {
                        credential_from_url(c, value);
+               } else if (!strcmp(key, "quit")) {
+                       c->quit = !!git_config_bool("quit", value);
                }
                /*
                 * Ignore other lines; we don't know what they mean, but
@@@ -205,10 -207,11 +207,10 @@@ static int run_credential_helper(struc
                                 const char *cmd,
                                 int want_output)
  {
 -      struct child_process helper;
 +      struct child_process helper = CHILD_PROCESS_INIT;
        const char *argv[] = { NULL, NULL };
        FILE *fp;
  
 -      memset(&helper, 0, sizeof(helper));
        argv[0] = cmd;
        helper.argv = argv;
        helper.use_shell = 1;
@@@ -274,6 -277,9 +276,9 @@@ void credential_fill(struct credential 
                credential_do(c, c->helpers.items[i].string, "get");
                if (c->username && c->password)
                        return;
+               if (c->quit)
+                       die("credential helper '%s' told us to quit",
+                           c->helpers.items[i].string);
        }
  
        credential_getpass(c);
diff --combined prompt.c
index e5b4938efcf329eb4f25b6f90231c35abeacbbd3,35ddbfab0cc01899936e8eb4e45e6c7ac8981dd8..8181eebbfcd0080540bc580416336436ced98297
+++ b/prompt.c
@@@ -6,7 -6,7 +6,7 @@@
  
  static char *do_askpass(const char *cmd, const char *prompt)
  {
 -      struct child_process pass;
 +      struct child_process pass = CHILD_PROCESS_INIT;
        const char *args[3];
        static struct strbuf buffer = STRBUF_INIT;
        int err = 0;
@@@ -15,6 -15,7 +15,6 @@@
        args[1] = prompt;
        args[2] = NULL;
  
 -      memset(&pass, 0, sizeof(pass));
        pass.argv = args;
        pass.out = -1;
  
@@@ -57,11 -58,19 +57,19 @@@ char *git_prompt(const char *prompt, in
                        r = do_askpass(askpass, prompt);
        }
  
-       if (!r)
-               r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
        if (!r) {
-               /* prompts already contain ": " at the end */
-               die("could not read %s%s", prompt, strerror(errno));
+               const char *err;
+               if (git_env_bool("GIT_TERMINAL_PROMPT", 1)) {
+                       r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
+                       err = strerror(errno);
+               } else {
+                       err = "terminal prompts disabled";
+               }
+               if (!r) {
+                       /* prompts already contain ": " at the end */
+                       die("could not read %s%s", prompt, err);
+               }
        }
        return r;
  }