Skip to content

Conversation

@2bitburrito
Copy link

@2bitburrito 2bitburrito commented Jul 23, 2025

Changed gitignore file.close from defer to explicit so as to ensure .gitignore is written before running git commands.

This fixes issue #416.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Problem/Feature

Please include a description of the problem or feature this PR is addressing.

Description of Changes:

  • Item 1
  • Item 2

Checklist

Changed gitignore file.close from defer to explicit so as to ensure
.gitignore is written before running git commands
@Ujstor
Copy link
Collaborator

Ujstor commented Jul 24, 2025

@2bitburrito Did you check if this approach works?

@2bitburrito
Copy link
Author

2bitburrito commented Jul 25, 2025

Yep. I wrote a quick n dirty gh action to show it passes on a window's system.

It was consistently failing before removing the defer so I do believe that it was a filesystem buffer issue.

Apologies if this is at all messy. It's my first pull request for open source.

@2bitburrito
Copy link
Author

I just made a change. Rather than losing the .Defer() I added .Sync() which is safer if an error occurs before the file.Close() is executed.

I believe this solves the issue?

You can see outputs from the gh actions test:

All files in repo:

    Directory: D:\a\go-blueprint\go-blueprint\test

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d--h-           7/31/2025  2:10 PM                .git
d----           7/31/2025  2:10 PM                cmd
d----           7/31/2025  2:10 PM                internal
-a---           7/31/2025  2:10 PM            885 .air.toml
-a---           7/31/2025  2:10 PM             26 .env
-a---           7/31/2025  2:10 PM            457 .gitignore
-a---           7/31/2025  2:10 PM            598 go.mod
-a---           7/31/2025  2:10 PM           2413 go.sum
-a---           7/31/2025  2:10 PM            717 Makefile
-a---           7/31/2025  2:10 PM            638 README.md

All git tracked files:

.air.toml
.gitignore
Makefile
README.md
cmd/api/main.go
go.mod
go.sum
internal/server/routes.go
internal/server/routes_test.go
internal/server/server.go

So the file is present in the directory and not being tracked by git.

Let me know if I'm missing something crucial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants