diff options
| author | 2026-03-23 03:25:44 +0000 | |
|---|---|---|
| committer | 2026-03-23 03:27:52 +0000 | |
| commit | 4a796e64ac576d6a3e3f2fe6174c4aa476ea0c5c (patch) | |
| tree | 44d72a20076ceab0981d0b553693d26ca36cc0be /refstore/files/update_verify_current.go | |
| parent | receivepack: Lifecycle/ownership docs (diff) | |
| signature | No signature | |
refstore: Improve interfaces, errors, and make batch work v0.1.92
Diffstat (limited to 'refstore/files/update_verify_current.go')
| -rw-r--r-- | refstore/files/update_verify_current.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/refstore/files/update_verify_current.go b/refstore/files/update_verify_current.go new file mode 100644 index 00000000..f8035994 --- /dev/null +++ b/refstore/files/update_verify_current.go @@ -0,0 +1,60 @@ +package files + +import ( + "strings" + + "codeberg.org/lindenii/furgit/refstore" +) + +func (executor *refUpdateExecutor) verifyPreparedUpdateCurrent(item preparedUpdate) error { + switch item.op.kind { + case updateCreate: + if item.target.ref.kind != directMissing { + return wrapUpdateError(item.op.name, &refstore.CreateExistsError{}) + } + + return nil + case updateReplace, updateDelete, updateVerify: + if item.target.ref.kind == directMissing { + return wrapUpdateError(item.op.name, refstore.ErrReferenceNotFound) + } + + if item.target.ref.kind != directDetached { + return wrapUpdateError(item.op.name, &refstore.ExpectedDetachedError{}) + } + + if item.target.ref.id != item.op.oldID { + return wrapUpdateError(item.op.name, &refstore.IncorrectOldValueError{ + Actual: item.target.ref.id.String(), + Expected: item.op.oldID.String(), + }) + } + + return nil + case updateCreateSymbolic: + if item.target.ref.kind != directMissing { + return wrapUpdateError(item.op.name, &refstore.CreateExistsError{}) + } + + return nil + case updateReplaceSymbolic, updateDeleteSymbolic, updateVerifySymbolic: + if item.target.ref.kind == directMissing { + return wrapUpdateError(item.op.name, refstore.ErrReferenceNotFound) + } + + if item.target.ref.kind != directSymbolic { + return wrapUpdateError(item.op.name, &refstore.ExpectedSymbolicError{}) + } + + if strings.TrimSpace(item.target.ref.target) != strings.TrimSpace(item.op.oldTarget) { + return wrapUpdateError(item.op.name, &refstore.IncorrectOldValueError{ + Actual: strings.TrimSpace(item.target.ref.target), + Expected: strings.TrimSpace(item.op.oldTarget), + }) + } + + return nil + } + + return nil +} |
