Git with Go stage #MG6: ERR upload-pack: not our ref

I’m stuck on Stage 7.

I’ve tried requesting refs from a repository.

Output from Discovery request:

001e# service=git-upload-pack
000001550deb936f12efc4c75dd215c45a7bdec6db0cc3c4 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow deepen-since deepen-not deepen-relative no-progress include-tag multi_ack_detailed allow-tip-sha1-in-want allow-reachable-sha1-in-want no-done symref=HEAD:refs/heads/master filter object-format=sha1 agent=git/github-f133c3a1d7e6
003f0deb936f12efc4c75dd215c45a7bdec6db0cc3c4 refs/heads/master
0000

Output from Ref request

0042want 003f0deb936f12efc4c75dd215c45a7bdec6db0cc3c4 no-progress
00000009done

Response:

Packfile: 0049ERR upload-pack: not our ref 003f0deb936f12efc4c75dd215c45a7bdec6db0c

And here’s a snippet of my code:

func GetRefs(repoUrl string, refs map[string]string) []byte {
	body := bytes.NewBuffer([]byte{})

	url := fmt.Sprintf("%s/git-upload-pack", repoUrl)
	for _, ref := range refs {
		line := packetLine(fmt.Sprintf("want %s no-progress\n", ref))
		body.WriteString(line)
	}

	body.WriteString("0000")
	body.WriteString(packetLine("done\n"))
	fmt.Println(body.String())
	resp, err := http.Post(url, "application/x-git-upload-pack-result", body)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error: %v\n", err)
		os.Exit(1)
	}
	defer resp.Body.Close()
	res := bytes.NewBuffer([]byte{})
	_, err = io.Copy(res, resp.Body)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error: %v\n", err)
		os.Exit(1)
	}
	
	return res.Bytes()

}

Any suggestion would be greatly appreciated :slight_smile:

I figured it out! If anyone else gets stuck in the same place. I didn’t realize that the discovery references were in pkt-line format.

// first 4 are the size, last 63 are the sha1 hash
003f0deb936f12efc4c75dd215c45a7bdec6db0cc3c4 refs/heads/master

@mgnsharon Thanks for sharing the fix here - nice find!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.

Note: I’ve updated the title of this post to include the stage ID (#MG6). You can learn about the stages rename here: Upcoming change: Stages overhaul.