-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
git: git_ensure_safe_directory(): check safety via git status #8673
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?
Conversation
WalkthroughThe function git_ensure_safe_directory changed its safety verification: instead of checking git config for safe.directory, it now runs a git status with -C on the target directory. If that per-directory status fails, it falls back to adding the directory to the global safe.directory using regular_git. The function’s external signature remains unchanged. No new public methods, updates to public method signatures, or public data structures were introduced. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
lib/functions/general/git.sh (2)
57-58: Use the local variable consistentlyMinor: use "$git_dir" instead of "$1" for readability and to match the canonicalization above.
- local git_dir="$1" - if [[ -e "$1/.git" ]]; then + local git_dir="$1" + if [[ -e "$git_dir/.git" ]]; then
59-59: Clarify log messageMessage implies “marking all directories as safe,” which isn’t accurate. The proposed change makes it explicit and less misleading.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
lib/functions/general/git.sh(1 hunks)
🔇 Additional comments (1)
lib/functions/general/git.sh (1)
59-61: Reviewgit_ensure_safe_directory: Canonicalize paths and userev-parse
- Always convert
git_dirto an absolute path before invokinggit -Cto avoid “cannot chdir” on relative inputs.- Replace the expensive
git statuscall with:- git -C "$git_dir" status > /dev/null + abs_dir="$(realpath -m "$git_dir")" + if ! git -C "$abs_dir" rev-parse --git-dir >/dev/null 2>&1; then + regular_git config --global --add safe.directory "$abs_dir" + fi- Update the alert message accordingly.
This change prevents relative‐path failures and reduces overhead. [mandatory_refactors_required]
The issue
Consider these two unmatching cases running
git config --global --get safe.directory "/home/armbian/build"The cause
git config --getmatch driectory name with a tab completion, not exactly the directory name or using glob match patternThe solution
use
git -C $1 statusto check the safety of the repo.The benefit
less impurity of possible change on user's ~/.git/config file.
Documentation summary for feature / change
Please delete this section if entry to main documentation is not needed.
If documentation entry is predicted, please provide key elements for further implementation into main documentation and set label to "Needs Documentation". You are welcome to open a PR to documentation or you can leave following information for technical writer:
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.
Checklist:
Please delete options that are not relevant.