Skip to content

Commit 3cc9caa

Browse files
committed
Merge branch 'rc/maint-curl-helper'
* rc/maint-curl-helper: remote-curl: ensure that URLs have a trailing slash http: make end_url_with_slash() public t5541-http-push: add test for URLs with trailing slash Conflicts: remote-curl.c
2 parents b7d0da8 + d8fab07 commit 3cc9caa

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ static inline int hex(int v)
720720
return 'A' + v - 10;
721721
}
722722

723-
static void end_url_with_slash(struct strbuf *buf, const char *url)
723+
void end_url_with_slash(struct strbuf *buf, const char *url)
724724
{
725725
strbuf_addstr(buf, url);
726726
if (buf->len && buf->buf[buf->len - 1] != '/')

http.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ extern void append_remote_object_url(struct strbuf *buf, const char *url,
117117
int only_two_digit_prefix);
118118
extern char *get_remote_object_url(const char *url, const char *hex,
119119
int only_two_digit_prefix);
120+
extern void end_url_with_slash(struct strbuf *buf, const char *url);
120121

121122
/* Options for http_request_*() */
122123
#define HTTP_NO_CACHE 1

remote-curl.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "sideband.h"
1010

1111
static struct remote *remote;
12-
static const char *url;
12+
static const char *url; /* always ends with a trailing slash */
1313

1414
struct options {
1515
int verbosity;
@@ -101,7 +101,7 @@ static struct discovery* discover_refs(const char *service)
101101
return last;
102102
free_discovery(last);
103103

104-
strbuf_addf(&buffer, "%s/info/refs", url);
104+
strbuf_addf(&buffer, "%sinfo/refs", url);
105105
if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) {
106106
is_http = 1;
107107
if (!strchr(url, '?'))
@@ -120,7 +120,7 @@ static struct discovery* discover_refs(const char *service)
120120
strbuf_reset(&buffer);
121121

122122
proto_git_candidate = 0;
123-
strbuf_addf(&buffer, "%s/info/refs", url);
123+
strbuf_addf(&buffer, "%sinfo/refs", url);
124124
refs_url = strbuf_detach(&buffer, NULL);
125125

126126
http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
@@ -511,7 +511,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
511511
rpc->out = client.out;
512512
strbuf_init(&rpc->result, 0);
513513

514-
strbuf_addf(&buf, "%s/%s", url, svc);
514+
strbuf_addf(&buf, "%s%s", url, svc);
515515
rpc->service_url = strbuf_detach(&buf, NULL);
516516

517517
strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
@@ -800,11 +800,13 @@ int main(int argc, const char **argv)
800800
remote = remote_get(argv[1]);
801801

802802
if (argc > 2) {
803-
url = argv[2];
803+
end_url_with_slash(&buf, argv[2]);
804804
} else {
805-
url = remote->url[0];
805+
end_url_with_slash(&buf, remote->url[0]);
806806
}
807807

808+
url = strbuf_detach(&buf, NULL);
809+
808810
http_init(remote);
809811

810812
do {

t/t5541-http-push.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,34 @@ test_expect_success 'setup remote repository' '
3434
mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
3535
'
3636

37-
test_expect_success 'clone remote repository' '
37+
cat >exp <<EOF
38+
GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
39+
POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
40+
EOF
41+
test_expect_success 'no empty path components' '
42+
# In the URL, add a trailing slash, and see if git appends yet another
43+
# slash.
3844
cd "$ROOT_PATH" &&
45+
git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
46+
47+
sed -e "
48+
s/^.* \"//
49+
s/\"//
50+
s/ [1-9][0-9]*\$//
51+
s/^GET /GET /
52+
" >act <"$HTTPD_ROOT_PATH"/access.log &&
53+
54+
# Clear the log, so that it does not affect the "used receive-pack
55+
# service" test which reads the log too.
56+
#
57+
# We do this before the actual comparison to ensure the log is cleared.
58+
echo > "$HTTPD_ROOT_PATH"/access.log &&
59+
60+
test_cmp exp act
61+
'
62+
63+
test_expect_success 'clone remote repository' '
64+
rm -rf test_repo_clone &&
3965
git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
4066
'
4167

@@ -68,6 +94,7 @@ test_expect_success 'create and delete remote branch' '
6894
'
6995

7096
cat >exp <<EOF
97+
7198
GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
7299
POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
73100
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200

0 commit comments

Comments
 (0)