Skip to content

Commit 9e5d2b4

Browse files
author
Junio C Hamano
committed
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>
1 parent 4607166 commit 9e5d2b4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fetch-pack.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,5 +458,19 @@ int main(int argc, char **argv)
458458
close(fd[0]);
459459
close(fd[1]);
460460
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+
461475
return ret;
462476
}

0 commit comments

Comments
 (0)