this commit exposes the format version of the operation pack and identity to reduce the changes needed in vendored code when migrating. This also creates error variables that can be propagated and tested against for migrations.
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
+ "github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/repository"
)
@@ -47,10 +48,10 @@ func (opp *OperationPack) UnmarshalJSON(data []byte) error {
}
if aux.Version < formatVersion {
- return fmt.Errorf("outdated repository format, please use https://github.com/MichaelMure/git-bug-migration to upgrade")
+ return entity.NewErrOldFormatVersion(aux.Version)
}
if aux.Version > formatVersion {
- return fmt.Errorf("your version of git-bug is too old for this repository (version %v), please upgrade to the latest version", aux.Version)
+ return entity.NewErrNewFormatVersion(aux.Version)
}
for _, raw := range aux.Operations {
@@ -30,3 +30,29 @@ func IsErrMultipleMatch(err error) bool {
_, ok := err.(*ErrMultipleMatch)
return ok
}
+
+// ErrOldFormatVersion indicate that the read data has a too old format.
+type ErrOldFormatVersion struct {
+ formatVersion uint
+}
+
+func NewErrOldFormatVersion(formatVersion uint) *ErrOldFormatVersion {
+ return &ErrOldFormatVersion{formatVersion: formatVersion}
+}
+
+func (e ErrOldFormatVersion) Error() string {
+ return fmt.Sprintf("outdated repository format %v, please use https://github.com/MichaelMure/git-bug-migration to upgrade", e.formatVersion)
+}
+
+// ErrNewFormatVersion indicate that the read data is too new for this software.
+type ErrNewFormatVersion struct {
+ formatVersion uint
+}
+
+func NewErrNewFormatVersion(formatVersion uint) *ErrNewFormatVersion {
+ return &ErrNewFormatVersion{formatVersion: formatVersion}
+}
+
+func (e ErrNewFormatVersion) Error() string {
+ return fmt.Sprintf("your version of git-bug is too old for this repository (version %v), please upgrade to the latest version", e.formatVersion)
+}