Skip to content

Commit 586d45a

Browse files
authored
Merge pull request go-git#6 from go-git/pr-1153
storage/filesystem: dotgit, unable to work with .git folder with temporal packfiles
2 parents eef6778 + 5132088 commit 586d45a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

storage/filesystem/dotgit/dotgit.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ const (
3333

3434
tmpPackedRefsPrefix = "._packed-refs"
3535

36-
packExt = ".pack"
37-
idxExt = ".idx"
36+
packPrefix = "pack-"
37+
packExt = ".pack"
38+
idxExt = ".idx"
3839
)
3940

4041
var (
@@ -224,11 +225,11 @@ func (d *DotGit) objectPacks() ([]plumbing.Hash, error) {
224225

225226
var packs []plumbing.Hash
226227
for _, f := range files {
227-
if !strings.HasSuffix(f.Name(), packExt) {
228+
n := f.Name()
229+
if !strings.HasSuffix(n, packExt) || !strings.HasPrefix(n, packPrefix) {
228230
continue
229231
}
230232

231-
n := f.Name()
232233
h := plumbing.NewHash(n[5 : len(n)-5]) //pack-(hash).pack
233234
if h.IsZero() {
234235
// Ignore files with badly-formatted names.

storage/filesystem/dotgit/dotgit_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ func testObjectPacks(c *C, fs billy.Filesystem, dir *DotGit, f *fixtures.Fixture
464464
c.Assert(err, IsNil)
465465
err = badFile.Close()
466466
c.Assert(err, IsNil)
467+
// temporary file generated by git gc
468+
tmpFile, err := fs.Create("objects/pack/.tmp-11111-pack-58rf8y4wm1b1k52bpe0kdlx6lpreg6ahso8n3ylc.pack")
469+
c.Assert(err, IsNil)
470+
err = tmpFile.Close()
471+
c.Assert(err, IsNil)
467472

468473
hashes2, err := dir.ObjectPacks()
469474
c.Assert(err, IsNil)

0 commit comments

Comments
 (0)