Skip to content

Commit 466ddf9

Browse files
dschogitster
authored andcommitted
http-push: when making directories, have a trailing slash in the path name
The function lock_remote() sends MKCOL requests to make leading directories; However, if it does not put a forward slash '/' at the end of the path, the server sends a 301 redirect. By leaving the '/' in place, we can avoid this additional step. Incidentally, at least one version of Curl (7.16.3) does not resend credentials when it follows a 301 redirect, so this commit also fixes a bug. Original patch by Tay Ray Chuan <rctay89@gmail.com>. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2064280 commit 466ddf9

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

http-push.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
12011201
/* Make sure leading directories exist for the remote ref */
12021202
ep = strchr(url + strlen(remote->url) + 1, '/');
12031203
while (ep) {
1204-
*ep = 0;
1204+
char saved_character = ep[1];
1205+
ep[1] = '\0';
12051206
slot = get_active_slot();
12061207
slot->results = &results;
12071208
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
@@ -1223,7 +1224,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
12231224
free(url);
12241225
return NULL;
12251226
}
1226-
*ep = '/';
1227+
ep[1] = saved_character;
12271228
ep = strchr(ep + 1, '/');
12281229
}
12291230

t/lib-httpd/apache.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ServerName dummy
22
PidFile httpd.pid
33
DocumentRoot www
4+
LogFormat "%h %l %u %t \"%r\" %>s %b" common
5+
CustomLog access.log common
46
ErrorLog error.log
57

68
<IfDefine SSL>

t/t5540-http-push.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ test_expect_failure 'create and delete remote branch' '
7676
test_must_fail git show-ref --verify refs/remotes/origin/dev
7777
'
7878

79+
test_expect_success 'MKCOL sends directory names with trailing slashes' '
80+
81+
! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
82+
83+
'
84+
7985
stop_httpd
8086

8187
test_done

0 commit comments

Comments
 (0)