ref: d79e1f6b14c942800cb68fdcd489e4854b182164
parent: 1ab775887383bd20730254ef67b8d6c9dd9968a8
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Jul 17 00:44:00 EDT 2025
git/get: don't fetch all prefixes by default we should really only be fetching heads/ or tags/, and not other refs; in addition to being able to clobber local refs, on github anyone can open a pull request against a repo, and we probably don't want to grab those refs by default.
--- a/sys/src/cmd/git/get.c
+++ b/sys/src/cmd/git/get.c
@@ -135,13 +135,19 @@
}
int
+prefixed(char *s, char *pfx)
+{
+ return strncmp(s, pfx, strlen(pfx)) == 0;
+}
+
+int
branchmatch(char *br, char *pat)
{
char name[128];
- if(strstr(pat, "refs/heads") == pat)
+ if(prefixed(pat, "refs/heads"))
snprint(name, sizeof(name), "%s", pat);
- else if(strstr(pat, "heads"))
+ else if(prefixed(pat, "heads/"))
snprint(name, sizeof(name), "refs/%s", pat);
else
snprint(name, sizeof(name), "refs/heads/%s", pat);
@@ -264,6 +270,8 @@
if(!okrefname(sp[1]))
sysfatal("remote side sent invalid ref: %s", sp[1]);
if(fetchbranch && !branchmatch(sp[1], fetchbranch))
+ continue;
+ else if(!prefixed(sp[1], "refs/heads/") && !prefixed(sp[1], "refs/tags/"))
continue;
if(refsz == nref + 1){
refsz *= 2;
--
⑨