git-fetch: fail if specified refspec does not match remote.
'git-fetch remote no-such-ref' succeeded without fetching any ref from the remote. Detect such case and report an error. Note that this makes 'git-fetch remote master master' to fail, because the remote branch 'master' matches the first refspec, and the second refspec is left unmatched, which is detected by the error checking logic. This is somewhat unintuitive, but giving the same refspec more than once to git-fetch is useless in any case so it should not be much of a problem. I'd accept a patch to change this if somebody cares enough, though. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 6, 2005 at 00:09 UTC
9e5d2b40967059dd5f35d02fba323751ef22ac4e
1 file changed
+14
fetch-pack.c
+14
@@ -458,5 +458,19 @@ int main(int argc, char **argv)
458
close(fd[0]);
459
close(fd[1]);
460
finish_connect(pid);
461
+
462
+ if (!ret && nr_heads) {
463
+ /* If the heads to pull were given, we should have
464
+ * consumed all of them by matching the remote.
465
+ * Otherwise, 'git-fetch remote no-such-ref' would
466
+ * silently succeed without issuing an error.
467
+ */
468
+ for (i = 0; i < nr_heads; i++)
469
+ if (heads[i] && heads[i][0]) {
470
+ error("no such remote ref %s", heads[i]);
471
+ ret = 1;
472
+ }
473
+ }
474
+
475
return ret;
476
}