Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/git/attribute/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewBatchChecker(repo *git.Repository, treeish string, attributes []string)
}
}()

cmd, envs, cleanup, err := checkAttrCommand(repo, treeish, nil, attributes)
cmd, envs, cleanup, err := checkAttrCommand(repo, treeish, nil, attributes, false)
if err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions modules/git/attribute/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"code.gitea.io/gitea/modules/git"
)

func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attributes []string) (*git.Command, []string, func(), error) {
func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attributes []string, cached bool) (*git.Command, []string, func(), error) {
cancel := func() {}
envs := []string{"GIT_FLUSH=1"}
cmd := git.NewCommand("check-attr", "-z")
Expand All @@ -39,6 +39,8 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
)
cancel = deleteTemporaryFile
}
} else if cached {
cmd.AddArguments("--cached")
} // else: no treeish, assume it is a not a bare repo, read from working directory

cmd.AddDynamicArguments(attributes...)
Expand All @@ -51,12 +53,13 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
type CheckAttributeOpts struct {
Filenames []string
Attributes []string
Cached bool
}

// CheckAttributes return the attributes of the given filenames and attributes in the given treeish.
// If treeish is empty, then it will use current working directory, otherwise it will use the provided treeish on the bare repo
func CheckAttributes(ctx context.Context, gitRepo *git.Repository, treeish string, opts CheckAttributeOpts) (map[string]*Attributes, error) {
cmd, envs, cancel, err := checkAttrCommand(gitRepo, treeish, opts.Filenames, opts.Attributes)
cmd, envs, cancel, err := checkAttrCommand(gitRepo, treeish, opts.Filenames, opts.Attributes, opts.Cached)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion services/repository/files/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,11 @@ func CreateOrUpdateFile(ctx context.Context, t *TemporaryUploadRepository, file
var lfsMetaObject *git_model.LFSMetaObject
if setting.LFS.StartServer && hasOldBranch {
// Check there is no way this can return multiple infos
attributesMap, err := attribute.CheckAttributes(ctx, t.gitRepo, "" /* use temp repo's working dir */, attribute.CheckAttributeOpts{
attributesMap, err := attribute.CheckAttributes(ctx, t.gitRepo, "", attribute.CheckAttributeOpts{
Attributes: []string{attribute.Filter},
Filenames: []string{file.Options.treePath},
// An index is set, so it's okay to list the attributes from it
Cached: true,
})
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions services/repository/files/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
}

var attributesMap map[string]*attribute.Attributes
if setting.LFS.StartServer {
attributesMap, err = attribute.CheckAttributes(ctx, t.gitRepo, "" /* use temp repo's working dir */, attribute.CheckAttributeOpts{
if setting.LFS.StartServer && hasOldBranch {
attributesMap, err = attribute.CheckAttributes(ctx, t.gitRepo, "", attribute.CheckAttributeOpts{
Attributes: []string{attribute.Filter},
Filenames: names,
// An index is set, so it's okay to list the attributes from it
Cached: true,
})
if err != nil {
return err
Expand Down