Skip to content

Fix #5302: Create .git/info directory before writing exclude file#5325

Merged
stefanhaller merged 1 commit intojesseduffield:masterfrom
cobyfrombrooklyn-bot:fix-issue-5302
Mar 8, 2026
Merged

Fix #5302: Create .git/info directory before writing exclude file#5325
stefanhaller merged 1 commit intojesseduffield:masterfrom
cobyfrombrooklyn-bot:fix-issue-5302

Conversation

@cobyfrombrooklyn-bot
Copy link

Fixes #5302

Problem

When .git/info directory does not exist (can happen with bare clones, manual deletion, or certain Git configurations), selecting "Add to .git/info/exclude" fails with:

open <repo-path>/.git/info/exclude: no such file or directory

The Exclude function used os.OpenFile with os.O_CREATE which creates the file but not its parent directory.

Fix

Added os.MkdirAll to create the .git/info directory (with 0755 permissions) before attempting to open the exclude file. MkdirAll is a no-op if the directory already exists, so existing behavior is unchanged.

Test

Added integration test file/exclude_without_info_dir that:

  1. Removes .git/info directory during repo setup
  2. Attempts to exclude a file via the menu
  3. Verifies .git/info/exclude is created with the correct content

Test fails without the fix, passes with it.

Tested locally on macOS ARM (Apple Silicon). Unit tests and integration test pass.

@stefanhaller stefanhaller added the bug Something isn't working label Mar 8, 2026
…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.
@stefanhaller stefanhaller enabled auto-merge March 8, 2026 15:25
@stefanhaller stefanhaller merged commit 25895bf into jesseduffield:master Mar 8, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fails to add to .git/info/exclude when .git/info directory is missing

2 participants