Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/cli/src/lib/wizard/apple/configure-sentry-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
});
}
30 changes: 30 additions & 0 deletions packages/cli/test/lib/wizard/apple/configure-sentry-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down
Loading