Skip to content

Commit

Permalink
git-fetch: fail if specified refspec does not match remote.
Browse files Browse the repository at this point in the history
'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>
  • Loading branch information
Junio C Hamano committed Nov 6, 2005
1 parent 4607166 commit 9e5d2b4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,19 @@ int main(int argc, char **argv)
close(fd[0]);
close(fd[1]);
finish_connect(pid);

if (!ret && nr_heads) {
/* If the heads to pull were given, we should have
* consumed all of them by matching the remote.
* Otherwise, 'git-fetch remote no-such-ref' would
* silently succeed without issuing an error.
*/
for (i = 0; i < nr_heads; i++)
if (heads[i] && heads[i][0]) {
error("no such remote ref %s", heads[i]);
ret = 1;
}
}

return ret;
}

0 comments on commit 9e5d2b4

Please sign in to comment.