Conversation
Agent-Logs-Url: https://github.com/AzureAD/microsoft-authentication-library-common-for-objc/sessions/11de8d55-737c-46e2-a1f3-ec281a14ef3f Co-authored-by: swasti29 <12692041+swasti29@users.noreply.github.com>
…ch comment Agent-Logs-Url: https://github.com/AzureAD/microsoft-authentication-library-common-for-objc/sessions/11de8d55-737c-46e2-a1f3-ec281a14ef3f Co-authored-by: swasti29 <12692041+swasti29@users.noreply.github.com>
| @@ -0,0 +1,86 @@ | |||
| #!/bin/bash | |||
There was a problem hiding this comment.
This pull request does not update changelog.txt.
Please consider if this change would be noticeable to a partner or user and either update changelog.txt or resolve this conversation.
Add missing exclusions: .strings, .stringsdict, .xcstrings, .md, .mdx to match pr-size-check-reusable.yml exactly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a repo-local Git pre-push hook (enabled via core.hooksPath) to warn developers when a push is likely to result in an oversized PR, encouraging smaller/split PRs in this codebase.
Changes:
- Added reusable
.githooks/pr-size-check.shto compute changed-line “churn” vs a base branch with file-pattern exclusions. - Added
.githooks/pre-pushentrypoint configuring repo-specific exclusions and sourcing the shared logic. - Added a
Makefilesetuptarget to configurecore.hooksPath = .githookslocally.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Makefile | Adds make setup to enable local git hooks via core.hooksPath. |
| .githooks/pre-push | Hook entrypoint that sets repo-specific exclusions and sources shared logic. |
| .githooks/pr-size-check.sh | Implements base-branch selection, file filtering, line-change counting, and warning/prompt behavior. |
| fi | ||
|
|
||
| # ── Get list of changed files (excluding patterns) ─────────── | ||
| mapfile -t CHANGED_FILES < <(git diff --name-only "$BASE_BRANCH"...HEAD 2>/dev/null | grep -vE "$GREP_PATTERN") |
There was a problem hiding this comment.
mapfile isn't available in the default /bin/bash on macOS (bash 3.2), so this hook will fail for many developers. Consider replacing this with a bash-3-compatible approach (e.g., a while IFS= read -r loop or using CHANGED_FILES=( $(...) ) with proper quoting) so the hook works on stock macOS shells.
| mapfile -t CHANGED_FILES < <(git diff --name-only "$BASE_BRANCH"...HEAD 2>/dev/null | grep -vE "$GREP_PATTERN") | |
| CHANGED_FILES=() | |
| while IFS= read -r changed_file; do | |
| CHANGED_FILES+=("$changed_file") | |
| done < <(git diff --name-only "$BASE_BRANCH"...HEAD 2>/dev/null | grep -vE "$GREP_PATTERN") |
| read -r -p " Push anyway? [y/N]: " response | ||
| if [[ ! "$response" =~ ^[Yy]$ ]]; then | ||
| echo "Push cancelled." | ||
| exit 1 |
There was a problem hiding this comment.
The prompt uses read from stdin, but pre-push hooks receive the refs-to-push on stdin. If the size exceeds the limit, this read will consume the first ref line (not user input) and typically cancel the push unexpectedly. Read from /dev/tty (when available) or fall back to a non-interactive warning-only behavior when no TTY is present.
| read -r -p " Push anyway? [y/N]: " response | |
| if [[ ! "$response" =~ ^[Yy]$ ]]; then | |
| echo "Push cancelled." | |
| exit 1 | |
| if [ -r /dev/tty ] && [ -w /dev/tty ]; then | |
| read -r -p " Push anyway? [y/N]: " response < /dev/tty | |
| if [[ ! "$response" =~ ^[Yy]$ ]]; then | |
| echo "Push cancelled." | |
| exit 1 | |
| fi | |
| else | |
| echo "ℹ️ No interactive terminal available; continuing without confirmation." |
| # ── Resolve base branch — tries origin/dev, origin/main, origin/master ────── | ||
| BASE_BRANCH="" | ||
| for candidate in origin/dev origin/main origin/master; do | ||
| if git show-ref --verify --quiet "refs/remotes/${candidate}"; then | ||
| BASE_BRANCH="$candidate" | ||
| break | ||
| fi | ||
| done |
There was a problem hiding this comment.
Base branch resolution is hardcoded to origin/*, but the pre-push hook is invoked with the target remote name as $1 and can be run against remotes other than origin. As written, pushes to a non-origin remote may incorrectly skip the check even if that remote has dev/main/master. Consider using the provided remote name (with a fallback to origin) when building refs/remotes/<remote>/... for the base branch candidates.
| # ── Count lines changed ─────────────────────────────────────── | ||
| TOTAL_LINES=$(git diff "$BASE_BRANCH"...HEAD -- "${CHANGED_FILES[@]}" 2>/dev/null \ | ||
| | grep -E "^\+|^-" \ | ||
| | grep -vE "^\+\+\+|^---" \ | ||
| | wc -l \ | ||
| | tr -d ' ') |
There was a problem hiding this comment.
This counts total diff hunk lines (additions + deletions), not “net line changes”. If the PR description intends net change, the counting logic needs to be adjusted; otherwise, update wording (e.g., “total line churn”) so the warning matches what’s being measured.
- Add extended image formats (bmp, webp, heic, heif, ico) - Add audio/video exclusions (mp4, mov, mp3, wav, etc.) - Add binary/submodule detection (warns on non-excluded binaries) - Use git diff --numstat for accurate line counting - Handle non-interactive shells gracefully Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Aligns caller workflow exclude_paths with local pre-push hook. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 22d46b4.
Local hook EXTRA_EXCLUDES should match the caller workflow's exclude_paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds a local git pre-push hook that warns developers when a push exceeds 500 changed lines, prompting to split into smaller PRs. Hook fires on every push to any remote branch and is bypassable via
git push --no-verify.Files added
.githooks/pr-size-check.sh— Shared hook logic: resolves base branch (origin/dev→origin/main→origin/master), filters out Xcode artifacts/configs/images, counts net line changes, and prompts if over limit.githooks/pre-push— Repo-specific entry point; setsEXTRA_EXCLUDESto skipIdentityCore/tests/,IdentityCore/MSIDTestsHostApp/, andscripts/, then sources the shared scriptMakefile—setuptarget that writescore.hooksPath = .githooksinto the local git configActivation (one-time per clone)
After this, every
git pushtriggers the size check automatically. Developers who already have a clone need to runmake setuponce; new clones require the same one-time step.Original prompt
Summary
Add a local pre-push git hook that warns developers when their changes exceed the recommended PR size (500 lines) before pushing to any remote branch.
Files to create
1.
.githooks/pr-size-check.sh— Shared reusable logic (identical across all repos)2.
.githooks/pre-push— Repo-specific hook for MSAL Common3.
Makefile— Addsetuptarget (create if not exists, or append if exists)Check if a
Makefilealready exists in the repo root. If it does, append the setup target. If not, create it:Important notes
devgit push --no-verifypr-size-check.shmust be executable:chmod +x .githooks/pr-size-check.shpre-pushmust be executable:chmod +x .githooks/pre-pushorigin/dev(falling back toorigin/mainthenorigin/master)The following is the prior conversation context from the user's chat exploration (may be truncated):
User: do we have currently any pre push
Assistant: Let me check all 4 repos.
Assistant: Here is what exists across all 4 repos:
.githooks/existspre-pushpre-commit.githooks/.githooks/.githooks/Key finding — Broker already has a
pre-commithook