diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-28 11:14:09 -0800 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-28 11:23:52 -0800 |
commit | cbab840ef28888c2e85112b3b48294f7333ec187 (patch) | |
tree | 9fbd8da724791193905635a4ed789c6ddf8f39c5 /storage/memory | |
parent | 83e7046d0c1ce12f5394a1d5a4e28cad32aa666d (diff) | |
download | go-git-cbab840ef28888c2e85112b3b48294f7333ec187.tar.gz |
dotgit: add CheckAndSetReference tests
Diffstat (limited to 'storage/memory')
-rw-r--r-- | storage/memory/storage.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/storage/memory/storage.go b/storage/memory/storage.go index 69394af..c9306ee 100644 --- a/storage/memory/storage.go +++ b/storage/memory/storage.go @@ -204,16 +204,17 @@ func (r ReferenceStorage) SetReference(ref *plumbing.Reference) error { } func (r ReferenceStorage) CheckAndSetReference(ref, old *plumbing.Reference) error { - if ref != nil { - if old != nil { - tmp := r[ref.Name()] - if tmp != nil && tmp.Hash() != old.Hash() { - return ErrRefHasChanged - } - } - r[ref.Name()] = ref + 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 } |