Merge branch 'jt/accept-capability-advertisement-when-fetching-from-void'
JGit can show a fake ref "capabilities^{}" to "git fetch" when it does not advertise any refs, but "git fetch" was not prepared to see such an advertisement. When the other side disconnects without giving any ref advertisement, we used to say "there may not be a repository at that URL", but we may have seen other advertisement like "shallow" and ".have" in which case we definitely know that a repository is there. The code to detect this case has also been updated. * jt/accept-capability-advertisement-when-fetching-from-void: connect: advertized capability is not a ref connect: tighten check for unexpected early hang up tests: move test_lazy_prereq JGIT to test-lib.sh
This commit is contained in:
commit
07d872434d
32
connect.c
32
connect.c
@ -43,9 +43,9 @@ int check_ref_type(const struct ref *ref, int flags)
|
||||
return check_ref(ref->name, flags);
|
||||
}
|
||||
|
||||
static void die_initial_contact(int got_at_least_one_head)
|
||||
static void die_initial_contact(int unexpected)
|
||||
{
|
||||
if (got_at_least_one_head)
|
||||
if (unexpected)
|
||||
die("The remote end hung up upon initial contact");
|
||||
else
|
||||
die("Could not read from remote repository.\n\n"
|
||||
@ -115,10 +115,18 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
|
||||
struct sha1_array *shallow_points)
|
||||
{
|
||||
struct ref **orig_list = list;
|
||||
int got_at_least_one_head = 0;
|
||||
|
||||
/*
|
||||
* A hang-up after seeing some response from the other end
|
||||
* means that it is unexpected, as we know the other end is
|
||||
* willing to talk to us. A hang-up before seeing any
|
||||
* response does not necessarily mean an ACL problem, though.
|
||||
*/
|
||||
int saw_response;
|
||||
int got_dummy_ref_with_capabilities_declaration = 0;
|
||||
|
||||
*list = NULL;
|
||||
for (;;) {
|
||||
for (saw_response = 0; ; saw_response = 1) {
|
||||
struct ref *ref;
|
||||
struct object_id old_oid;
|
||||
char *name;
|
||||
@ -131,7 +139,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
|
||||
PACKET_READ_GENTLE_ON_EOF |
|
||||
PACKET_READ_CHOMP_NEWLINE);
|
||||
if (len < 0)
|
||||
die_initial_contact(got_at_least_one_head);
|
||||
die_initial_contact(saw_response);
|
||||
|
||||
if (!len)
|
||||
break;
|
||||
@ -165,13 +173,25 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(name, "capabilities^{}")) {
|
||||
if (saw_response)
|
||||
die("protocol error: unexpected capabilities^{}");
|
||||
if (got_dummy_ref_with_capabilities_declaration)
|
||||
die("protocol error: multiple capabilities^{}");
|
||||
got_dummy_ref_with_capabilities_declaration = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!check_ref(name, flags))
|
||||
continue;
|
||||
|
||||
if (got_dummy_ref_with_capabilities_declaration)
|
||||
die("protocol error: unexpected ref after capabilities^{}");
|
||||
|
||||
ref = alloc_ref(buffer + GIT_SHA1_HEXSZ + 1);
|
||||
oidcpy(&ref->old_oid, &old_oid);
|
||||
*list = ref;
|
||||
list = &ref->next;
|
||||
got_at_least_one_head = 1;
|
||||
}
|
||||
|
||||
annotate_refs_with_symref_info(*orig_list);
|
||||
|
@ -158,10 +158,6 @@ test_expect_success 'pack with missing parent' '
|
||||
git pack-objects --stdout --revs <revs >/dev/null
|
||||
'
|
||||
|
||||
test_lazy_prereq JGIT '
|
||||
type jgit
|
||||
'
|
||||
|
||||
test_expect_success JGIT 'we can read jgit bitmaps' '
|
||||
git clone . compat-jgit &&
|
||||
(
|
||||
|
@ -207,5 +207,45 @@ test_expect_success 'ls-remote --symref omits filtered-out matches' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_lazy_prereq GIT_DAEMON '
|
||||
test_tristate GIT_TEST_GIT_DAEMON &&
|
||||
test "$GIT_TEST_GIT_DAEMON" != false
|
||||
'
|
||||
|
||||
# This test spawns a daemon, so run it only if the user would be OK with
|
||||
# testing with git-daemon.
|
||||
test_expect_success PIPE,JGIT,GIT_DAEMON 'indicate no refs in standards-compliant empty remote' '
|
||||
JGIT_DAEMON_PORT=${JGIT_DAEMON_PORT-${this_test#t}} &&
|
||||
JGIT_DAEMON_PID= &&
|
||||
git init --bare empty.git &&
|
||||
>empty.git/git-daemon-export-ok &&
|
||||
mkfifo jgit_daemon_output &&
|
||||
{
|
||||
jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
|
||||
JGIT_DAEMON_PID=$!
|
||||
} &&
|
||||
test_when_finished kill "$JGIT_DAEMON_PID" &&
|
||||
{
|
||||
read line &&
|
||||
case $line in
|
||||
Exporting*)
|
||||
;;
|
||||
*)
|
||||
echo "Expected: Exporting" &&
|
||||
false;;
|
||||
esac &&
|
||||
read line &&
|
||||
case $line in
|
||||
"Listening on"*)
|
||||
;;
|
||||
*)
|
||||
echo "Expected: Listening on" &&
|
||||
false;;
|
||||
esac
|
||||
} <jgit_daemon_output &&
|
||||
# --exit-code asks the command to exit with 2 when no
|
||||
# matching refs are found.
|
||||
test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
|
||||
'
|
||||
|
||||
test_done
|
||||
|
@ -1073,6 +1073,10 @@ test_lazy_prereq NOT_ROOT '
|
||||
test "$uid" != 0
|
||||
'
|
||||
|
||||
test_lazy_prereq JGIT '
|
||||
type jgit
|
||||
'
|
||||
|
||||
# SANITY is about "can you correctly predict what the filesystem would
|
||||
# do by only looking at the permission bits of the files and
|
||||
# directories?" A typical example of !SANITY is running the test
|
||||
|
Loading…
Reference in New Issue
Block a user