Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

Commit ead720a

Browse files
committed
fix bugs
1 parent 60e5d2b commit ead720a

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

migration3/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ git-bug 11f3991e2be17a5e0740c429f48961bfe468c23a
33

44
Changes:
55
- Exposed formatVersion of OperationPack
6+
- Removed error wrapping for bug and identity decoding
7+
- Added custom error message for invalid formatVersion
68

79
Usage: This version is used to update the bug and identity ids to meet the new standards

migration3/before/bug/operation_pack.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
// 2: no more legacy identities
1414
const formatVersion = 2
1515

16+
var ErrInvalidFormatVersion = fmt.Errorf("invalid format version")
17+
1618
// OperationPack represent an ordered set of operation to apply
1719
// to a Bug. These operations are stored in a single Git commit.
1820
//
@@ -50,10 +52,10 @@ func (opp *OperationPack) UnmarshalJSON(data []byte) error {
5052
opp.FormatVersion = aux.Version
5153

5254
if aux.Version < formatVersion {
53-
return fmt.Errorf("outdated repository format, please use https://github.com/MichaelMure/git-bug-migration to upgrade")
55+
return ErrInvalidFormatVersion
5456
}
5557
if aux.Version > formatVersion {
56-
return fmt.Errorf("your version of git-bug is too old for this repository (version %v), please upgrade to the latest version", aux.Version)
58+
return ErrInvalidFormatVersion
5759
}
5860

5961
for _, raw := range aux.Operations {

migration3/before/identity/version.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
// 1: original format
1717
const formatVersion = 1
1818

19+
var ErrInvalidFormatVersion = fmt.Errorf("invalid format version")
20+
1921
// Version is a complete set of information about an Identity at a point in time.
2022
type Version struct {
2123
// The lamport time at which this version become effective
@@ -103,7 +105,7 @@ func (v *Version) UnmarshalJSON(data []byte) error {
103105
}
104106

105107
if aux.FormatVersion != formatVersion {
106-
return fmt.Errorf("unknown format version %v", aux.FormatVersion)
108+
return ErrInvalidFormatVersion
107109
}
108110

109111
v.time = aux.Time

migration3/migration3.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package migration3
22

33
import (
4+
"errors"
45
"fmt"
56

67
afterbug "github.com/MichaelMure/git-bug-migration/migration3/after/bug"
@@ -41,6 +42,14 @@ func (m *Migration3) migrate(oldRepo beforerepo.ClockedRepo, newRepo afterrepo.C
4142
migratedIdentities := map[beforeentity.Id]*afteridentity.Identity{}
4243

4344
for streamedIdentity := range identities {
45+
if streamedIdentity.Err != nil {
46+
if errors.Is(streamedIdentity.Err, beforeidentity.ErrInvalidFormatVersion) {
47+
fmt.Print("skipping bug, already updated\n")
48+
continue
49+
} else {
50+
return streamedIdentity.Err
51+
}
52+
}
4453
oldIdentity := streamedIdentity.Identity
4554
fmt.Printf("identity %s: ", oldIdentity.Id().Human())
4655
newIdentity, err := afteridentity.NewIdentityFull(
@@ -63,11 +72,22 @@ func (m *Migration3) migrate(oldRepo beforerepo.ClockedRepo, newRepo afterrepo.C
6372
}
6473

6574
for streamedBug := range bugs {
75+
if streamedBug.Err != nil {
76+
if errors.Is(streamedBug.Err, beforebug.ErrInvalidFormatVersion) {
77+
fmt.Print("skipping bug, already updated\n")
78+
continue
79+
} else {
80+
return streamedBug.Err
81+
}
82+
}
6683
oldBug := streamedBug.Bug
6784
fmt.Printf("bug %s: ", oldBug.Id().Human())
6885
newBug, err := migrateBug(oldBug, migratedIdentities)
6986
if err != nil {
7087
return err
88+
} else if newBug == nil {
89+
fmt.Print("skipping bug, already updated\n")
90+
return nil
7191
}
7292
if err := newBug.Commit(newRepo); err != nil {
7393
return err

0 commit comments

Comments
 (0)