Skip to content

Commit

Permalink
Merge pull request #812 from L11R/incoming-dir-fix
Browse files Browse the repository at this point in the history
storage: filesystem/dotgit, add support for tmp_objdir prefix
  • Loading branch information
pjbgf authored Jul 20, 2023
2 parents 56c4bf4 + 939ad4a commit 0f46b7a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion storage/filesystem/dotgit/dotgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,9 @@ func (d *DotGit) hasIncomingObjects() bool {
directoryContents, err := d.fs.ReadDir(objectsPath)
if err == nil {
for _, file := range directoryContents {
if strings.HasPrefix(file.Name(), "incoming-") && file.IsDir() {
if file.IsDir() && (strings.HasPrefix(file.Name(), "tmp_objdir-incoming-") ||
// Before Git 2.35 incoming commits directory had another prefix
strings.HasPrefix(file.Name(), "incoming-")) {
d.incomingDirName = file.Name()
}
}
Expand Down
25 changes: 23 additions & 2 deletions storage/filesystem/dotgit/dotgit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,27 @@ func (s *SuiteDotGit) TestObject(c *C) {
fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
dir := New(fs)

hash := plumbing.NewHash("03db8e1fbe133a480f2867aac478fd866686d69e")
file, err := dir.Object(hash)
c.Assert(err, IsNil)
c.Assert(strings.HasSuffix(
file.Name(), fs.Join("objects", "03", "db8e1fbe133a480f2867aac478fd866686d69e")),
Equals, true,
)
incomingHash := "9d25e0f9bde9f82882b49fe29117b9411cb157b7" //made up hash
incomingDirPath := fs.Join("objects", "tmp_objdir-incoming-123456")
incomingFilePath := fs.Join(incomingDirPath, incomingHash[0:2], incomingHash[2:40])
fs.MkdirAll(incomingDirPath, os.FileMode(0755))
fs.Create(incomingFilePath)

_, err = dir.Object(plumbing.NewHash(incomingHash))
c.Assert(err, IsNil)
}

func (s *SuiteDotGit) TestPreGit235Object(c *C) {
fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
dir := New(fs)

hash := plumbing.NewHash("03db8e1fbe133a480f2867aac478fd866686d69e")
file, err := dir.Object(hash)
c.Assert(err, IsNil)
Expand All @@ -665,7 +686,7 @@ func (s *SuiteDotGit) TestObjectStat(c *C) {
_, err := dir.ObjectStat(hash)
c.Assert(err, IsNil)
incomingHash := "9d25e0f9bde9f82882b49fe29117b9411cb157b7" //made up hash
incomingDirPath := fs.Join("objects", "incoming-123456")
incomingDirPath := fs.Join("objects", "tmp_objdir-incoming-123456")
incomingFilePath := fs.Join(incomingDirPath, incomingHash[0:2], incomingHash[2:40])
fs.MkdirAll(incomingDirPath, os.FileMode(0755))
fs.Create(incomingFilePath)
Expand All @@ -683,7 +704,7 @@ func (s *SuiteDotGit) TestObjectDelete(c *C) {
c.Assert(err, IsNil)

incomingHash := "9d25e0f9bde9f82882b49fe29117b9411cb157b7" //made up hash
incomingDirPath := fs.Join("objects", "incoming-123456")
incomingDirPath := fs.Join("objects", "tmp_objdir-incoming-123456")
incomingSubDirPath := fs.Join(incomingDirPath, incomingHash[0:2])
incomingFilePath := fs.Join(incomingSubDirPath, incomingHash[2:40])

Expand Down

0 comments on commit 0f46b7a

Please sign in to comment.