Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

remote: support for non-force, fast-forward-only fetches #665

Merged
merged 7 commits into from
Nov 29, 2017

Conversation

strib
Copy link
Contributor

@strib strib commented Nov 27, 2017

This PR adds support for a missing "+" in a fetch refspec, which should indicate a fast-forward-only fetch. (Alternatively, the caller could put Force=true into the FetchOptions to indicate that all fetches should be treated as forces.)

It relies on file-level locking provided by the storage layer, so that distributed storage layers (being accessed concurrently by multiple independent nodes each running go-git) can be supported.

Code mostly written by @taruti, based on an early version by @lupine in #490.

@@ -16,6 +16,7 @@ var ErrMaxResolveRecursion = errors.New("max. recursion level reached")
// ReferenceStorer is a generic storage of references.
type ReferenceStorer interface {
SetReference(*plumbing.Reference) error
CheckAndSetReference(new, old *plumbing.Reference) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that the order methods are updocumented too, I belive because looks like obviuos (even with that we should document the behaviour at some point), but we should document this one now, sinse for me it`s not a obviuos the goal.

if old == nil {
return nil
}
ref, err := d.readReferenceFrom(f, old.Name().String())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not covered by the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readReferenceFrom is definitely covered by the tests, since it's called by readReferenceFile below. But if you're referring to checkReferenceAndTruncate, sure I'll add a test for it.

@@ -202,6 +203,20 @@ func (r ReferenceStorage) SetReference(ref *plumbing.Reference) error {
return nil
}

func (r ReferenceStorage) CheckAndSetReference(ref, old *plumbing.Reference) error {
if ref != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be change this to:

if ref == nil {
    return nil
}

@@ -202,6 +203,20 @@ func (r ReferenceStorage) SetReference(ref *plumbing.Reference) error {
return nil
}

func (r ReferenceStorage) CheckAndSetReference(ref, old *plumbing.Reference) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not covered by the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't notice that the remote tests don't use filesystem storage. I'll add a test.

@strib
Copy link
Contributor Author

strib commented Nov 28, 2017

@mcuadros I've added more tests and addressed your comments. Please take another look, thanks!

@mcuadros mcuadros merged commit c07c778 into src-d:master Nov 29, 2017
// not `nil`, it first checks that the current stored value for
// `old.Name()` matches the given reference value in `old`. If
// not, it returns an error and doesn't update `new`.
CheckAndSetReference(new, old *plumbing.Reference) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is a good time to add doc comments to the other methods in this interface?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants