identity: PR fixes

Michael Muré created

Change summary

bridge/github/export_test.go |  2 +-
bridge/github/import_test.go |  2 +-
bridge/gitlab/export_test.go |  2 +-
bridge/gitlab/import_test.go |  2 +-
identity/identity_test.go    | 10 ++++++++++
identity/version.go          |  9 ++++++---
6 files changed, 20 insertions(+), 7 deletions(-)

Detailed changes

bridge/github/export_test.go 🔗

@@ -126,7 +126,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
 	}
 }
 
-func TestPushPull(t *testing.T) {
+func TestGithubPushPull(t *testing.T) {
 	// repo owner
 	envUser := os.Getenv("GITHUB_TEST_USER")
 

bridge/github/import_test.go 🔗

@@ -18,7 +18,7 @@ import (
 	"github.com/MichaelMure/git-bug/util/interrupt"
 )
 
-func Test_Importer(t *testing.T) {
+func TestGithubImporter(t *testing.T) {
 	envToken := os.Getenv("GITHUB_TOKEN_PRIVATE")
 	if envToken == "" {
 		t.Skip("Env var GITHUB_TOKEN_PRIVATE missing")

bridge/gitlab/export_test.go 🔗

@@ -134,7 +134,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
 	}
 }
 
-func TestPushPull(t *testing.T) {
+func TestGitlabPushPull(t *testing.T) {
 	// token must have 'repo' and 'delete_repo' scopes
 	envToken := os.Getenv("GITLAB_API_TOKEN")
 	if envToken == "" {

bridge/gitlab/import_test.go 🔗

@@ -18,7 +18,7 @@ import (
 	"github.com/MichaelMure/git-bug/util/interrupt"
 )
 
-func TestImport(t *testing.T) {
+func TestGitlabImport(t *testing.T) {
 	envToken := os.Getenv("GITLAB_API_TOKEN")
 	if envToken == "" {
 		t.Skip("Env var GITLAB_API_TOKEN missing")

identity/identity_test.go 🔗

@@ -204,6 +204,16 @@ func TestMetadata(t *testing.T) {
 
 	assertHasKeyValue(t, loaded.ImmutableMetadata(), "key1", "value1")
 	assertHasKeyValue(t, loaded.MutableMetadata(), "key1", "value2")
+
+	// set metadata after commit
+	versionCount := len(identity.versions)
+	identity.SetMetadata("foo", "bar")
+	require.True(t, identity.NeedCommit())
+	require.Len(t, identity.versions, versionCount+1)
+
+	err = identity.Commit(repo)
+	require.NoError(t, err)
+	require.Len(t, identity.versions, versionCount+1)
 }
 
 func assertHasKeyValue(t *testing.T, metadata map[string]string, key, value string) {

identity/version.go 🔗

@@ -18,10 +18,9 @@ import (
 
 // 1: original format
 // 2: Identity Ids are generated from the first version serialized data instead of from the first git commit
+//    + Identity hold multiple lamport clocks from other entities, instead of just bug edit
 const formatVersion = 2
 
-// TODO ^^
-
 // version is a complete set of information about an Identity at a point in time.
 type version struct {
 	name      string
@@ -42,7 +41,7 @@ type version struct {
 	// version of a bug, used to later generate the ID
 	// len(Nonce) should be > 20 and < 64 bytes
 	// It has no functional purpose and should be ignored.
-	// TODO: optional?
+	// TODO: optional after first version?
 	nonce []byte
 
 	// A set of arbitrary key/value to store metadata about a version or about an Identity in general.
@@ -122,6 +121,10 @@ func (v *version) Clone() *version {
 	// copy direct fields
 	clone := *v
 
+	// reset some fields
+	clone.commitHash = ""
+	clone.id = entity.UnsetId
+
 	clone.times = make(map[string]lamport.Time)
 	for name, t := range v.times {
 		clone.times[name] = t