Skip to content

Commit 357179a

Browse files
fix: pr self-review cleanup
* remove duplicate merge migration note from README Known Limitations * preserve exception chain with `from exc` in generate_sql * handle missing git binary in file_exists_on_branch * add .env to .gitignore
1 parent 978307d commit 357179a

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ htmlcov/
2525
.vscode/
2626
.DS_Store
2727

28+
# Environment
29+
.env
30+
2831
# Python version
2932
.python-version

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Merge migrations (where `down_revision` is a tuple) are skipped since they produ
6464
* The hook runs `alembic upgrade --sql`, which executes your project's `env.py` in offline mode. No database connection is made, but the Python code in `env.py` does run.
6565
* If `DATABASE_URL` is not set, the hook provides a dummy fallback (`postgresql://localhost/lint`) so alembic's offline mode can generate SQL without a real connection string.
6666
* If `alembic upgrade --sql` fails for a migration (e.g. due to missing dependencies or env configuration), the hook prints the error to stderr and fails the run.
67-
* Merge migrations (where `down_revision` is a tuple) produce no DDL and are always skipped.
6867

6968
## Squawk Configuration
7069

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

squawk_alembic/hook.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ def generate_sql(filepath):
121121
text=True,
122122
env=env,
123123
)
124-
except FileNotFoundError:
124+
except FileNotFoundError as exc:
125125
raise GenerateSqlError(
126126
"squawk-alembic: alembic not found. Ensure alembic is installed in your environment."
127-
)
127+
) from exc
128128

129129
if result.returncode != 0:
130130
raise GenerateSqlError(
@@ -161,10 +161,13 @@ def validate_branch(branch):
161161

162162
def file_exists_on_branch(filepath, branch):
163163
"""Check if a file exists on the given git branch."""
164-
result = subprocess.run(
165-
["git", "cat-file", "-e", f"{branch}:{filepath}"],
166-
capture_output=True,
167-
)
164+
try:
165+
result = subprocess.run(
166+
["git", "cat-file", "-e", f"{branch}:{filepath}"],
167+
capture_output=True,
168+
)
169+
except FileNotFoundError:
170+
return False
168171
return result.returncode == 0
169172

170173

0 commit comments

Comments
 (0)