Skip to content

Commit a48b409

Browse files
peffgitster
authored andcommitted
git_connect: clarify conn->use_shell flag
When executing user-specified programs, we generally always want to use a shell, for flexibility and consistency. One big exception is executing $GIT_SSH, which for historical reasons must not use a shell. Once upon a time the logic in git_connect looked like: if (protocol == PROTO_SSH) { ... setup ssh ... } else { ... setup local connection ... conn->use_shell = 1; } But over time the PROTO_SSH block has grown, and the "local" block has shrunk so that it contains only conn->use_shell; it's easy to miss at the end of the large block. Moreover, PROTO_SSH now also sometimes sets use_shell, when the new GIT_SSH_COMMAND is used. Let's just set conn->use_shell when we're setting up the "conn" struct, and unset it (with a comment) in the historical GIT_SSH case. This will make the flow easier to follow. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aab4043 commit a48b409

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

connect.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,11 @@ struct child_process *git_connect(int fd[2], const char *url,
723723

724724
/* remove repo-local variables from the environment */
725725
conn->env = local_repo_env;
726+
conn->use_shell = 1;
726727
conn->in = conn->out = -1;
727728
if (protocol == PROTO_SSH) {
728729
const char *ssh;
729-
int putty, tortoiseplink = 0;
730+
int putty = 0, tortoiseplink = 0;
730731
char *ssh_host = hostandport;
731732
const char *port = NULL;
732733
get_host_and_port(&ssh_host, &port);
@@ -748,13 +749,17 @@ struct child_process *git_connect(int fd[2], const char *url,
748749
}
749750

750751
ssh = getenv("GIT_SSH_COMMAND");
751-
if (ssh) {
752-
conn->use_shell = 1;
753-
putty = 0;
754-
} else {
752+
if (!ssh) {
755753
const char *base;
756754
char *ssh_dup;
757755

756+
/*
757+
* GIT_SSH is the no-shell version of
758+
* GIT_SSH_COMMAND (and must remain so for
759+
* historical compatibility).
760+
*/
761+
conn->use_shell = 0;
762+
758763
ssh = getenv("GIT_SSH");
759764
if (!ssh)
760765
ssh = "ssh";
@@ -764,8 +769,9 @@ struct child_process *git_connect(int fd[2], const char *url,
764769

765770
tortoiseplink = !strcasecmp(base, "tortoiseplink") ||
766771
!strcasecmp(base, "tortoiseplink.exe");
767-
putty = !strcasecmp(base, "plink") ||
768-
!strcasecmp(base, "plink.exe") || tortoiseplink;
772+
putty = tortoiseplink ||
773+
!strcasecmp(base, "plink") ||
774+
!strcasecmp(base, "plink.exe");
769775

770776
free(ssh_dup);
771777
}
@@ -779,8 +785,6 @@ struct child_process *git_connect(int fd[2], const char *url,
779785
argv_array_push(&conn->args, port);
780786
}
781787
argv_array_push(&conn->args, ssh_host);
782-
} else {
783-
conn->use_shell = 1;
784788
}
785789
argv_array_push(&conn->args, cmd.buf);
786790

0 commit comments

Comments
 (0)