diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 3a3f7f4..4126abd 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -108,5 +108,8 @@ I had to suffer an hour of debugging because I implemented git handling on a db ## Hackatime. Users can login using Hack Club's Hackatime. Why? To get stats on their projects. +## Git. +When opening a repo with `git.OpenRepo()`, make sure to add `defer repo.Close()` after it. + ## Resources - [https://github.com/firecracker-microvm/firecracker/blob/main/docs/prod-host-setup.md](Firecracker production guide) \ No newline at end of file diff --git a/app/repo-config.go b/app/repo-config.go index 49e3316..6f34410 100644 --- a/app/repo-config.go +++ b/app/repo-config.go @@ -37,6 +37,7 @@ func (a *App) RepoConfigHandler(w http.ResponseWriter, r *http.Request) { } case http.MethodGet: gitRepo, err := git.OpenRepo(dbRepo.UserID, &dbRepo.ID, "") + defer gitRepo.Git.Close() if err != nil { http.Error(w, "Something went wrong", 500) return diff --git a/app/repo-issues.go b/app/repo-issues.go index 6db6c05..04364b1 100644 --- a/app/repo-issues.go +++ b/app/repo-issues.go @@ -16,6 +16,7 @@ import ( func (a *App) RepoIssuesIndex(w http.ResponseWriter, r *http.Request) { repo := r.Context().Value(md.RepoKey).(types.Repo) gitRepo, _ := git.OpenRepo(repo.UserID, &repo.ID, "") + defer gitRepo.Git.Close() a.renderRepo(w, r, "issues/issue_list", repoViewOptions{ View: "issues", @@ -111,6 +112,7 @@ func (a *App) repoIssueView(w http.ResponseWriter, r *http.Request) { // keep the navbar happy gitRepo, err := git.OpenRepo(repo.UserID, &repo.ID, "") + defer gitRepo.Git.Close() a.renderRepo(w, r, "issues/view_issue", repoViewOptions{ DB: &repo, diff --git a/app/repo.go b/app/repo.go index a2b25c4..922742b 100644 --- a/app/repo.go +++ b/app/repo.go @@ -147,6 +147,7 @@ func (a *App) RepoHandler(w http.ResponseWriter, r *http.Request) { // opens a git repo. // mind-blowing, ain't it? gitRepo, err := git.OpenRepo(dbRepo.UserID, &dbRepo.ID, reqBranch) + defer gitRepo.Git.Close() if err != nil { switch err { diff --git a/lib/git/git.go b/lib/git/git.go index 72f8581..22178c5 100644 --- a/lib/git/git.go +++ b/lib/git/git.go @@ -64,7 +64,6 @@ func OpenRepo(userID *uuid.UUID, repoID *uuid.UUID, branch string) (*GitRepo, er return nil, err } } - defer repo.Close() head, err := ResolveHead(repo, branch) // potentially nil. if err != nil && err != ErrRepoHasNoHead {