src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.9k stars 540 forks source link

The order of references in Remote.List() is non-deterministic #1232

Open petergardfjall opened 5 years ago

petergardfjall commented 5 years ago

The implementation of Remote.List() lists does not preserve the reference order as found in the remote repo.

To reproduce this behavior, try running https://github.com/src-d/go-git/blob/master/_examples/ls-remote/main.go against a repo several times and watch the order of references change between calls. This is different from the behavior of git ls-remote <repoURL> whose order is deterministic.

The reason appears to be the use of maps to store and iterate over references

https://github.com/src-d/go-git/blob/aac20cc0e86f9f563bc74c42e9b9c598dfe271da/storage/memory/storage.go#L242

In Go, the iteration order of maps is non-deterministic.