improve test and comment

This commit is contained in:
wxiaoguang 2025-04-11 15:19:38 +08:00
parent 1d333296eb
commit a0cfb36717
3 changed files with 19 additions and 15 deletions

View File

@ -102,13 +102,17 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
}, attr)
}
var expectedAttrs = Attributes{
LinguistGenerated: "unspecified",
LinguistDetectable: "unspecified",
LinguistDocumentation: "unspecified",
LinguistVendored: "unspecified",
LinguistLanguage: "Python",
GitlabLanguage: "unspecified",
func expectedAttrs() *Attributes {
return &Attributes{
m: map[string]Attribute{
LinguistGenerated: "unspecified",
LinguistDetectable: "unspecified",
LinguistDocumentation: "unspecified",
LinguistVendored: "unspecified",
LinguistLanguage: "Python",
GitlabLanguage: "unspecified",
},
}
}
func Test_BatchChecker(t *testing.T) {
@ -127,7 +131,7 @@ func Test_BatchChecker(t *testing.T) {
defer checker.Close()
attributes, err := checker.CheckPath("i-am-a-python.p")
assert.NoError(t, err)
assert.Equal(t, expectedAttrs, attributes)
assert.Equal(t, expectedAttrs(), attributes)
})
// run git check-attr on work tree
@ -148,7 +152,7 @@ func Test_BatchChecker(t *testing.T) {
defer checker.Close()
attributes, err := checker.CheckPath("i-am-a-python.p")
assert.NoError(t, err)
assert.Equal(t, expectedAttrs, attributes)
assert.Equal(t, expectedAttrs(), attributes)
})
if !git.DefaultFeatures().SupportCheckAttrOnBare {
@ -163,6 +167,6 @@ func Test_BatchChecker(t *testing.T) {
attributes, err := checker.CheckPath("i-am-a-python.p")
assert.NoError(t, err)
assert.Equal(t, expectedAttrs, attributes)
assert.Equal(t, expectedAttrs(), attributes)
})
}

View File

@ -21,7 +21,7 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
cmd.AddArguments("--all")
}
// there is treeish, read from source or index
// there is treeish, read from bare repo or temp index created by "read-tree"
if treeish != "" {
if git.DefaultFeatures().SupportCheckAttrOnBare {
cmd.AddArguments("--source")
@ -39,7 +39,7 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
)
cancel = deleteTemporaryFile
}
} // no treeish, read from working directory
} // else: no treeish, assume it is a not a bare repo, read from working directory
cmd.AddDynamicArguments(attributes...)
if len(filenames) > 0 {

View File

@ -32,7 +32,7 @@ func Test_Checker(t *testing.T) {
})
assert.NoError(t, err)
assert.Len(t, attrs, 1)
assert.Equal(t, expectedAttrs, attrs["i-am-a-python.p"])
assert.Equal(t, expectedAttrs(), attrs["i-am-a-python.p"])
})
// run git check-attr on work tree
@ -54,7 +54,7 @@ func Test_Checker(t *testing.T) {
})
assert.NoError(t, err)
assert.Len(t, attrs, 1)
assert.Equal(t, expectedAttrs, attrs["i-am-a-python.p"])
assert.Equal(t, expectedAttrs(), attrs["i-am-a-python.p"])
})
if !git.DefaultFeatures().SupportCheckAttrOnBare {
@ -69,6 +69,6 @@ func Test_Checker(t *testing.T) {
})
assert.NoError(t, err)
assert.Len(t, attrs, 1)
assert.Equal(t, expectedAttrs, attrs["i-am-a-python.p"])
assert.Equal(t, expectedAttrs(), attrs["i-am-a-python.p"])
})
}