diff --git a/models/lfs.go b/models/lfs.go index 711e5b0494453..39b0b2dd69a29 100644 --- a/models/lfs.go +++ b/models/lfs.go @@ -44,20 +44,20 @@ const ( func NewLFSMetaObject(m *LFSMetaObject) (*LFSMetaObject, error) { var err error - has, err := x.Get(m) + sess := x.NewSession() + defer sess.Close() + if err = sess.Begin(); err != nil { + return nil, err + } + + has, err := sess.Get(m) if err != nil { return nil, err } if has { m.Existing = true - return m, nil - } - - sess := x.NewSession() - defer sess.Close() - if err = sess.Begin(); err != nil { - return nil, err + return m, sess.Commit() } if _, err = sess.Insert(m); err != nil {