Fix #5302: Create .git/info directory before writing exclude file#5325
Open
cobyfrombrooklyn-bot wants to merge 1 commit intojesseduffield:masterfrom
Open
Fix #5302: Create .git/info directory before writing exclude file#5325cobyfrombrooklyn-bot wants to merge 1 commit intojesseduffield:masterfrom
cobyfrombrooklyn-bot wants to merge 1 commit intojesseduffield:masterfrom
Conversation
…lude file When .git/info directory does not exist (can happen with bare clones or manual deletion), the Exclude function failed with 'no such file or directory'. Added os.MkdirAll to create the directory before opening the exclude file. Added integration test exclude_without_info_dir that removes .git/info before attempting to exclude a file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5302
Problem
When
.git/infodirectory does not exist (can happen with bare clones, manual deletion, or certain Git configurations), selecting "Add to .git/info/exclude" fails with:The
Excludefunction usedos.OpenFilewithos.O_CREATEwhich creates the file but not its parent directory.Fix
Added
os.MkdirAllto create the.git/infodirectory (with 0755 permissions) before attempting to open the exclude file.MkdirAllis a no-op if the directory already exists, so existing behavior is unchanged.Test
Added integration test
file/exclude_without_info_dirthat:.git/infodirectory during repo setup.git/info/excludeis created with the correct contentTest fails without the fix, passes with it.
Tested locally on macOS ARM (Apple Silicon). Unit tests and integration test pass.