Skip to content

Commit 74e5583

Browse files
committed
fix
1 parent de1131f commit 74e5583

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

modules/git/attribute/batch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewBatchChecker(repo *git.Repository, treeish string, attributes []string)
3636
}
3737
}()
3838

39-
cmd, envs, cleanup, err := checkAttrCommand(repo, treeish, nil, attributes, false)
39+
cmd, envs, cleanup, err := checkAttrCommand(repo, treeish, nil, attributes)
4040
if err != nil {
4141
return nil, err
4242
}

modules/git/attribute/checker.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"code.gitea.io/gitea/modules/git"
1414
)
1515

16-
func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attributes []string, cached bool) (*git.Command, []string, func(), error) {
16+
func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attributes []string) (*git.Command, []string, func(), error) {
1717
cancel := func() {}
1818
envs := []string{"GIT_FLUSH=1"}
1919
cmd := git.NewCommand("check-attr", "-z")
@@ -39,11 +39,12 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
3939
)
4040
cancel = deleteTemporaryFile
4141
}
42-
} else if cached {
43-
// read from existing index instead of work tree, in cases where the repo is bare and has an index or the work tree
44-
// contains unstaged changes that shouldn't affect the attribute check
42+
} else {
43+
// Read from existing index, in cases where the repo is bare and has an index,
44+
// or the work tree contains unstaged changes that shouldn't affect the attribute check.
45+
// It is caller's responsibility to add changed ".gitattributes" into the index if they want to respect the new changes.
4546
cmd.AddArguments("--cached")
46-
} // else: no treeish, assume it is a not a bare repo, read from working directory
47+
}
4748

4849
cmd.AddDynamicArguments(attributes...)
4950
if len(filenames) > 0 {
@@ -55,13 +56,12 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
5556
type CheckAttributeOpts struct {
5657
Filenames []string
5758
Attributes []string
58-
Cached bool
5959
}
6060

6161
// CheckAttributes return the attributes of the given filenames and attributes in the given treeish.
6262
// If treeish is empty, then it will use current working directory, otherwise it will use the provided treeish on the bare repo
6363
func CheckAttributes(ctx context.Context, gitRepo *git.Repository, treeish string, opts CheckAttributeOpts) (map[string]*Attributes, error) {
64-
cmd, envs, cancel, err := checkAttrCommand(gitRepo, treeish, opts.Filenames, opts.Attributes, opts.Cached)
64+
cmd, envs, cancel, err := checkAttrCommand(gitRepo, treeish, opts.Filenames, opts.Attributes)
6565
if err != nil {
6666
return nil, err
6767
}

modules/git/attribute/checker_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func Test_Checker(t *testing.T) {
6161
attrs, err := CheckAttributes(t.Context(), gitRepo, "", CheckAttributeOpts{
6262
Filenames: []string{"i-am-a-python.p"},
6363
Attributes: LinguistAttributes,
64-
Cached: true,
6564
})
6665
assert.NoError(t, err)
6766
assert.Len(t, attrs, 1)

services/repository/files/update.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,6 @@ func CreateOrUpdateFile(ctx context.Context, t *TemporaryUploadRepository, file
495495
attributesMap, err := attribute.CheckAttributes(ctx, t.gitRepo, "" /* use temp repo's working dir */, attribute.CheckAttributeOpts{
496496
Attributes: []string{attribute.Filter},
497497
Filenames: []string{file.Options.treePath},
498-
// An index is set, so it's okay to list the attributes from it
499-
Cached: true,
500498
})
501499
if err != nil {
502500
return err

services/repository/files/upload.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,10 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
107107
}
108108

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

0 commit comments

Comments
 (0)