driusan / dgit

A Pure Go Git Implementation
MIT License
112 stars 10 forks source link

Unable to push - object not found #248

Closed henesy closed 5 years ago

henesy commented 5 years ago

As per title, I am now unable to push with dgit, but I haven't tried in quite awhile, maybe I'm missing something obvious?

This should be on the latest dgit commit.

Shell transcript:

tenshi% git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .gitignore
    examples/
    main.c
    mkfile

nothing added to commit but untracked files present (use "git add" to track)
tenshi% git add .
tenshi% git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   .gitignore
    modified:   README.md
    new file:   examples/tmp.cfg
    new file:   examples/tmp.proto
    new file:   main.c
    new file:   mkfile

tenshi% git commit
Warning: editor environment not set. Falling back on ed...
231
a
add skeleton for features ;; only calls rfork and exec for now
.
w
294
q
81fd72e88d58ed746ed032342de3579b178c84db
tenshi% git push master
origin  on  https://github.com/henesy/ducker.git
report-status
delete-refs
side-band-64k
quiet
atomic
ofs-delta
agent=git/github-g776217765456

Object not found.
tenshi% cat .git/config
[core]
    repositoryformatversion = 0
    bare = false
[remote "origin"]
    url = https://github.com/henesy/ducker.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
tenshi% 
henesy commented 5 years ago

Fwiw, copying the exact repository (incl .git dir) to linux and pushing with git there works, so I don't think my .git/config is set up wrong

driusan commented 5 years ago

No, it sounds like it's not finding the object for one of the blobs.. is this an initial commit/push to the repo or a follow-up one? I'll clone the repo and take a look when I'm at a computer, but if I can't reproduce it with the cloned copy would you be able to put the .git folder somewhere?

edit: no need, I can reproduce by trying to push that repo to a new, empty github repo..

driusan commented 5 years ago

You can apply this patch as a temporary workaround:

diff --git a/git/sha1.go b/git/sha1.go
index f8c881d..14267ca 100644
--- a/git/sha1.go
+++ b/git/sha1.go
@@ -679,6 +679,10 @@ func (t TreeID) GetAllObjectsExcept(cl *Client, excludeList map[Sha1]struct{}, p
    if excludeList != nil {
        excludeList[Sha1(t)] = struct{}{}
    }
+   if (Sha1(t) == Sha1{}) {
+       // Consider the empty Sha1 to be the same as an empty tree.
+       return nil, nil
+   }
    o, err := cl.GetObject(Sha1(t))
    if err != nil {
        return nil, err

but I want to figure out why dgit rev-list --objects 81fd72e88d58ed746ed032342de3579b178c84db (which is used to find the list of objects to push) ends up there with an empty Sha1 before pushing the fix to master, because it looks like there's something weird going on on a deeper level.

henesy commented 5 years ago

Oh that’s a bit spooky

I’ll apply then patch when I get home, glad I could sniff something out for ya :)

driusan commented 5 years ago

I thought #249 should fix the root of it, but it looks like after the rev-list problem it's still generating an invalid packfile when I try pushing (but getting past the Object not found error message, at least).. so the patch above might still not be able to push afterall, I'll have to dig a little more.

driusan commented 5 years ago

Okay, I managed to push that repo to https://github.com/driusan/ducker-test after the changes from #251 .. can you give it a try with the master branch?

henesy commented 5 years ago

Seems to work now!

https://github.com/henesy/ducker-test was my test repo, no problems on push.

Weird bug, but thank you so much for the fix :)