X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=connect.c;h=9ae991ac42544716599ff8bf3ebaaa376c8119e4;hb=a347b17f15dd5358ced8d447af144a46b224982d;hp=f4563f951ac48dcc359071b7c1d68b795b617012;hpb=72a534dab016813eec71935323b197650a2c0c9d;p=git.git diff --git a/connect.c b/connect.c index f4563f951..9ae991ac4 100644 --- a/connect.c +++ b/connect.c @@ -479,7 +479,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig, /* * Don't do destructive transforms with git:// as that - * protocol code does '[]' dewrapping of its own. + * protocol code does '[]' unwrapping of its own. */ if (host[0] == '[') { end = strchr(host + 1, ']'); @@ -582,18 +582,8 @@ struct child_process *git_connect(int fd[2], const char *url_orig, *arg++ = host; } else { - /* remove these from the environment */ - const char *env[] = { - ALTERNATE_DB_ENVIRONMENT, - DB_ENVIRONMENT, - GIT_DIR_ENVIRONMENT, - GIT_WORK_TREE_ENVIRONMENT, - GRAFT_ENVIRONMENT, - INDEX_ENVIRONMENT, - NO_REPLACE_OBJECTS_ENVIRONMENT, - NULL - }; - conn->env = env; + /* remove repo-local variables from the environment */ + conn->env = local_repo_env; conn->use_shell = 1; } *arg++ = cmd.buf; @@ -622,3 +612,40 @@ int finish_connect(struct child_process *conn) free(conn); return code; } + +char *git_getpass(const char *prompt) +{ + char *askpass; + struct child_process pass; + const char *args[3]; + static struct strbuf buffer = STRBUF_INIT; + + askpass = getenv("GIT_ASKPASS"); + + if (!askpass || !(*askpass)) + return getpass(prompt); + + args[0] = askpass; + args[1] = prompt; + args[2] = NULL; + + memset(&pass, 0, sizeof(pass)); + pass.argv = args; + pass.out = -1; + + if (start_command(&pass)) + exit(1); + + strbuf_reset(&buffer); + if (strbuf_read(&buffer, pass.out, 20) < 0) + die("failed to read password from %s\n", askpass); + + close(pass.out); + + if (finish_command(&pass)) + exit(1); + + strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n")); + + return buffer.buf; +}