Commits

Anonymous committed 3057ded

http-push and http-fetch: handle URLs without trailing /

The URL to a repository http-push and http-fetch takes should
have a trailing slash. Instead of failing the request, add it
ourselves before attempting such a request.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Comments (0)

Files changed (2)

builtin-http-fetch.c

 	const char **write_ref = NULL;
 	char **commit_id;
 	const char *url;
+	char *rewritten_url = NULL;
 	int arg = 1;
 	int rc = 0;
 	int get_tree = 0;
 		commits = 1;
 	}
 	url = argv[arg];
+	if (url && url[strlen(url)-1] != '/') {
+		rewritten_url = malloc(strlen(url)+2);
+		strcpy(rewritten_url, url);
+		strcat(rewritten_url, "/");
+		url = rewritten_url;
+	}
 
 	walker = get_http_walker(url);
 	walker->get_tree = get_tree;
 
 	walker_free(walker);
 
+	if (rewritten_url)
+		free(rewritten_url);
+
 	return rc;
 }
 	int i;
 	int new_refs;
 	struct ref *ref;
+	char *rewritten_url = NULL;
 
 	setup_git_directory();
 
 
 	no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
 
+	if (remote->url && remote->url[strlen(remote->url)-1] != '/') {
+		rewritten_url = malloc(strlen(remote->url)+2);
+		strcpy(rewritten_url, remote->url);
+		strcat(rewritten_url, "/");
+		remote->url = rewritten_url;
+		++remote->path_len;
+	}
+
 	/* Verify DAV compliance/lock support */
 	if (!locking_available()) {
 		rc = 1;
 	}
 
  cleanup:
+	if (rewritten_url)
+		free(rewritten_url);
 	if (info_ref_lock)
 		unlock_remote(info_ref_lock);
 	free(remote);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.