aboutsummaryrefslogtreecommitdiffstats
path: root/storage/memory/storage.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-11-29 12:22:37 +0100
committerGitHub <noreply@github.com>2017-11-29 12:22:37 +0100
commitc07c778ed043429427533e2fd7549a3d54b903f1 (patch)
tree9fbd8da724791193905635a4ed789c6ddf8f39c5 /storage/memory/storage.go
parent6dda959c4bda3a422a9a1c6425f92efa914c4d82 (diff)
parentcbab840ef28888c2e85112b3b48294f7333ec187 (diff)
downloadgo-git-c07c778ed043429427533e2fd7549a3d54b903f1.tar.gz
Merge pull request #665 from keybase/strib/gh-fast-forward-fetch
remote: support for non-force, fast-forward-only fetches
Diffstat (limited to 'storage/memory/storage.go')
-rw-r--r--storage/memory/storage.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/storage/memory/storage.go b/storage/memory/storage.go
index 2380fed..c9306ee 100644
--- a/storage/memory/storage.go
+++ b/storage/memory/storage.go
@@ -12,6 +12,7 @@ import (
)
var ErrUnsupportedObjectType = fmt.Errorf("unsupported object type")
+var ErrRefHasChanged = fmt.Errorf("reference has changed concurrently")
// Storage is an implementation of git.Storer that stores data on memory, being
// ephemeral. The use of this storage should be done in controlled envoriments,
@@ -202,6 +203,21 @@ func (r ReferenceStorage) SetReference(ref *plumbing.Reference) error {
return nil
}
+func (r ReferenceStorage) CheckAndSetReference(ref, old *plumbing.Reference) error {
+ if ref == nil {
+ return nil
+ }
+
+ if old != nil {
+ tmp := r[ref.Name()]
+ if tmp != nil && tmp.Hash() != old.Hash() {
+ return ErrRefHasChanged
+ }
+ }
+ r[ref.Name()] = ref
+ return nil
+}
+
func (r ReferenceStorage) Reference(n plumbing.ReferenceName) (*plumbing.Reference, error) {
ref, ok := r[n]
if !ok {