Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 348c44e

Browse files
committed
Merge branch 'hv/remote-end-hung-up'
When we get disconnected while expecting a response from the remote side because authentication failed, we issued an error message "The remote side hung up unexpectedly." Give hint that it may be a permission problem in the message when we can reasonably suspect it. * hv/remote-end-hung-up: remove the impression of unexpectedness when access is denied
2 parents b129051 + 46284dd commit 348c44e

File tree

4 files changed

+51
-16
lines changed

4 files changed

+51
-16
lines changed

connect.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,25 @@ static void add_extra_have(struct extra_have_objects *extra, unsigned char *sha1
4949
extra->nr++;
5050
}
5151

52+
static void die_initial_contact(int got_at_least_one_head)
53+
{
54+
if (got_at_least_one_head)
55+
die("The remote end hung up upon initial contact");
56+
else
57+
die("Could not read from remote repository.\n\n"
58+
"Please make sure you have the correct access rights\n"
59+
"and the repository exists.");
60+
}
61+
5262
/*
5363
* Read all the refs from the other end
5464
*/
5565
struct ref **get_remote_heads(int in, struct ref **list,
5666
unsigned int flags,
5767
struct extra_have_objects *extra_have)
5868
{
69+
int got_at_least_one_head = 0;
70+
5971
*list = NULL;
6072
for (;;) {
6173
struct ref *ref;
@@ -64,7 +76,10 @@ struct ref **get_remote_heads(int in, struct ref **list,
6476
char *name;
6577
int len, name_len;
6678

67-
len = packet_read_line(in, buffer, sizeof(buffer));
79+
len = packet_read(in, buffer, sizeof(buffer));
80+
if (len < 0)
81+
die_initial_contact(got_at_least_one_head);
82+
6883
if (!len)
6984
break;
7085
if (buffer[len-1] == '\n')
@@ -95,6 +110,7 @@ struct ref **get_remote_heads(int in, struct ref **list,
95110
hashcpy(ref->old_sha1, old_sha1);
96111
*list = ref;
97112
list = &ref->next;
113+
got_at_least_one_head = 1;
98114
}
99115
return list;
100116
}

pkt-line.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,19 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
135135
strbuf_add(buf, buffer, n);
136136
}
137137

138-
static void safe_read(int fd, void *buffer, unsigned size)
138+
static int safe_read(int fd, void *buffer, unsigned size, int return_line_fail)
139139
{
140140
ssize_t ret = read_in_full(fd, buffer, size);
141141
if (ret < 0)
142142
die_errno("read error");
143-
else if (ret < size)
143+
else if (ret < size) {
144+
if (return_line_fail)
145+
return -1;
146+
144147
die("The remote end hung up unexpectedly");
148+
}
149+
150+
return ret;
145151
}
146152

147153
static int packet_length(const char *linelen)
@@ -169,12 +175,14 @@ static int packet_length(const char *linelen)
169175
return len;
170176
}
171177

172-
int packet_read_line(int fd, char *buffer, unsigned size)
178+
static int packet_read_internal(int fd, char *buffer, unsigned size, int return_line_fail)
173179
{
174-
int len;
180+
int len, ret;
175181
char linelen[4];
176182

177-
safe_read(fd, linelen, 4);
183+
ret = safe_read(fd, linelen, 4, return_line_fail);
184+
if (return_line_fail && ret < 0)
185+
return ret;
178186
len = packet_length(linelen);
179187
if (len < 0)
180188
die("protocol error: bad line length character: %.4s", linelen);
@@ -185,12 +193,24 @@ int packet_read_line(int fd, char *buffer, unsigned size)
185193
len -= 4;
186194
if (len >= size)
187195
die("protocol error: bad line length %d", len);
188-
safe_read(fd, buffer, len);
196+
ret = safe_read(fd, buffer, len, return_line_fail);
197+
if (return_line_fail && ret < 0)
198+
return ret;
189199
buffer[len] = 0;
190200
packet_trace(buffer, len, 0);
191201
return len;
192202
}
193203

204+
int packet_read(int fd, char *buffer, unsigned size)
205+
{
206+
return packet_read_internal(fd, buffer, size, 1);
207+
}
208+
209+
int packet_read_line(int fd, char *buffer, unsigned size)
210+
{
211+
return packet_read_internal(fd, buffer, size, 0);
212+
}
213+
194214
int packet_get_line(struct strbuf *out,
195215
char **src_buf, size_t *src_len)
196216
{

pkt-line.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void packet_buf_flush(struct strbuf *buf);
1313
void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
1414

1515
int packet_read_line(int fd, char *buffer, unsigned size);
16+
int packet_read(int fd, char *buffer, unsigned size);
1617
int packet_get_line(struct strbuf *out, char **src_buf, size_t *src_len);
1718
ssize_t safe_write(int, const void *, ssize_t);
1819

t/t5512-ls-remote.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,15 @@ test_expect_success 'use branch.<name>.remote if possible' '
8787
test_expect_success 'confuses pattern as remote when no remote specified' '
8888
cat >exp <<-\EOF &&
8989
fatal: '\''refs*master'\'' does not appear to be a git repository
90-
fatal: The remote end hung up unexpectedly
90+
fatal: Could not read from remote repository.
91+
92+
Please make sure you have the correct access rights
93+
and the repository exists.
9194
EOF
9295
#
93-
# Do not expect "git ls-remote <pattern>" to work; ls-remote, correctly,
94-
# confuses <pattern> for <remote>. Although ugly, this behaviour is akin
95-
# to the confusion of refspecs for remotes by git-fetch and git-push,
96-
# eg:
97-
#
98-
# $ git fetch branch
99-
#
100-
96+
# Do not expect "git ls-remote <pattern>" to work; ls-remote needs
97+
# <remote> if you want to feed <pattern>, just like you cannot say
98+
# fetch <branch>.
10199
# We could just as easily have used "master"; the "*" emphasizes its
102100
# role as a pattern.
103101
test_must_fail git ls-remote refs*master >actual 2>&1 &&

0 commit comments

Comments
 (0)