146
for_each_ref(one_local_ref, NULL);
147
}
148
149
-static int receive_status(int in)
149
+static struct ref *set_ref_error(struct ref *refs, const char *line)
150
{
151
+ struct ref *ref;
152
+
153
+ for (ref = refs; ref; ref = ref->next) {
154
+ const char *msg;
155
+ if (prefixcmp(line, ref->name))
156
+ continue;
157
+ msg = line + strlen(ref->name);
158
+ if (*msg++ != ' ')
159
+ continue;
160
+ ref->status = REF_STATUS_REMOTE_REJECT;
161
+ ref->error = xstrdup(msg);
162
+ ref->error[strlen(ref->error)-1] = '\0';
163
+ return ref;
164
+ }
165
+ return NULL;
166
+}
167
+
168
+/* a return value of -1 indicates that an error occurred,
169
+ * but we were able to set individual ref errors. A return
170
+ * value of -2 means we couldn't even get that far. */
171
+static int receive_status(int in, struct ref *refs)
172
+{
173
+ struct ref *hint;
174
char line[1000];
175
int ret = 0;
176
int len = packet_read_line(in, line, sizeof(line));
177
if (len < 10 || memcmp(line, "unpack ", 7)) {
178
fprintf(stderr, "did not receive status back\n");
156
- return -1;
179
+ return -2;
180
}
181
if (memcmp(line, "unpack ok\n", 10)) {
182
fputs(line, stderr);
183
ret = -1;
184
}
185
+ hint = NULL;
186
while (1) {
187
len = packet_read_line(in, line, sizeof(line));
188
if (!len)
195
}
196
if (!memcmp(line, "ok", 2))
197
continue;
174
- fputs(line, stderr);
198
+ if (hint)
199
+ hint = set_ref_error(hint, line + 3);
200
+ if (!hint)
201
+ hint = set_ref_error(refs, line + 3);
202
ret = -1;
203
}
204
return ret;
323
print_ref_status('!', "[rejected]", ref, ref->peer_ref,
324
"non-fast forward");
325
break;
326
+ case REF_STATUS_REMOTE_REJECT:
327
+ if (ref->deletion)
328
+ print_ref_status('!', "[remote rejected]", ref, NULL, ref->error);
329
+ else
330
+ print_ref_status('!', "[remote rejected]", ref, ref->peer_ref, ref->error);
331
+ break;
332
case REF_STATUS_OK:
333
print_ok_ref_status(ref);
334
break;
344
int allow_deleting_refs = 0;
345
int expect_status_report = 0;
346
int flags = MATCH_REFS_NONE;
347
+ int ret;
348
349
if (args.send_all)
350
flags |= MATCH_REFS_ALL;
462
}
463
close(out);
464
431
- print_push_status(dest, remote_refs);
432
-
465
if (expect_status_report) {
434
- if (receive_status(in))
466
+ ret = receive_status(in, remote_refs);
467
+ if (ret == -2)
468
return -1;
469
}
470
+ else
471
+ ret = 0;
472
+
473
+ print_push_status(dest, remote_refs);
474
475
if (!args.dry_run && remote) {
476
for (ref = remote_refs; ref; ref = ref->next)
479
480
if (!new_refs)
481
fprintf(stderr, "Everything up-to-date\n");
482
+ if (ret < 0)
483
+ return ret;
484
for (ref = remote_refs; ref; ref = ref->next) {
485
switch (ref->status) {
486
case REF_STATUS_NONE: