Skip to content

Commit c853fcc

Browse files
committed
Modify regex
1 parent f9efc5e commit c853fcc

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/cli/lib/deployment.test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,23 @@ test("git ignore changes", () => {
5656
expect(changesToGitIgnore(null)).toEqual(".env.local\n");
5757
expect(changesToGitIgnore("")).toEqual("\n.env.local\n");
5858
expect(changesToGitIgnore(".env")).toEqual(".env\n.env.local\n");
59+
expect(changesToGitIgnore("# .env.local")).toEqual(
60+
"# .env.local\n.env.local\n",
61+
);
5962

6063
// Handle existing
6164
expect(changesToGitIgnore(".env.local")).toEqual(null);
6265
expect(changesToGitIgnore(".env.*")).toEqual(null);
6366
expect(changesToGitIgnore(".env*")).toEqual(null);
64-
65-
// Handle inline comments
66-
expect(changesToGitIgnore(".env.local # convex env")).toEqual(null);
67+
expect(changesToGitIgnore(".env*.local")).toEqual(null);
68+
expect(changesToGitIgnore("*.local")).toEqual(null);
69+
expect(changesToGitIgnore("# convex env\n.env.local")).toEqual(null);
6770

6871
// Handle Windows
6972
expect(changesToGitIgnore(".env.local\r")).toEqual(null);
7073

7174
// Handle whitespace
72-
expect(changesToGitIgnore(".env.local ")).toEqual(null);
75+
expect(changesToGitIgnore(" .env.local ")).toEqual(null);
7376

7477
// Add .env.local (even if it's negated) to guide the user to solve the problem
7578
expect(changesToGitIgnore("!.env.local")).toEqual(

src/cli/lib/deployment.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,18 @@ export function changesToGitIgnore(existingFile: string | null): string | null {
147147
}
148148
const gitIgnoreLines = existingFile.split("\n");
149149
const envVarFileIgnored = gitIgnoreLines.some((line) => {
150-
// Remove any inline comments
151-
const trimmedLine = line.split("#")[0].trim();
150+
// Remove extra whitespace
151+
const trimmedLine = line.trim();
152152

153-
// Ignore negated patterns
154-
if (trimmedLine.startsWith("!")) return false;
153+
// Ignore negated patterns and comments
154+
if (trimmedLine.startsWith("!") || trimmedLine.startsWith("#"))
155+
return false;
155156

156157
const envIgnorePatterns = [
157-
/^\.env\.local$/,
158-
/^\.env\.\*$/,
159-
/^\.env\*$/,
160-
/^.*\.local$/,
161-
/^\.env\*\.local$/,
158+
// .env.local, .env.*, .env*
159+
/^\.env(\.local|\.\*|\*)$/,
160+
// .env*.local, *.local
161+
/^(\.env)?\*\.local$/,
162162
];
163163

164164
return envIgnorePatterns.some((pattern) => pattern.test(trimmedLine));

0 commit comments

Comments
 (0)