Skip to content

Commit

Permalink
http-push: when making directories, have a trailing slash in the path…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jan 18, 2009
1 parent 2064280 commit 466ddf9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions http-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
/* Make sure leading directories exist for the remote ref */
ep = strchr(url + strlen(remote->url) + 1, '/');
while (ep) {
*ep = 0;
char saved_character = ep[1];
ep[1] = '\0';
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
Expand All @@ -1223,7 +1224,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
free(url);
return NULL;
}
*ep = '/';
ep[1] = saved_character;
ep = strchr(ep + 1, '/');
}

Expand Down
2 changes: 2 additions & 0 deletions t/lib-httpd/apache.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ServerName dummy
PidFile httpd.pid
DocumentRoot www
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog access.log common
ErrorLog error.log

<IfDefine SSL>
Expand Down
6 changes: 6 additions & 0 deletions t/t5540-http-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ test_expect_failure 'create and delete remote branch' '
test_must_fail git show-ref --verify refs/remotes/origin/dev
'

test_expect_success 'MKCOL sends directory names with trailing slashes' '
! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
'

stop_httpd

test_done

0 comments on commit 466ddf9

Please sign in to comment.