Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Require approval for Git attributes and preserve filenames

Manav Rathi96c268763f00
diff --git a/.github/scripts/change-approval.mjs b/.github/scripts/change-approval.mjs
index cb878696d9..b09e6d4b36 100644
--- a/.github/scripts/change-approval.mjs
+++ b/.github/scripts/change-approval.mjs
@@ -20,7 +20,7 @@ const guardrailFiles = new Set([
"analysis_options.yaml",
]);
const configFile =
- /(^|\/)(rust-toolchain\.toml|\.cargo\/(config|audit)\.toml|\.npmrc|\.nvmrc|\.tool-versions|\.node-version|\.python-version|gradle-wrapper\.properties)$/;
+ /(^|\/)(\.gitattributes|rust-toolchain\.toml|\.cargo\/(config|audit)\.toml|\.npmrc|\.nvmrc|\.tool-versions|\.node-version|\.python-version|gradle-wrapper\.properties)$/;
const tomlPackages = (text) =>
text
@@ -101,7 +101,7 @@ const numstat = (...filter) =>
git("diff", "--numstat", "--no-renames", "-z", ...filter, mergeBase, ...(local ? [] : ["HEAD"]))
.split("\0")
.filter(Boolean)
- .map((row) => row.split("\t"));
+ .map((row) => row.match(/^([^\t]+)\t([^\t]+)\t(.*)$/s).slice(1));
const untracked = local
? git("ls-files", "--others", "--exclude-standard", "-z")
.split("\0")
@@ -114,7 +114,7 @@ const kept = numstat("--diff-filter=a").map(([, , file]) => file);
const treeSizes = () =>
git("--literal-pathspecs", "ls-tree", "-l", "-z", "HEAD", "--", ...present.map(([, , file]) => file))
.split("\0")
- .map((line) => line.match(/ blob \S+ +(\d+)\t(.*)$/))
+ .map((line) => line.match(/ blob \S+ +(\d+)\t(.*)$/s))
.filter(Boolean)
.map(([, size, file]) => [file, Number(size)]);
const diskSizes = () =>
diff --git a/.github/scripts/change-approval.test.mjs b/.github/scripts/change-approval.test.mjs
index 7a9fdef298..acf7a08246 100644
--- a/.github/scripts/change-approval.test.mjs
+++ b/.github/scripts/change-approval.test.mjs
@@ -108,6 +108,15 @@ test("binary deleted is ignored", (t) => {
assert.equal(scan(t, { "a.bin": Buffer.alloc(16) }, { "a.bin": null }), "");
});
+test("CI preserves tabs and newlines in binary and large filenames", (t) => {
+ const binary = "image.png\tpayload.jar";
+ const large = "large\nfile.txt";
+ const size = 1024 * 1024 + 1;
+ const { output, summary } = scan(t, {}, { [binary]: Buffer.alloc(16), [large]: "a".repeat(size) }, { ci: true });
+ assert.equal(output, 'categories=["binary files","large files"]\n');
+ assert.equal(summary, `## Binary files\n\n- \`${binary}\` (16 bytes)\n\n## Large files\n\n- \`${large}\` (${size} bytes)\n`);
+});
+
test("routine image, font, and xcassets binaries are ignored", (t) => {
const output = scan(t, {}, {
"src/logo.PNG": Buffer.alloc(16),
@@ -357,6 +366,23 @@ test("new root .cargo/config.toml is a config file, even untracked", (t) => {
assert.equal(scan(t, { "a.txt": "a\n" }, { ".cargo/config.toml": "[registries]\n" }, { commit: false }), expected);
});
+test("Git attributes require config approval even when they hide binary changes", (t) => {
+ const { output, summary } = scan(
+ t,
+ { "modified/.gitattributes": "", "deleted/.gitattributes": "", "a.jar": Buffer.alloc(16) },
+ {
+ ".gitattributes": "*.jar diff\n",
+ "added/.gitattributes": "*.jar diff\n",
+ "modified/.gitattributes": "*.jar diff\n",
+ "deleted/.gitattributes": null,
+ "a.jar": Buffer.alloc(32),
+ },
+ { ci: true },
+ );
+ assert.equal(output, 'categories=["config files"]\n');
+ assert.equal(summary, "## Toolchain and registry config\n\n- `.gitattributes`\n- `added/.gitattributes`\n- `deleted/.gitattributes`\n- `modified/.gitattributes`\n");
+});
+
test("uncommitted and untracked changes are scanned locally", (t) => {
const output = scan(
t,