From a4dc2ebeb271066192ce4514e7fb0a6de32ffecf Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 22:41:28 +0000 Subject: [PATCH] fix(cli): only treat an exact .sentryclirc line as gitignored The Apple wizard skipped adding .sentryclirc to an existing .gitignore whenever the file mentioned the name anywhere, such as in a comment. Only count an uncommented .sentryclirc or /.sentryclirc line. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> --- .../lib/wizard/apple/configure-sentry-cli.ts | 14 ++++++++- .../wizard/apple/configure-sentry-cli.test.ts | 30 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/lib/wizard/apple/configure-sentry-cli.ts b/packages/cli/src/lib/wizard/apple/configure-sentry-cli.ts index 5e5488e7a..fd9e567d6 100644 --- a/packages/cli/src/lib/wizard/apple/configure-sentry-cli.ts +++ b/packages/cli/src/lib/wizard/apple/configure-sentry-cli.ts @@ -76,7 +76,7 @@ function createSentryCLIRC( writeFileSync(gitignorePath, ".sentryclirc"); } else { const gitIgnore = readFileSync(gitignorePath).toString(); - if (!gitIgnore.includes(".sentryclirc")) { + if (!ignoresSentryCliRc(gitIgnore)) { clack.log.info( `Appending .sentryclirc to .gitignore file at path: ${chalk.cyan( gitignorePath, @@ -86,3 +86,15 @@ function createSentryCLIRC( } } } + +/** + * Whether `.gitignore` already has a line that ignores `.sentryclirc`. Only an + * exact `.sentryclirc` or `/.sentryclirc` line counts, so a comment or another + * pattern that mentions the name does not. + */ +function ignoresSentryCliRc(gitIgnore: string): boolean { + return gitIgnore.split(/\r?\n/).some((line) => { + const pattern = line.trim(); + return pattern === ".sentryclirc" || pattern === "/.sentryclirc"; + }); +} diff --git a/packages/cli/test/lib/wizard/apple/configure-sentry-cli.test.ts b/packages/cli/test/lib/wizard/apple/configure-sentry-cli.test.ts index 4270d9755..6964c5f13 100644 --- a/packages/cli/test/lib/wizard/apple/configure-sentry-cli.test.ts +++ b/packages/cli/test/lib/wizard/apple/configure-sentry-cli.test.ts @@ -119,6 +119,36 @@ xcuserdata/ }); }); + describe("only mentions '.sentryclirc' in a comment", () => { + it("should append the .sentryclirc file to the .gitignore file", () => { + // -- Arrange -- + fs.writeFileSync(gitignorePath, "# .sentryclirc\nxcuserdata/\n"); + + // -- Act -- + configureSentryCLI({ projectDir, authToken, orgSlug, projectSlug }); + + // -- Assert -- + expect(fs.readFileSync(gitignorePath, "utf8")).toBe( + "# .sentryclirc\nxcuserdata/\n\n.sentryclirc\n", + ); + }); + }); + + describe("contains '/.sentryclirc'", () => { + it("should not append the .sentryclirc file to the .gitignore file", () => { + // -- Arrange -- + fs.writeFileSync(gitignorePath, "xcuserdata/\n/.sentryclirc\n"); + + // -- Act -- + configureSentryCLI({ projectDir, authToken, orgSlug, projectSlug }); + + // -- Assert -- + expect(fs.readFileSync(gitignorePath, "utf8")).toBe( + "xcuserdata/\n/.sentryclirc\n", + ); + }); + }); + describe("does not contain '.sentryclirc'", () => { it("should append the .sentryclirc file to the .gitignore file", () => { // -- Arrange --