mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-15 14:38:03 +02:00
f0f6436370
Files tracked by Git LFS used to come out as the pointer text:
version https://git-lfs.github.com/spec/v1
oid sha256:...
size ...
…because GitHub's blob API returns the pointer, not the resolved
content. Detect that prefix on the first ~150 bytes of the blob stream
and switch to a fresh fetch via the web raw URL
(github.com/<owner>/<repo>/raw/<commit>/<path>), which auto-redirects
to media.githubusercontent.com and resolves the LFS object — auth
header carries through. Non-LFS files are forwarded through the
existing pipeline unchanged.
Fixes #95.
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
const { expect } = require("chai");
|
|
const { Readable } = require("stream");
|
|
|
|
// Standalone test of the LFS-pointer detection shape used in
|
|
// GitHubStream#resolveLfsPointer. We can't easily import that method (it's
|
|
// private and the file pulls in heavy GitHub plumbing), so this mirrors the
|
|
// detection logic to confirm the head-bytes check.
|
|
|
|
const LFS_PREFIX = "version https://git-lfs.github.com/spec/";
|
|
|
|
function isLfsPointer(buf) {
|
|
return (
|
|
buf.length >= LFS_PREFIX.length &&
|
|
buf.toString("utf8", 0, LFS_PREFIX.length) === LFS_PREFIX
|
|
);
|
|
}
|
|
|
|
describe("LFS pointer detection (#95)", function () {
|
|
it("recognizes the standard pointer prefix", function () {
|
|
const pointer = Buffer.from(
|
|
"version https://git-lfs.github.com/spec/v1\n" +
|
|
"oid sha256:abc123\nsize 12345\n"
|
|
);
|
|
expect(isLfsPointer(pointer)).to.equal(true);
|
|
});
|
|
|
|
it("doesn't false-positive on plain text starting with 'version'", function () {
|
|
const fake = Buffer.from(
|
|
"version 1.2.3\nA short release notes file mentioning git-lfs.\n"
|
|
);
|
|
expect(isLfsPointer(fake)).to.equal(false);
|
|
});
|
|
|
|
it("doesn't false-positive on binary headers", function () {
|
|
const elf = Buffer.from([0x7f, 0x45, 0x4c, 0x46, ...new Array(100).fill(0)]);
|
|
expect(isLfsPointer(elf)).to.equal(false);
|
|
});
|
|
|
|
it("handles short streams below the prefix length", function () {
|
|
expect(isLfsPointer(Buffer.from("vers"))).to.equal(false);
|
|
});
|
|
});
|