-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ci: catch conflict markers and check desktop rust #8030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3372476
b96fbfe
be62451
254c2bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,25 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Universal source hygiene: fail fast on unresolved merge conflict markers. | ||
| STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM) | ||
|
|
||
| if [ -n "$STAGED_FILES" ]; then | ||
| conflict_found=0 | ||
| while IFS= read -r file; do | ||
| [ -n "$file" ] || continue | ||
| if git grep --cached -n -I -E '^(<<<<<<<|>>>>>>>)' -- "$file"; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This checks only the cached index before the hook's later formatter blocks mutate the index with Useful? React with 👍 / 👎. |
||
| conflict_found=1 | ||
| fi | ||
| done <<EOF | ||
| $STAGED_FILES | ||
| EOF | ||
|
|
||
| if [ "$conflict_found" -eq 1 ]; then | ||
| echo "Unresolved merge conflict markers found in staged files" >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| # Dart formatting for app/ | ||
| STAGED_DART_FILES=$(git diff --cached --name-only --diff-filter=ACM "app/**.dart" | grep -v -e '\.gen\.dart$' -e '\.g\.dart$') | ||
|
|
||
|
|
@@ -79,4 +99,34 @@ if [ -n "$STAGED_C_FILES" ]; then | |
| echo "$STAGED_C_FILES" | xargs git add | ||
| fi | ||
|
|
||
| # Rust formatting/checking for desktop backend. | ||
| STAGED_DESKTOP_RUST_INPUTS=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^desktop/macos/Backend-Rust/' || true) | ||
| STAGED_DESKTOP_RUST_FILES=$(printf '%s\n' "$STAGED_DESKTOP_RUST_INPUTS" | grep -E '\.rs$' || true) | ||
|
|
||
| if [ -n "$STAGED_DESKTOP_RUST_INPUTS" ]; then | ||
| echo "Checking desktop Rust backend..." | ||
| if ! command -v cargo >/dev/null 2>&1; then | ||
| echo "cargo is not installed. Please install Rust/Cargo first" >&2 | ||
| exit 1 | ||
| fi | ||
| if [ -n "$STAGED_DESKTOP_RUST_FILES" ]; then | ||
| while IFS= read -r file; do | ||
| [ -n "$file" ] || continue | ||
| if ! rustfmt --edition 2021 "$file"; then | ||
| echo "rustfmt failed for $file" >&2 | ||
| exit 1 | ||
| fi | ||
| git add "$file" | ||
| done <<EOF | ||
| $STAGED_DESKTOP_RUST_FILES | ||
| EOF | ||
| fi | ||
| if ! ( | ||
| cd desktop/macos/Backend-Rust && \ | ||
| cargo check --locked | ||
| ); then | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| exit 0 | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The CI rustfmt invocation is not path-safe:
xargssplits filenames on whitespace, so changed Rust files with spaces in their path will break formatting checks.Prompt for AI agents