@@ -17,8 +17,8 @@ import (
17
17
"gopkg.in/src-d/go-git.v4/storage/filesystem"
18
18
"gopkg.in/src-d/go-git.v4/utils/ioutil"
19
19
20
- "gopkg.in/src-d/go-billy.v2 "
21
- "gopkg.in/src-d/go-billy.v2 /osfs"
20
+ "gopkg.in/src-d/go-billy.v3 "
21
+ "gopkg.in/src-d/go-billy.v3 /osfs"
22
22
)
23
23
24
24
var (
@@ -92,11 +92,6 @@ func setWorktreeAndStoragePaths(r *Repository, worktree billy.Filesystem) error
92
92
return nil
93
93
}
94
94
95
- _ , isOS := fs .Filesystem ().(* osfs.OS )
96
- if ! isOS {
97
- return nil
98
- }
99
-
100
95
if err := createDotGitFile (worktree , fs .Filesystem ()); err != nil {
101
96
return err
102
97
}
@@ -105,9 +100,9 @@ func setWorktreeAndStoragePaths(r *Repository, worktree billy.Filesystem) error
105
100
}
106
101
107
102
func createDotGitFile (worktree , storage billy.Filesystem ) error {
108
- path , err := filepath .Rel (worktree .Base (), storage .Base ())
103
+ path , err := filepath .Rel (worktree .Root (), storage .Root ())
109
104
if err != nil {
110
- path = storage .Base ()
105
+ path = storage .Root ()
111
106
}
112
107
113
108
if path == ".git" {
@@ -126,9 +121,9 @@ func createDotGitFile(worktree, storage billy.Filesystem) error {
126
121
}
127
122
128
123
func setConfigWorktree (r * Repository , worktree , storage billy.Filesystem ) error {
129
- path , err := filepath .Rel (storage .Base (), worktree .Base ())
124
+ path , err := filepath .Rel (storage .Root (), worktree .Root ())
130
125
if err != nil {
131
- path = worktree .Base ()
126
+ path = worktree .Root ()
132
127
}
133
128
134
129
if path == ".." {
@@ -194,7 +189,7 @@ func PlainInit(path string, isBare bool) (*Repository, error) {
194
189
dot = osfs .New (path )
195
190
} else {
196
191
wt = osfs .New (path )
197
- dot = wt .Dir (".git" )
192
+ dot , _ = wt .Chroot (".git" )
198
193
}
199
194
200
195
s , err := filesystem .NewStorage (dot )
@@ -209,7 +204,7 @@ func PlainInit(path string, isBare bool) (*Repository, error) {
209
204
// repository is bare or a normal one. If the path doesn't contain a valid
210
205
// repository ErrRepositoryNotExists is returned
211
206
func PlainOpen (path string ) (* Repository , error ) {
212
- dot , wt , err := dotGitToFilesystems (path )
207
+ dot , wt , err := dotGitToOSFilesystems (path )
213
208
if err != nil {
214
209
return nil , err
215
210
}
@@ -230,7 +225,7 @@ func PlainOpen(path string) (*Repository, error) {
230
225
return Open (s , wt )
231
226
}
232
227
233
- func dotGitToFilesystems (path string ) (dot , wt billy.Filesystem , err error ) {
228
+ func dotGitToOSFilesystems (path string ) (dot , wt billy.Filesystem , err error ) {
234
229
fs := osfs .New (path )
235
230
fi , err := fs .Stat (".git" )
236
231
if err != nil {
@@ -242,18 +237,19 @@ func dotGitToFilesystems(path string) (dot, wt billy.Filesystem, err error) {
242
237
}
243
238
244
239
if fi .IsDir () {
245
- return fs .Dir (".git" ), fs , nil
240
+ dot , err = fs .Chroot (".git" )
241
+ return dot , fs , err
246
242
}
247
243
248
- dot , err = dotGitFileToFilesystem ( fs )
244
+ dot , err = dotGitFileToOSFilesystem ( path , fs )
249
245
if err != nil {
250
246
return nil , nil , err
251
247
}
252
248
253
249
return dot , fs , nil
254
250
}
255
251
256
- func dotGitFileToFilesystem ( fs billy.Filesystem ) (billy.Filesystem , error ) {
252
+ func dotGitFileToOSFilesystem ( path string , fs billy.Filesystem ) (billy.Filesystem , error ) {
257
253
var err error
258
254
259
255
f , err := fs .Open (".git" )
@@ -279,7 +275,7 @@ func dotGitFileToFilesystem(fs billy.Filesystem) (billy.Filesystem, error) {
279
275
return osfs .New (gitdir ), nil
280
276
}
281
277
282
- return fs .Dir ( gitdir ), err
278
+ return osfs . New ( fs .Join ( path , gitdir )), nil
283
279
}
284
280
285
281
// PlainClone a repository into the path with the given options, isBare defines
0 commit comments