Skip to content

Commit a0cfb36

Browse files
committed
improve test and comment
1 parent 1d33329 commit a0cfb36

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

modules/git/attribute/batch_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,17 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
102102
}, attr)
103103
}
104104

105-
var expectedAttrs = Attributes{
106-
LinguistGenerated: "unspecified",
107-
LinguistDetectable: "unspecified",
108-
LinguistDocumentation: "unspecified",
109-
LinguistVendored: "unspecified",
110-
LinguistLanguage: "Python",
111-
GitlabLanguage: "unspecified",
105+
func expectedAttrs() *Attributes {
106+
return &Attributes{
107+
m: map[string]Attribute{
108+
LinguistGenerated: "unspecified",
109+
LinguistDetectable: "unspecified",
110+
LinguistDocumentation: "unspecified",
111+
LinguistVendored: "unspecified",
112+
LinguistLanguage: "Python",
113+
GitlabLanguage: "unspecified",
114+
},
115+
}
112116
}
113117

114118
func Test_BatchChecker(t *testing.T) {
@@ -127,7 +131,7 @@ func Test_BatchChecker(t *testing.T) {
127131
defer checker.Close()
128132
attributes, err := checker.CheckPath("i-am-a-python.p")
129133
assert.NoError(t, err)
130-
assert.Equal(t, expectedAttrs, attributes)
134+
assert.Equal(t, expectedAttrs(), attributes)
131135
})
132136

133137
// run git check-attr on work tree
@@ -148,7 +152,7 @@ func Test_BatchChecker(t *testing.T) {
148152
defer checker.Close()
149153
attributes, err := checker.CheckPath("i-am-a-python.p")
150154
assert.NoError(t, err)
151-
assert.Equal(t, expectedAttrs, attributes)
155+
assert.Equal(t, expectedAttrs(), attributes)
152156
})
153157

154158
if !git.DefaultFeatures().SupportCheckAttrOnBare {
@@ -163,6 +167,6 @@ func Test_BatchChecker(t *testing.T) {
163167

164168
attributes, err := checker.CheckPath("i-am-a-python.p")
165169
assert.NoError(t, err)
166-
assert.Equal(t, expectedAttrs, attributes)
170+
assert.Equal(t, expectedAttrs(), attributes)
167171
})
168172
}

modules/git/attribute/checker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
2121
cmd.AddArguments("--all")
2222
}
2323

24-
// there is treeish, read from source or index
24+
// there is treeish, read from bare repo or temp index created by "read-tree"
2525
if treeish != "" {
2626
if git.DefaultFeatures().SupportCheckAttrOnBare {
2727
cmd.AddArguments("--source")
@@ -39,7 +39,7 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
3939
)
4040
cancel = deleteTemporaryFile
4141
}
42-
} // no treeish, read from working directory
42+
} // else: no treeish, assume it is a not a bare repo, read from working directory
4343

4444
cmd.AddDynamicArguments(attributes...)
4545
if len(filenames) > 0 {

modules/git/attribute/checker_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Test_Checker(t *testing.T) {
3232
})
3333
assert.NoError(t, err)
3434
assert.Len(t, attrs, 1)
35-
assert.Equal(t, expectedAttrs, attrs["i-am-a-python.p"])
35+
assert.Equal(t, expectedAttrs(), attrs["i-am-a-python.p"])
3636
})
3737

3838
// run git check-attr on work tree
@@ -54,7 +54,7 @@ func Test_Checker(t *testing.T) {
5454
})
5555
assert.NoError(t, err)
5656
assert.Len(t, attrs, 1)
57-
assert.Equal(t, expectedAttrs, attrs["i-am-a-python.p"])
57+
assert.Equal(t, expectedAttrs(), attrs["i-am-a-python.p"])
5858
})
5959

6060
if !git.DefaultFeatures().SupportCheckAttrOnBare {
@@ -69,6 +69,6 @@ func Test_Checker(t *testing.T) {
6969
})
7070
assert.NoError(t, err)
7171
assert.Len(t, attrs, 1)
72-
assert.Equal(t, expectedAttrs, attrs["i-am-a-python.p"])
72+
assert.Equal(t, expectedAttrs(), attrs["i-am-a-python.p"])
7373
})
7474
}

0 commit comments

Comments
 (0)