Skip to content

Commit f879501

Browse files
committed
Merge branch 'jk/fix-proto-downgrade-to-v0'
Transports that do not support protocol v2 did not correctly fall back to protocol v0 under certain conditions, which has been corrected. * jk/fix-proto-downgrade-to-v0: git_connect(): fix corner cases in downgrading v2 to v0
2 parents 8069aa0 + eaa0fd6 commit f879501

File tree

7 files changed

+47
-13
lines changed

7 files changed

+47
-13
lines changed

builtin/fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
213213
int flags = args.verbose ? CONNECT_VERBOSE : 0;
214214
if (args.diag_url)
215215
flags |= CONNECT_DIAG_URL;
216-
conn = git_connect(fd, dest, args.uploadpack,
217-
flags);
216+
conn = git_connect(fd, dest, "git-upload-pack",
217+
args.uploadpack, flags);
218218
if (!conn)
219219
return args.diag_url ? 0 : 1;
220220
}

builtin/send-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
274274
fd[0] = 0;
275275
fd[1] = 1;
276276
} else {
277-
conn = git_connect(fd, dest, receivepack,
277+
conn = git_connect(fd, dest, "git-receive-pack", receivepack,
278278
args.verbose ? CONNECT_VERBOSE : 0);
279279
}
280280

connect.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@ static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
14081408
* the connection failed).
14091409
*/
14101410
struct child_process *git_connect(int fd[2], const char *url,
1411+
const char *name,
14111412
const char *prog, int flags)
14121413
{
14131414
char *hostandport, *path;
@@ -1417,10 +1418,11 @@ struct child_process *git_connect(int fd[2], const char *url,
14171418

14181419
/*
14191420
* NEEDSWORK: If we are trying to use protocol v2 and we are planning
1420-
* to perform a push, then fallback to v0 since the client doesn't know
1421-
* how to push yet using v2.
1421+
* to perform any operation that doesn't involve upload-pack (i.e., a
1422+
* fetch, ls-remote, etc), then fallback to v0 since we don't know how
1423+
* to do anything else (like push or remote archive) via v2.
14221424
*/
1423-
if (version == protocol_v2 && !strcmp("git-receive-pack", prog))
1425+
if (version == protocol_v2 && strcmp("git-upload-pack", name))
14241426
version = protocol_v0;
14251427

14261428
/* Without this we cannot rely on waitpid() to tell

connect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define CONNECT_DIAG_URL (1u << 1)
88
#define CONNECT_IPV4 (1u << 2)
99
#define CONNECT_IPV6 (1u << 3)
10-
struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
10+
struct child_process *git_connect(int fd[2], const char *url, const char *name, const char *prog, int flags);
1111
int finish_connect(struct child_process *conn);
1212
int git_connection_is_socket(struct child_process *conn);
1313
int server_supports(const char *feature);

remote-curl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,11 @@ static struct discovery *discover_refs(const char *service, int for_push)
474474

475475
/*
476476
* NEEDSWORK: If we are trying to use protocol v2 and we are planning
477-
* to perform a push, then fallback to v0 since the client doesn't know
478-
* how to push yet using v2.
477+
* to perform any operation that doesn't involve upload-pack (i.e., a
478+
* fetch, ls-remote, etc), then fallback to v0 since we don't know how
479+
* to do anything else (like push or remote archive) via v2.
479480
*/
480-
if (version == protocol_v2 && !strcmp("git-receive-pack", service))
481+
if (version == protocol_v2 && strcmp("git-upload-pack", service))
481482
version = protocol_v0;
482483

483484
/* Add the extra Git-Protocol header */

t/t5702-protocol-v2.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,33 @@ test_expect_success 'file:// --negotiate-only with protocol v0' '
728728
test_i18ngrep "negotiate-only requires protocol v2" err
729729
'
730730

731+
test_expect_success 'push with custom path does not request v2' '
732+
rm -f env.trace &&
733+
git -C client push \
734+
--receive-pack="env >../env.trace; git-receive-pack" \
735+
origin HEAD:refs/heads/custom-push-test &&
736+
test_path_is_file env.trace &&
737+
! grep ^GIT_PROTOCOL env.trace
738+
'
739+
740+
test_expect_success 'fetch with custom path does request v2' '
741+
rm -f env.trace &&
742+
git -C client fetch \
743+
--upload-pack="env >../env.trace; git-upload-pack" \
744+
origin HEAD &&
745+
grep ^GIT_PROTOCOL=version=2 env.trace
746+
'
747+
748+
test_expect_success 'archive with custom path does not request v2' '
749+
rm -f env.trace &&
750+
git -C client archive \
751+
--exec="env >../env.trace; git-upload-archive" \
752+
--remote=origin \
753+
HEAD >/dev/null &&
754+
test_path_is_file env.trace &&
755+
! grep ^GIT_PROTOCOL env.trace
756+
'
757+
731758
# Test protocol v2 with 'http://' transport
732759
#
733760
. "$TEST_DIRECTORY"/lib-httpd.sh

transport.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,12 @@ static int connect_setup(struct transport *transport, int for_push)
279279
}
280280

281281
data->conn = git_connect(data->fd, transport->url,
282-
for_push ? data->options.receivepack :
283-
data->options.uploadpack,
282+
for_push ?
283+
"git-receive-pack" :
284+
"git-upload-pack",
285+
for_push ?
286+
data->options.receivepack :
287+
data->options.uploadpack,
284288
flags);
285289

286290
return 0;
@@ -914,7 +918,7 @@ static int connect_git(struct transport *transport, const char *name,
914918
{
915919
struct git_transport_data *data = transport->data;
916920
data->conn = git_connect(data->fd, transport->url,
917-
executable, 0);
921+
name, executable, 0);
918922
fd[0] = data->fd[0];
919923
fd[1] = data->fd[1];
920924
return 0;

0 commit comments

Comments
 (0)