@@ -32,7 +32,7 @@ func TestReposHandler(t *testing.T) {
3232 repos : []string {"project1" , "project2" },
3333 }, {
3434 name : "nested" ,
35- repos : []string {"project1" , "project1/subproject" , "project2" , "dir/project3" },
35+ repos : []string {"project1" , "project1/subproject" , "project2" , "dir/project3" , "dir/project4.bare" },
3636 }}
3737 for _ , tc := range cases {
3838 t .Run (tc .name , func (t * testing.T ) {
@@ -171,6 +171,12 @@ func testReposHandler(t *testing.T, h http.Handler, repos []Repo) {
171171 }
172172}
173173
174+ func gitInitBare (t * testing.T , path string ) {
175+ if err := exec .Command ("git" , "init" , "--bare" , path ).Run (); err != nil {
176+ t .Fatal (err )
177+ }
178+ }
179+
174180func gitInitRepos (t * testing.T , names ... string ) string {
175181 root , err := os .MkdirTemp ("" , "" )
176182 if err != nil {
@@ -184,10 +190,11 @@ func gitInitRepos(t *testing.T, names ...string) string {
184190 if err := os .MkdirAll (p , 0755 ); err != nil {
185191 t .Fatal (err )
186192 }
187- p = filepath . Join ( p , ".git" )
188- if err := exec . Command ( "git" , "init" , "-- bare", p ). Run (); err != nil {
189- t . Fatal ( err )
193+
194+ if ! strings . HasSuffix ( p , ". bare" ) {
195+ p = filepath . Join ( p , ".git" )
190196 }
197+ gitInitBare (t , p )
191198 }
192199
193200 return root
@@ -221,6 +228,32 @@ func TestIgnoreGitSubmodules(t *testing.T) {
221228 }
222229}
223230
231+ func TestIsBareRepo (t * testing.T ) {
232+ dir , err := os .MkdirTemp ("" , "" )
233+ if err != nil {
234+ t .Fatal (err )
235+ }
236+ t .Cleanup (func () { os .RemoveAll (dir ) })
237+
238+ gitInitBare (t , dir )
239+
240+ if ! isBareRepo (dir ) {
241+ t .Errorf ("Path %s it not a bare repository" , dir )
242+ }
243+ }
244+
245+ func TestEmptyDirIsNotBareRepo (t * testing.T ) {
246+ dir , err := os .MkdirTemp ("" , "" )
247+ if err != nil {
248+ t .Fatal (err )
249+ }
250+ t .Cleanup (func () { os .RemoveAll (dir ) })
251+
252+ if isBareRepo (dir ) {
253+ t .Errorf ("Path %s it falsey detected as a bare repository" , dir )
254+ }
255+ }
256+
224257func testLogger (t * testing.T ) * log.Logger {
225258 return log .New (testWriter {t }, "testLogger " , log .LstdFlags )
226259}
0 commit comments