Skip to content

Commit 00fdb48

Browse files
brechtvlGiteaBot
authored andcommitted
Fix archive creating LFS hooks and breaking pull requests (go-gitea#28848)
When LFS hooks are present in gitea-repositories, operations like git push for creating a pull request fail. These repositories are not meant to include LFS files or git push them, that is handled separately. And so they should not have LFS hooks. Installing git-lfs on some systems (like Debian Linux) will automatically set up /etc/gitconfig to create LFS hooks in repositories. For most git commands in Gitea this is not a problem, either because they run on a temporary clone or the git command does not create LFS hooks. But one case where this happens is git archive for creating repository archives. To fix that, add a GIT_CONFIG_NOSYSTEM=1 to disable using the system configuration for that command. According to a comment, GIT_CONFIG_NOSYSTEM is not used for all git commands because the system configuration can be intentionally set up for Gitea to use. Resolves go-gitea#19810, go-gitea#21148
1 parent 8b5c918 commit 00fdb48

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: modules/git/repo_archive.go

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"io"
11+
"os"
1112
"path/filepath"
1213
"strings"
1314
)
@@ -62,11 +63,15 @@ func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, t
6263
cmd.AddOptionFormat("--format=%s", format.String())
6364
cmd.AddDynamicArguments(commitID)
6465

66+
// Avoid LFS hooks getting installed because of /etc/gitconfig, which can break pull requests.
67+
env := append(os.Environ(), "GIT_CONFIG_NOSYSTEM=1")
68+
6569
var stderr strings.Builder
6670
err := cmd.Run(&RunOpts{
6771
Dir: repo.Path,
6872
Stdout: target,
6973
Stderr: &stderr,
74+
Env: env,
7075
})
7176
if err != nil {
7277
return ConcatenateError(err, stderr.String())

0 commit comments

Comments
 (0)