Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--remote-curl.c23
-rwxr-xr-xt/t5550-http-fetch-dumb.sh18
2 files changed, 39 insertions, 2 deletions
diff --git a/remote-curl.c b/remote-curl.c
index 3ed0dfec1b..774a1ca71f 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -252,6 +252,19 @@ static struct ref *parse_git_refs(struct discovery *heads, int for_push)
return list;
}
+static const struct git_hash_algo *detect_hash_algo(struct discovery *heads)
+{
+ const char *p = memchr(heads->buf, '\t', heads->len);
+ int algo;
+ if (!p)
+ return the_hash_algo;
+
+ algo = hash_algo_by_length((p - heads->buf) / 2);
+ if (algo == GIT_HASH_UNKNOWN)
+ return NULL;
+ return &hash_algos[algo];
+}
+
static struct ref *parse_info_refs(struct discovery *heads)
{
char *data, *start, *mid;
@@ -262,6 +275,12 @@ static struct ref *parse_info_refs(struct discovery *heads)
struct ref *ref = NULL;
struct ref *last_ref = NULL;
+ options.hash_algo = detect_hash_algo(heads);
+ if (!options.hash_algo)
+ die("%sinfo/refs not valid: could not determine hash algorithm; "
+ "is this a git repository?",
+ transport_anonymize_url(url.buf));
+
data = heads->buf;
start = NULL;
mid = data;
@@ -272,13 +291,13 @@ static struct ref *parse_info_refs(struct discovery *heads)
if (data[i] == '\t')
mid = &data[i];
if (data[i] == '\n') {
- if (mid - start != the_hash_algo->hexsz)
+ if (mid - start != options.hash_algo->hexsz)
die(_("%sinfo/refs not valid: is this a git repository?"),
transport_anonymize_url(url.buf));
data[i] = 0;
ref_name = mid + 1;
ref = alloc_ref(ref_name);
- get_oid_hex(start, &ref->old_oid);
+ get_oid_hex_algop(start, &ref->old_oid, options.hash_algo);
if (!refs)
refs = ref;
if (last_ref)
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index 50485300eb..e57716bacd 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -50,6 +50,24 @@ test_expect_success 'create password-protected repository' '
"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
'
+test_expect_success 'create empty remote repository' '
+ git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" &&
+ (cd "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" &&
+ mkdir -p hooks &&
+ write_script "hooks/post-update" <<-\EOF &&
+ exec git update-server-info
+ EOF
+ hooks/post-update
+ )
+'
+
+test_expect_success 'empty dumb HTTP repository has default hash algorithm' '
+ test_when_finished "rm -fr clone-empty" &&
+ git clone $HTTPD_URL/dumb/empty.git clone-empty &&
+ git -C clone-empty rev-parse --show-object-format >empty-format &&
+ test "$(cat empty-format)" = "$(test_oid algo)"
+'
+
setup_askpass_helper
test_expect_success 'cloning password-protected repository can fail' '